From 62e1f59d4f32cfb53e69a3f0e6a9676ed8583457 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Tue, 6 Dec 2022 14:00:59 -0400 Subject: [PATCH] chore: setup linux ci for .deb --- ci/Jenkinsfile | 99 +++++++++++++++++++++++++++++++++++++ ci/Jenkinsfile.linux | 78 +++++++++++++++++++++++++++++ scripts/linux/Dockerfile | 2 +- scripts/linux/build-pkgs.sh | 46 +---------------- scripts/linux/fpm-build.sh | 45 +++++++++++++++++ 5 files changed, 224 insertions(+), 46 deletions(-) create mode 100644 ci/Jenkinsfile create mode 100644 ci/Jenkinsfile.linux create mode 100755 scripts/linux/fpm-build.sh diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile new file mode 100644 index 00000000..b35a63c8 --- /dev/null +++ b/ci/Jenkinsfile @@ -0,0 +1,99 @@ +library 'status-jenkins-lib@v1.4.3' + +pipeline { + agent { label 'linux' } + + options { + timestamps() + disableConcurrentBuilds() + /* Prevent Jenkins jobs from running forever */ + timeout(time: 40, unit: 'MINUTES') + /* Limit builds retained */ + buildDiscarder(logRotator( + numToKeepStr: '10', + daysToKeepStr: '30', + artifactNumToKeepStr: '10', + )) + } + + /* WARNING: Defining parameters here with the ?: trick causes them to remember last value. */ + parameters { + booleanParam( + name: 'PUBLISH', + description: 'Trigger publishing of build results for nightly or release.', + defaultValue: getPublishDefault(params.PUBLISH), + ) + } + + stages { + stage('Build') { + parallel { + stage('iOS') { steps { script { + ios = jenkins.Build('go-waku/platforms/ios') + } } } + stage('Android') { steps { script { + android = jenkins.Build('go-waku/platforms/android') + } } } + stage('Linux') { steps { script { + linux = jenkins.Build('go-waku/platforms/linux') + } } } + } + } + stage('Archive') { + steps { script { + sh('rm -f pkg/*') + jenkins.copyArts(ios) + jenkins.copyArts(android) + jenkins.copyArts(linux) + sha = "pkg/${utils.pkgFilename(ext: 'sha256')}" + dir('pkg') { + /* generate sha256 checksums for upload */ + sh "sha256sum * | tee ../${sha}" + archiveArtifacts('*') + } + } } + } + stage('Upload') { + steps { script { + /* object for easier URLs handling */ + urls = [ + /* mobile */ + Android: utils.pkgUrl(android), + iOS: utils.pkgUrl(ios), + Linux: utils.pkgUrl(linux), + /* upload the sha256 checksums file too */ + SHA: s3.uploadArtifact(sha), + ] + /* add URLs to the build description */ + jenkins.setBuildDesc(urls) + } } + } + stage('Publish') { + when { expression { params.PUBLISH } } + steps { script { + github.publishReleaseFiles(repo: 'status-desktop'); + } } + } + } +} + +/* Helper that generates list of available choices for a parameter + * but re-orders them based on the currently set value. First is default. */ +def List genChoices(String previousChoice, List defaultChoices) { + if (previousChoice == null) { + return defaultChoices + } + choices = defaultChoices.minus(previousChoice) + choices.add(0, previousChoice) + return choices +} + +/* Helper that makes PUBLISH default to 'false' unless: + * - The build is for a release branch + * - A user explicitly specified a value + * Since release builds create and re-create GitHub drafts every time. */ +def Boolean getPublishDefault(Boolean previousValue) { + if (env.JOB_NAME.startsWith('go-waku/release')) { return true } + if (previousValue != null) { return previousValue } + return false +} \ No newline at end of file diff --git a/ci/Jenkinsfile.linux b/ci/Jenkinsfile.linux new file mode 100644 index 00000000..48c4aab4 --- /dev/null +++ b/ci/Jenkinsfile.linux @@ -0,0 +1,78 @@ +library 'status-jenkins-lib@v1.3.3' + +pipeline { + agent { + dockerfile { + label 'linux' + dir 'src/github.com/waku-org/go-waku/scripts/linux' + } + } + + options { + timestamps() + disableConcurrentBuilds() + /* Prevent Jenkins jobs from running forever */ + timeout(time: 30, unit: 'MINUTES') + /* Go requires a certain directory structure */ + checkoutToSubdirectory('src/github.com/waku-org/go-waku') + /* Limit builds retained */ + buildDiscarder(logRotator( + numToKeepStr: '10', + daysToKeepStr: '20', + artifactNumToKeepStr: '10', + )) + /* Allows combined build to copy */ + copyArtifactPermission('/go-waku/*') + } + + environment { + BUILD_PLATFORM = 'linux' + /* Other stuff */ + TARGET = 'linux' + REPO = "${env.WORKSPACE}/src/github.com/waku-org/go-waku" + GOPATH = "${env.WORKSPACE}" + PATH = "/usr/local/go/bin:${env.PATH}:${env.GOPATH}/bin" + } + + stages { + + stage('Prep') { steps { dir(env.REPO) { script { + env.DEB_ARTIFACT = "${env.REPO}/pkg/" + utils.pkgFilename( + name: "go-waku", + type: "x86_64", + ext: "deb" + ) + } } } } + + stage('Build') { steps { dir(env.REPO) { + sh "make" + dir('./scripts/linux') { + sh "./fpm-build.sh" + } + dir('build') { + sh "cp gowaku*.deb ${env.DEB_ARTIFACT}" + } + } } } + + stage('Parallel Upload') { + parallel { + stage('Archive') { + steps { script { + archiveArtifacts(env.DEB_ARTIFACT.minus("${env.WORKSPACE}/")) + } } + } + stage('Upload') { + steps { script { + env.PKG_URL = s3.uploadArtifact(env.DEB_ARTIFACT) + jenkins.setBuildDesc(x86_64_deb: env.PKG_URL) + } } + } + } + } + } + post { + success { script { github.notifyPR(true) } } + failure { script { github.notifyPR(false) } } + always { cleanWs() } + } +} \ No newline at end of file diff --git a/scripts/linux/Dockerfile b/scripts/linux/Dockerfile index 2109d690..dd95d204 100644 --- a/scripts/linux/Dockerfile +++ b/scripts/linux/Dockerfile @@ -10,7 +10,7 @@ LABEL description="go-waku: deb/rpm builder" RUN export DEBIAN_FRONTEND=noninteractive \ && apt update -yq \ - && apt install -yq ruby wget git rpm build-essential + && apt install -yq ruby wget git rpm build-essential s3cmd curl # Installing Golang RUN GOLANG_SHA256="74b9640724fd4e6bb0ed2a1bc44ae813a03f1e72a4c76253e2d5c015494430ba" \ diff --git a/scripts/linux/build-pkgs.sh b/scripts/linux/build-pkgs.sh index 065b58a2..0efff30a 100755 --- a/scripts/linux/build-pkgs.sh +++ b/scripts/linux/build-pkgs.sh @@ -5,48 +5,4 @@ make cd /go-waku/scripts/linux -parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )/../../ - -VERSION=`cat ${parent_path}/VERSION` - -if [ ! -f ${parent_path}/build/waku ] -then - echo "waku binary does not exist. Execute make first" - exit -fi - -tmpdir=`mktemp -d` - -chmod 777 ${tmpdir} - -cp ${parent_path}/build/waku ${tmpdir} - -strip --strip-unneeded ${tmpdir}/waku - -pushd ${tmpdir} - -fpm_build () { - fpm \ - -s dir -t $1 \ - -p gowaku-${VERSION}-x86_64.$1 \ - --name go-waku \ - --license "MIT, Apache 2.0" \ - --version ${VERSION} \ - --architecture x86_64 \ - --depends libc6 \ - --description "Go implementation of Waku v2 protocol" \ - --url "https://github.com/waku-org/go-waku" \ - --maintainer "Richard Ramos " \ - waku=/usr/bin/waku -} - -fpm_build "deb" -fpm_build "rpm" - -echo "./././.asasdasd" - -ls - -mv *.deb *.rpm ${parent_path}/build/. - -popd +./fpm-build.sh diff --git a/scripts/linux/fpm-build.sh b/scripts/linux/fpm-build.sh new file mode 100755 index 00000000..b3700821 --- /dev/null +++ b/scripts/linux/fpm-build.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )/../../ + +VERSION=`cat ${parent_path}/VERSION` + +if [ ! -f ${parent_path}/build/waku ] +then + echo "waku binary does not exist. Execute make first" + exit +fi + +tmpdir=`mktemp -d` + +chmod 777 ${tmpdir} + +cp ${parent_path}/build/waku ${tmpdir} + +strip --strip-unneeded ${tmpdir}/waku + +pushd ${tmpdir} + +fpm_build () { + fpm \ + -s dir -t $1 \ + -p gowaku-${VERSION}-x86_64.$1 \ + --name go-waku \ + --license "MIT, Apache 2.0" \ + --version ${VERSION} \ + --architecture x86_64 \ + --depends libc6 \ + --description "Go implementation of Waku v2 protocol" \ + --url "https://github.com/waku-org/go-waku" \ + --maintainer "Richard Ramos " \ + waku=/usr/bin/waku +} + +fpm_build "deb" +fpm_build "rpm" + +ls + +mv *.deb *.rpm ${parent_path}/build/. + +popd