From 9273dd5f460bf041fb026ef5766f413393ef3c39 Mon Sep 17 00:00:00 2001 From: Jamie Curnow Date: Tue, 25 Jun 2024 20:11:36 +1000 Subject: [PATCH] Use common build script --- Jenkinsfile.el8 | 10 ++--- Jenkinsfile.el9 | 41 +++++++++++++++++ README.md | 12 +---- SPECS/golang.spec | 2 +- build | 109 ---------------------------------------------- 5 files changed, 46 insertions(+), 128 deletions(-) create mode 100644 Jenkinsfile.el9 delete mode 100755 build diff --git a/Jenkinsfile.el8 b/Jenkinsfile.el8 index c5c3579..8dc0736 100644 --- a/Jenkinsfile.el8 +++ b/Jenkinsfile.el8 @@ -7,16 +7,12 @@ pipeline { ansiColor('xterm') } agent { - label 'rpmbuild' + label 'rpm' } stages { stage('Build') { steps { - sh './build 8' - } - } - stage('Sign') { - steps { + rpmBuild(8) rpmSign() } } @@ -28,7 +24,7 @@ pipeline { dir(path: 'SRPMS') { archiveArtifacts(artifacts: '**/*.src.rpm', caseSensitive: true, onlyIfSuccessful: true, allowEmptyArchive: true) } - rpmGithubRelease('centos8') + rpmGithubRelease('el8') } } } diff --git a/Jenkinsfile.el9 b/Jenkinsfile.el9 new file mode 100644 index 0000000..35b0344 --- /dev/null +++ b/Jenkinsfile.el9 @@ -0,0 +1,41 @@ +@Library('jc21') _ + +pipeline { + options { + buildDiscarder(logRotator(numToKeepStr: '10')) + disableConcurrentBuilds() + ansiColor('xterm') + } + agent { + label 'rpm' + } + stages { + stage('Build') { + steps { + rpmBuild(9) + 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('el9') + } + } + } + post { + success { + juxtapose event: 'success' + sh 'figlet "SUCCESS"' + } + failure { + juxtapose event: 'failure' + sh 'figlet "FAILURE"' + } + } +} diff --git a/README.md b/README.md index 03ba88e..344b63d 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,3 @@ # [golang](https://golang.org) -Build for Redhat based distros hosted on [yum.jc21.com](https://yum.jc21.com) - -### Building Locally - -```bash -git clone https://github.com/jc21-rpm/golang.git -cd golang - -# Using centos 8 as building distro: -./build 8 -``` +Build for Enterprise Linux based distros hosted on [yum.jc21.com](https://yum.jc21.com) diff --git a/SPECS/golang.spec b/SPECS/golang.spec index 3feff38..a675be1 100644 --- a/SPECS/golang.spec +++ b/SPECS/golang.spec @@ -4,7 +4,7 @@ Name: golang Version: 1.22.4 -Release: 1 +Release: 1%{?dist} Summary: The Go Programming Language License: BSD and Public Domain URL: https://www.shellcheck.net/ diff --git a/build b/build deleted file mode 100755 index e554727..0000000 --- a/build +++ /dev/null @@ -1,109 +0,0 @@ -#!/bin/bash - -################################################## -# -# ./build EL_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' - -EL_VERSION=$1 -if [ "$EL_VERSION" == "" ]; then - echo -e "${RED}ERROR: You must specify a EL version to build for, either 8 or 9" - 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 EL ${EL_VERSION}${RESET}" - - # Make sure docker exists - if hash docker 2>/dev/null; then - # Generate a Docker image based on env vars and rocky version, for use both manually and in CI - eval "DOCKER_IMAGE=\$\{DOCKER_RPMBUILD_EL${EL_VERSION}:-jc21/rpmbuild-rocky${EL_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 - - # Docker Run - RPMBUILD=/home/rpmbuilder/rpmbuild - docker run --rm \ - --name "rpmbuild-${BUILD_TAG:-${EL_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} -n -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