From 8119a01bf6df2946309bc1a832c8e21178303399 Mon Sep 17 00:00:00 2001 From: William Petit Date: Fri, 31 Mar 2023 14:29:10 +0200 Subject: [PATCH] chore: add jenkins pipeline --- Jenkinsfile | 69 +++++++++++++++++++++++++++++++++++++++++ Makefile | 7 +++-- misc/jenkins/Dockerfile | 24 ++++++++++++++ 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 Jenkinsfile create mode 100644 misc/jenkins/Dockerfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..3797724 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,69 @@ +@Library('cadoles') _ + +pipeline { + agent { + dockerfile { + label 'docker' + filename 'Dockerfile' + dir 'misc/jenkins' + } + } + + stages { + stage('Run unit tests') { + steps { + script { + withCredentials([ + usernamePassword([ + credentialsId: 'forge-jenkins', + usernameVariable: 'GIT_USERNAME', + passwordVariable: 'GIT_PASSWORD' + ]) + ]) { + sh ''' + 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' + export GOPRIVATE=forge.cadoles.com/arcad/edge + make test + ''' + } + } + } + } + + stage('Release') { + when { + anyOf { + branch 'master' + branch 'develop' + } + } + steps { + script { + withCredentials([ + usernamePassword([ + credentialsId: 'forge-jenkins', + usernameVariable: 'GITEA_RELEASE_USERNAME', + passwordVariable: 'GITEA_RELEASE_PASSWORD' + ]) + ]) { + sh 'make gitea-release' + } + def currentVersion = sh(returnStdout: true, script: 'make full-version').trim() + build( + job: "../emissary-firmware/${env.GIT_BRANCH}", + parameters: [ + [$class: 'StringParameterValue', name: 'emissaryRelease', value: currentVersion] + ] + ) + } + } + } + } + + post { + always { + cleanWs() + } + } +} diff --git a/Makefile b/Makefile index ec28dad..9061057 100644 --- a/Makefile +++ b/Makefile @@ -135,7 +135,7 @@ gitea-release: tools/gitea-release/bin/gitea-release.sh goreleaser 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 tools/gitea-release/bin/gitea-release.sh: @@ -150,4 +150,7 @@ AGENT_ID ?= 1 load-sample-specs: cat misc/spec-samples/app.emissary.cadoles.com.json | ./bin/server api agent spec update -a $(AGENT_ID) --no-patch --spec-data - --spec-name app.emissary.cadoles.com - cat misc/spec-samples/proxy.emissary.cadoles.com.json | ./bin/server api agent spec update -a $(AGENT_ID) --no-patch --spec-data - --spec-name proxy.emissary.cadoles.com \ No newline at end of file + cat misc/spec-samples/proxy.emissary.cadoles.com.json | ./bin/server api agent spec update -a $(AGENT_ID) --no-patch --spec-data - --spec-name proxy.emissary.cadoles.com + +full-version: + @echo $(FULL_VERSION) \ No newline at end of file diff --git a/misc/jenkins/Dockerfile b/misc/jenkins/Dockerfile new file mode 100644 index 0000000..c852821 --- /dev/null +++ b/misc/jenkins/Dockerfile @@ -0,0 +1,24 @@ +FROM reg.cadoles.com/proxy_cache/library/ubuntu:22.04 + +ARG HTTP_PROXY= +ARG HTTPS_PROXY= +ARG http_proxy= +ARG https_proxy= +ARG GO_VERSION=1.19.2 + +# 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 + +# Install Go +RUN mkdir -p /tmp \ + && wget -O /tmp/go${GO_VERSION}.linux-amd64.tar.gz https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz \ + && rm -rf /usr/local/go \ + && mkdir -p /usr/local \ + && tar -C /usr/local -xzf /tmp/go${GO_VERSION}.linux-amd64.tar.gz + +ENV PATH="${PATH}:/usr/local/go/bin" + +# 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