Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jc21 committed Mar 20, 2024
0 parents commit 2f3a6fb
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea
._*
.DS_Store
RPMS
SRPMS
DEPS
SOURCES/*
45 changes: 45 additions & 0 deletions Jenkinsfile.centos8
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@Library('jc21') _

pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
disableConcurrentBuilds()
ansiColor('xterm')
}
agent {
label 'rpmbuild'
}
stages {
stage('Build') {
steps {
sh './build 8 rust'
}
}
stage('Sign') {
steps {
rpmSign()
}
}
stage('Publish') {
steps {
dir(path: 'RPMS') {
archiveArtifacts(artifacts: '**/*/*.rpm', caseSensitive: true, onlyIfSuccessful: true)
}
dir(path: 'SRPMS') {
archiveArtifacts(artifacts: '**/*.src.rpm', caseSensitive: true, onlyIfSuccessful: true, allowEmptyArchive: true)
}
rpmGithubRelease('centos8')
}
}
}
post {
success {
juxtapose event: 'success'
sh 'figlet "SUCCESS"'
}
failure {
juxtapose event: 'failure'
sh 'figlet "FAILURE"'
}
}
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# [jnv](https://github.com/ynqa/jnv)

Builds for RHEL based distros hosted on [yum.jc21.com](https://yum.jc21.com)
39 changes: 39 additions & 0 deletions SPECS/jnv.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%global debug_package %{nil}

Name: jnv
Version: 0.1.0
Release: 1
Summary: interactive JSON filter using jq
Group: Applications/System
License: MIT
URL: https://github.com/ynqa/%{name}
BuildRequires: cmake
BuildRequires: cargo, rust, clang-devel, clang-libs
Source: https://github.com/ynqa/%{name}/archive/refs/tags/v0.1.0.tar.gz

%description
jnv is designed for navigating JSON, offering an interactive JSON
viewer and jq filter editor.

%prep
%setup -q -n %{name}-%{version}

%build
cargo build --release

%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/usr/bin
cp target/release/jnv %{buildroot}/usr/bin/

%clean
rm -rf %{buildroot}

%files
%defattr(-,root,root,-)
%doc LICENSE* *.md
/usr/bin/jnv

%changelog
* Wed Mar 20 2024 Jamie Curnow <[email protected]> - 0.1.0-1
- v0.1.0
115 changes: 115 additions & 0 deletions build
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash

##################################################
#
# ./build CENTOS_VERSION [DOCKER_TAG] [SPEC_FILE]
#
# If no docker tag, `latest` is used
# If no Spec file (without .spec), all spec files
# found will be built.
#
# ie:
# ./build 7 golang php-pecl-memcache_php72_php73
#
##################################################

CWD=$(pwd)
CYAN='\E[1;36m'
RED='\E[1;31m'
YELLOW='\E[1;33m'
GREEN='\E[1;32m'
BLUE='\E[1;34m'
RESET='\E[0m'

CENTOS_VERSION=$1
if [ "$CENTOS_VERSION" == "" ]; then
echo -e "${RED}ERROR: You must specify a Centos version to build for, either 7 or 8"
echo -e "ie: ./build 7${RESET}"
exit 1
fi

DOCKER_TAG=$2
if [ "$DOCKER_TAG" == "" ]; then
DOCKER_TAG=latest
fi

SPECIFIC_SPEC_FILE=$3

# Loop over all Specs in the SPECS folder
for SPECFILE in SPECS/*.spec; do
PACKAGE=${SPECFILE#"SPECS/"}
PACKAGE=${PACKAGE%".spec"}

if [ "${SPECIFIC_SPEC_FILE}" == "" ] || [ "${SPECIFIC_SPEC_FILE}" == "${PACKAGE}" ]; then
echo -e "${BLUE}${GREEN}Building ${CYAN}${PACKAGE} ${GREEN}for Centos ${CENTOS_VERSION}${RESET}"

# Make sure docker exists
if hash docker 2>/dev/null; then
# Generate a Docker image based on env vars and centos version, for use both manually and in CI
eval "DOCKER_IMAGE=\$\{DOCKER_RPMBUILD_EL${CENTOS_VERSION}:-jc21/rpmbuild-centos${CENTOS_VERSION}\}"
eval "DOCKER_IMAGE=${DOCKER_IMAGE}"

# Folder setup
echo -e "${BLUE}${YELLOW}Folder setup${RESET}"
rm -rf RPMS/* SRPMS/*
mkdir -p {RPMS,SRPMS,DEPS,SPECS,SOURCES}
chmod -R 777 {RPMS,SRPMS}

# Pull latest builder image
echo -e "${BLUE}${YELLOW}Pulling docker image: ${DOCKER_IMAGE}:${DOCKER_TAG}${RESET}"
docker pull "${DOCKER_IMAGE}:${DOCKER_TAG}"

# Use the build to change the ownership of folders
echo -e "${BLUE}${YELLOW}Temporarily changing ownership${RESET}"
docker run --rm \
-v "${CWD}:/home/rpmbuilder/rpmbuild" \
"${DOCKER_IMAGE}:${DOCKER_TAG}" \
sudo chown -R rpmbuilder:rpmbuilder /home/rpmbuilder/rpmbuild

# Do the build
echo -e "${BLUE}${YELLOW}Building ${PACKAGE}${RESET}"

DISABLE_MIRROR=
if [ -n "$NOMIRROR" ]; then
DISABLE_MIRROR=-m
fi

# If centos 8, we want -n option
NOBEST=
if [ "${CENTOS_VERSION}" == "8" ]; then
NOBEST=-n
fi

# Docker Run
RPMBUILD=/home/rpmbuilder/rpmbuild
docker run --rm \
--name "rpmbuild-${BUILD_TAG:-centos${CENTOS_VERSION}-${PACKAGE}}" \
-v "${CWD}/DEPS:${RPMBUILD}/DEPS" \
-v "${CWD}/RPMS:${RPMBUILD}/RPMS" \
-v "${CWD}/SRPMS:${RPMBUILD}/SRPMS" \
-v "${CWD}/SPECS:${RPMBUILD}/SPECS" \
-v "${CWD}/SOURCES:${RPMBUILD}/SOURCES" \
-e "GOPROXY=${GOPROXY}" \
"${DOCKER_IMAGE}:${DOCKER_TAG}" \
/bin/build-spec ${DISABLE_MIRROR} ${NOBEST} -o -r /home/rpmbuilder/rpmbuild/DEPS/*/*.rpm -- "/home/rpmbuilder/rpmbuild/SPECS/${PACKAGE}.spec"

BUILD_SUCCESS=$?

# Change ownership back
echo -e "${BLUE}${YELLOW}Reverting ownership${RESET}"
docker run --rm \
-v "${CWD}:/home/rpmbuilder/rpmbuild" \
"${DOCKER_IMAGE}:${DOCKER_TAG}" \
sudo chown -R "$(id -u):$(id -g)" /home/rpmbuilder/rpmbuild

# do we need to exit the loop?
if [ $BUILD_SUCCESS -ne 0 ]; then
echo -e "${BLUE}${RED}Exiting due to error${RESET}"
exit ${BUILD_SUCCESS}
fi
else
echo -e "${RED}ERROR: Docker command is not available${RESET}"
exit 1
fi
fi
done
7 changes: 7 additions & 0 deletions rpm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"publish": {
"PACKAGE": "jnv",
"GH_USER": "jc21-rpm",
"VERSION": "0.1.0"
}
}

0 comments on commit 2f3a6fb

Please sign in to comment.