From 503d3644ceda1a48dda3dc077418843f625afaec Mon Sep 17 00:00:00 2001 From: Louis Maillard <louis.maillard@savoirfairelinux.com> Date: Wed, 9 Oct 2024 11:18:58 -0400 Subject: [PATCH] jenkins: add build pipeline for .deb artefacts Add a Jenkinsfile for automation of building artefacts for debian, ubuntu and following distros. Jenkins read a build.version file to determine version to build. We don't just run `extras/packaging/build_package.sh -a` because this would lead to running unverified shell script from unapproved commit outside of docker isolation, directly on jenkins server. Change-Id: I0482aa489272952755b88efefa0674175ca88cdd --- extras/packaging/Jenkinsfile | 141 +++++++++++++++++++++++++++++ extras/packaging/build.version | 1 + extras/packaging/build_packages.sh | 2 +- 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 extras/packaging/Jenkinsfile create mode 100644 extras/packaging/build.version diff --git a/extras/packaging/Jenkinsfile b/extras/packaging/Jenkinsfile new file mode 100644 index 0000000..48761c5 --- /dev/null +++ b/extras/packaging/Jenkinsfile @@ -0,0 +1,141 @@ +pipeline { + agent any + triggers { + gerrit customUrl: '', + gerritProjects: [ + [branches: [[compareType: 'PLAIN', pattern: 'master']], + compareType: 'PLAIN', + disableStrictForbiddenFileVerification: false, + pattern: 'dhtnet']], + triggerOnEvents: [ + commentAddedContains('!build'), + patchsetCreated(excludeDrafts: true, excludeNoCodeChange: true)] + } + options { + ansiColor('xterm') + } + parameters { + string(name: 'GERRIT_REFSPEC', + defaultValue: 'refs/heads/dhtnet', + description: 'The Gerrit refspec to fetch.') + } + environment { + PKG_NAME="dhtnet" + PKG_VERSION="" + FOLDER_NAME="$PKG_NAME-$PKG_VERSION" + } + stages { + stage('SCM Checkout') { + steps { + checkout changelog: true, poll: false, + scm: [$class: 'GitSCM', + branches: [[name: 'FETCH_HEAD']], + doGenerateSubmoduleConfigurations: false, + extensions: [ + [$class: 'CloneOption', noTags: true, reference: '', shallow: true], + [$class: 'WipeWorkspace']], + submoduleCfg: [], + userRemoteConfigs: [[refspec: '${GERRIT_REFSPEC}', url: 'https://${JAMI_GERRIT_URL}/dhtnet']]] + } + } + stage('Prepare build') { + steps { + script { + PKG_VERSION=sh( + script: "head -1 extras/packaging/build.version | grep -o '^[0-9\\.]\\+\$' -", + returnStdout: true + ).trim() + FOLDER_NAME="$PKG_NAME-$PKG_VERSION" + } + sh """ + if [ -z "$PKG_VERSION" ]; then + echo "Empty value in build.version: $PKG_VERSION" + exit 1 + fi + + rm -Rf "dependencies/msgpack" + rm -Rf "dependencies/opendht" + rm -Rf "dependencies/pjproject" + rm -Rf "dependencies/restinio" + git submodule update --init --recursive + """ + dir('extras/packaging') { + sh """ + rm -Rf "$FOLDER_NAME" + rm -f -- *${FOLDER_NAME}.tar.gz + mkdir -p "$FOLDER_NAME" + + # copy source code + cp -Rf ../../dependencies "$FOLDER_NAME/dependencies" + cp -Rf ../../include "$FOLDER_NAME/include" + cp -Rf ../../src "$FOLDER_NAME/src" + cp -Rf ../../tools "$FOLDER_NAME/tools" + cp -Rf ../../CMakeLists.txt "$FOLDER_NAME/CMakeLists.txt" + cp -Rf ../../COPYING "$FOLDER_NAME/COPYING" + cp -Rf ../../dhtnet.pc.in "$FOLDER_NAME/dhtnet.pc.in" + cp -Rf ../../README.md "$FOLDER_NAME/README.md" + + # copy debian conf and create debian/ubuntu archive + cp -Rf "./gnu-linux/debian" "$FOLDER_NAME/debian" + tar -czf "deb-${FOLDER_NAME}.tar.gz" "$FOLDER_NAME" + rm -Rf "$FOLDER_NAME/debian" + """ + } + } + } + stage('Build distributions') { + parallel { + stage('Ubuntu 22.04') { + steps { + dir('extras/packaging') { + sh """ + target="ubuntu-22" + mkdir -p "\$target" + docker build -t "dhtnet-builder:\$target" -f "gnu-linux/\$target.Dockerfile" --build-arg PKG_NAME="$FOLDER_NAME" . + docker run --rm \ + -v "\$(pwd)/\$target/":/build/artifacts \ + -e PKG_NAME="$FOLDER_NAME" "dhtnet-builder:\$target" + """ + } + } + } + stage('Ubuntu 24.04') { + steps { + dir('extras/packaging') { + sh """ + target="ubuntu-24" + mkdir -p "\$target" + docker build -t "dhtnet-builder:\$target" -f "gnu-linux/\$target.Dockerfile" --build-arg PKG_NAME="$FOLDER_NAME" . + docker run --rm \ + -v "\$(pwd)/\$target/":/build/artifacts \ + -e PKG_NAME="$FOLDER_NAME" "dhtnet-builder:\$target" + """ + } + } + } + stage('Debian 12') { + steps { + dir('extras/packaging') { + sh """ + target="debian-12" + mkdir -p "\$target" + docker build -t "dhtnet-builder:\$target" -f "gnu-linux/\$target.Dockerfile" --build-arg PKG_NAME="$FOLDER_NAME" . + docker run --rm \ + -v "\$(pwd)/\$target/":/build/artifacts \ + -e PKG_NAME="$FOLDER_NAME" "dhtnet-builder:\$target" + """ + } + } + } + } + } + } + post { + success { + dir('extras/packaging') { + archiveArtifacts artifacts: 'ubuntu-*/dhtnet_*.deb, debian-*/dhtnet_*.deb', + caseSensitive: false + } + } + } +} diff --git a/extras/packaging/build.version b/extras/packaging/build.version new file mode 100644 index 0000000..9325c3c --- /dev/null +++ b/extras/packaging/build.version @@ -0,0 +1 @@ +0.3.0 \ No newline at end of file diff --git a/extras/packaging/build_packages.sh b/extras/packaging/build_packages.sh index 03f46f7..38e50f2 100755 --- a/extras/packaging/build_packages.sh +++ b/extras/packaging/build_packages.sh @@ -2,7 +2,7 @@ set -e PKG_NAME=dhtnet -PKG_VERSION=0.3.0 +PKG_VERSION="$(head -1 extras/packaging/build.version | grep -o '^[0-9\.]\+$' -)" FOLDER_NAME="${PKG_NAME}-${PKG_VERSION}" -- GitLab