From 2c701ffc16ea0ee4e4fdaac16c05fb8fdc01e6bb Mon Sep 17 00:00:00 2001 From: William Petit Date: Fri, 31 Mar 2023 16:02:28 +0200 Subject: [PATCH] chore: add jenkins pipeline --- Jenkinsfile | 102 ++++++++++++++++++++++++++++++++++++++++ Makefile | 8 ++-- emissary_release.txt | 1 + misc/jenkins/Dockerfile | 14 ++++++ 4 files changed, 121 insertions(+), 4 deletions(-) create mode 100644 Jenkinsfile create mode 100644 emissary_release.txt create mode 100644 misc/jenkins/Dockerfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..4d9ade1 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,102 @@ +pipeline { + agent { + dockerfile { + filename 'Dockerfile' + dir 'misc/jenkins' + } + } + + parameters { + persistentText(name: 'emissaryRelease', defaultValue: 'latest', description: 'Numéro de release Emissary', successfulOnly: false) + } + + stages { + stage('Cancel older jobs') { + steps { + script { + def buildNumber = env.BUILD_NUMBER as int + if (buildNumber > 1) milestone(buildNumber - 1) + milestone(buildNumber) + } + } + } + + stage('Update emissary release') { + when { + expression { + return params.emissaryRelease != 'latest' + } + } + steps { + script { + currentEmissaryRelease = readFile('emissary_release.txt').trim() + + if (currentEmissaryRelease == params.emissaryRelease) { + currentBuild.result = 'SUCCESS' + return + } + + withCredentials([ + usernamePassword([ + credentialsId: 'forge-jenkins', + usernameVariable: 'GIT_USERNAME', + passwordVariable: 'GIT_PASSWORD' + ]) + ]) { + sh """ + git config user.email "jenkins@cadoles.com" + git config user.name "Jenkins" + git config credential.https://forge.cadoles.com.username "\$GIT_USERNAME" + git config credential.https://forge.cadoles.com.helper '!f() { test "\$1" = get && echo "password=\$GIT_PASSWORD"; }; f' + + echo '${params.emissaryRelease}' > emissary_release.txt + git add emissary_release.txt + git commit -m "feat: use emissary ${params.emissaryRelease}" + git pull --rebase + git push origin \$(git rev-parse HEAD):${env.GIT_BRANCH} + """ + } + } + } + } + + stage('Build and release') { + steps { + script { + withCredentials([ + usernamePassword([ + credentialsId: 'forge-jenkins', + usernameVariable: 'GITEA_DOWNLOAD_USERNAME', + passwordVariable: 'GITEA_DOWNLOAD_PASSWORD' + ]) + ]) { + sh ''' + make download-emissary-release + make all + ''' + } + } + } + } + + stage('Release') { + steps { + withCredentials([ + usernamePassword([ + credentialsId: 'forge-jenkins', + usernameVariable: 'GITEA_RELEASE_USERNAME', + passwordVariable: 'GITEA_RELEASE_PASSWORD' + ]) + ]) { + sh 'make gitea-release' + } + } + } + } + + post { + always { + cleanWs() + } + } +} diff --git a/Makefile b/Makefile index c29a4e0..92a43ee 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ IMAGEBUILDER_CUSTOM_FILES_DIR_PATH := $(IMAGEBUILDER_DIR_PATH)/files BIN_DIR := "$(shell readlink -f bin)/$(OPENWRT_VERSION)/$(OPENWRT_TARGET)/$(OPENWRT_PROFILE)$(BIN_DIR_NAME_SUFFIX)" -GITEA_DOWNLOAD_RELEASE_NAME ?= v2023.3.29-e5b6c5e +GITEA_DOWNLOAD_RELEASE_NAME ?= $(shell cat emissary_release.txt) EMISSARY_ARCH ?= armv6 EMISSARY_RECONCILIATION_INTERVAL ?= @@ -110,7 +110,7 @@ gitea-release: tools/gitea-release/bin/gitea-release.sh GITEA_RELEASE_COMMITISH_TARGET="$(GIT_VERSION)" \ GITEA_RELEASE_IS_DRAFT="false" \ GITEA_RELEASE_BODY="" \ - GITEA_RELEASE_ATTACHMENTS="$(shell find .gitea-release/* -type f)" \ + GITEA_RELEASE_ATTACHMENTS="$$(find .gitea-release/* -type f)" \ tools/gitea-release/bin/gitea-release.sh .PHONY: download-emissary-release @@ -143,5 +143,5 @@ UPX_VERSION := 4.0.2 tools/upx/bin/upx: mkdir -p tools/upx/bin curl -L --output tools/upx/upx-$(UPX_VERSION)-amd64_linux.tar.xz https://github.com/upx/upx/releases/download/v$(UPX_VERSION)/upx-$(UPX_VERSION)-amd64_linux.tar.xz - cd tools/upx && tar -xJf upx-$(UPX_VERSION)-amd64_linux.tar.xz - ln -s $(shell readlink -f tools/upx/upx-$(UPX_VERSION)-amd64_linux/upx) tools/upx/bin/upx \ No newline at end of file + cd tools/upx && tar -xJf upx-$(UPX_VERSION)-amd64_linux.tar.xz && wait $$! + $(SHELL) -c 'ln -s $$(readlink -f tools/upx/upx-$(UPX_VERSION)-amd64_linux/upx) tools/upx/bin/upx' \ No newline at end of file diff --git a/emissary_release.txt b/emissary_release.txt new file mode 100644 index 0000000..02ec9d6 --- /dev/null +++ b/emissary_release.txt @@ -0,0 +1 @@ +v2023.3.29-e5b6c5e \ No newline at end of file diff --git a/misc/jenkins/Dockerfile b/misc/jenkins/Dockerfile new file mode 100644 index 0000000..337948b --- /dev/null +++ b/misc/jenkins/Dockerfile @@ -0,0 +1,14 @@ +FROM reg.cadoles.com/proxy_cache/library/ubuntu:22.04 + +ARG HTTP_PROXY= +ARG HTTPS_PROXY= +ARG http_proxy= +ARG https_proxy= + +# Install dev environment dependencies +RUN export DEBIAN_FRONTEND=noninteractive &&\ + apt-get update -y &&\ + apt-get install -y --no-install-recommends curl ca-certificates build-essential wget unzip tar git jq gawk python3 rsync file + +# Add LetsEncrypt certificates +RUN curl -k https://forge.cadoles.com/Cadoles/Jenkins/raw/branch/master/resources/com/cadoles/common/add-letsencrypt-ca.sh | bash \ No newline at end of file