From b41dc2851e7aea872b6084ec12388d600b2cc898 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Mon, 30 Nov 2020 12:59:53 +0100 Subject: [PATCH] ci: add MAKE_TARGET parameter, remove default from IMAGE_TAG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adjustments to Jenkinsfile to allow building of different targets and pushing images with different tags depending on job parameters. If we specify a `string` parameter in `parameters` they will be overwritten in job definition after very job build. I created four jobs at: https://ci.status.im/job/nim-waku/ * [manual](https://ci.status.im/job/nim-waku/job/manual/) - For building by hand * [deploy-v1-test](https://ci.status.im/job/nim-waku/job/deploy-v1-test/) - Auto build from `master` * [deploy-v2-test](https://ci.status.im/job/nim-waku/job/deploy-v2-test/) - Auto build from `master` * [deploy-v2-prod](https://ci.status.im/job/nim-waku/job/deploy-v2-prod/) - Triggered manually Signed-off-by: Jakub SokoĊ‚owski --- Jenkinsfile | 54 ++++++++++----------- docs/contributors/continuous-integration.md | 32 ++++++++++++ 2 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 docs/contributors/continuous-integration.md diff --git a/Jenkinsfile b/Jenkinsfile index 146a04aa9..fdbee382c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,29 +1,6 @@ pipeline { agent { label 'linux' } - parameters { - string( - name: 'BRANCH', - defaultValue: 'master', - description: 'Name of branch to build.' - ) - string( - name: 'IMAGE_TAG', - defaultValue: 'wakunode2', - description: 'Name of Docker tag to push.' - ) - string( - name: 'IMAGE_NAME', - defaultValue: 'statusteam/nim-waku', - description: 'Name of Docker image to push.' - ) - string( - name: 'NIM_PARAMS', - defaultValue: '-d:disableMarchNative -d:chronicles_colors:none -d:insecure', - description: 'Flags for Nim compilation.' - ) - } - options { timestamps() /* manage how many builds we keep */ @@ -33,12 +10,37 @@ pipeline { )) } + /* WARNING: Two more parameters can be defined. + * See 'environment' section. */ + parameters { + string( + name: 'MAKE_TARGET', + description: 'Makefile target to build. Optional Parameter.', + defaultValue: params.MAKE_TARGET ?: 'wakunode2', + ) + string( + name: 'IMAGE_TAG', + description: 'Name of Docker tag to push. Optional Parameter.', + defaultValue: params.IMAGE_TAG ?: 'deploy-v2-test', + ) + string( + name: 'IMAGE_NAME', + description: 'Name of Docker image to push.', + defaultValue: params.IMAGE_NAME ?: 'statusteam/nim-waku', + ) + string( + name: 'NIM_PARAMS', + description: 'Flags for Nim compilation.', + defaultValue: params.NIM_PARAMS ?: '-d:disableMarchNative -d:chronicles_colors:none -d:insecure', + ) + } + stages { stage('Build') { steps { script { image = docker.build( "${params.IMAGE_NAME}:${env.GIT_COMMIT.take(6)}", - "--build-arg=MAKE_TARGET='${params.IMAGE_TAG}' " + + "--build-arg=MAKE_TARGET='${params.MAKE_TARGET}' " + "--build-arg=NIM_PARAMS='${params.NIM_PARAMS}' ." ) } } @@ -48,9 +50,7 @@ pipeline { steps { script { withDockerRegistry([credentialsId: "dockerhub-statusteam-auto", url: ""]) { image.push() - } - withDockerRegistry([credentialsId: "dockerhub-statusteam-auto", url: ""]) { - image.push(params.IMAGE_TAG) + image.push(env.IMAGE_TAG) } } } } diff --git a/docs/contributors/continuous-integration.md b/docs/contributors/continuous-integration.md new file mode 100644 index 000000000..c3217ad65 --- /dev/null +++ b/docs/contributors/continuous-integration.md @@ -0,0 +1,32 @@ +# Description + +This document describes the continuous integration setup for `nim-waku`. + +# Details + +The CI setup exists on the Status.im Jenkins instance: + +https://ci.status.im/job/nim-waku/ + +It currently consists four jobs: + +* [manual](https://ci.status.im/job/nim-waku/job/manual/) - For manually executing builds using parameters. +* [deploy-v1-test](https://ci.status.im/job/nim-waku/job/deploy-v1-test/) - Builds every new commit in `master` and deploys to `wakuv1.test` fleet. +* [deploy-v2-test](https://ci.status.im/job/nim-waku/job/deploy-v2-test/) - Builds every new commit in `master` and deploys to `wakuv2.test` fleet. +* [deploy-v2-prod](https://ci.status.im/job/nim-waku/job/deploy-v2-prod/) - Currently has no automatic trigger, and deploys to `wakuv2.prod` fleet. + +# Configuration + +The main configuration file is [`Jenkinsfile`](../../Jenkinsfile) at the root of this repo. + +Key part is the definition of four `parameters`: + +* `MAKE_TARGET` - Which `Makefile` target is built. +* `IMAGE_TAG` - Tag of the Docker image to push. +* `IMAGE_NAME` - Name of the Docker image to push. +* `NIM_PARAMS` - Nim compilation parameters. + +The use of `?:` [Elvis operator](http://groovy-lang.org/operators.html#_elvis_operator) plays a key role in allowing parameters to be changed for each defined job in Jenkins without it being overridden by the `Jenkinsfile` defaults after every job run. +```groovy +defaultValue: params.IMAGE_TAG ?: 'deploy-v2-test', +```