nwaku/ci/Jenkinsfile.release

124 lines
3.5 KiB
Groovy

#!/usr/bin/env groovy
library 'status-jenkins-lib@v1.8.17'
pipeline {
agent { label 'linux' }
options {
timestamps()
timeout(time: 20, unit: 'MINUTES')
buildDiscarder(logRotator(
numToKeepStr: '10',
daysToKeepStr: '30',
))
}
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: getDefaultImageTag()
)
string(
name: 'IMAGE_NAME',
description: 'Name of Docker image to push.',
defaultValue: params.IMAGE_NAME ?: 'harbor.status.im/wakuorg/nwaku',
)
string(
name: 'DOCKER_CRED',
description: 'Name of Docker Registry credential.',
defaultValue: params.DOCKER_CRED ?: 'harbor-wakuorg-robot',
)
string(
name: 'DOCKER_REGISTRY_URL',
description: 'URL of the Docker Registry',
defaultValue: params.DOCKER_REGISTRY_URL ?: 'https://harbor.status.im'
)
string(
name: 'NIMFLAGS',
description: 'Flags for Nim compilation.',
defaultValue: params.NIMFLAGS ?: [
'--colors:off',
'-d:disableMarchNative',
'-d:chronicles_colors:none',
'-d:insecure',
].join(' ')
)
choice(
name: "LOWEST_LOG_LEVEL_ALLOWED",
choices: ['TRACE', 'DEGUG', 'INFO', 'NOTICE', 'WARN', 'ERROR', 'FATAL'],
description: "Defines the log level, which will be available at runtime (Chronicles log level)",
)
booleanParam(
name: 'DEBUG',
description: 'Enable debug features (heaptrack).',
defaultValue: false
)
}
stages {
stage('Build') {
steps { script {
image = docker.build(
"${params.IMAGE_NAME}:${params.IMAGE_TAG ?: env.GIT_COMMIT.take(8)}",
"--label=build='${env.BUILD_URL}' " +
"--label=commit='${git.commit()}' " +
"--label=version='${git.describe('--tags')}' " +
"--build-arg=MAKE_TARGET='${params.MAKE_TARGET}' " +
"--build-arg=NIMFLAGS='${params.NIMFLAGS} -d:postgres ' " +
"--build-arg=LOG_LEVEL='${params.LOWEST_LOG_LEVEL_ALLOWED}' " +
"--target=${params.DEBUG ? "debug" : "prod"} ."
)
} }
}
stage('Check') {
steps { script {
image.inside('--entrypoint=""') { c ->
sh '/usr/bin/wakunode --version'
}
} }
}
stage('Push') {
when { expression { params.IMAGE_TAG != '' } }
steps { script {
withDockerRegistry([
credentialsId: params.DOCKER_CRED, url: params.DOCKER_REGISTRY_URL
]) {
image.push()
/* If Git ref is a tag push it as Docker tag too. */
if (params.GIT_REF ==~ /v\d+\.\d+\.\d+.*/) {
image.push(params.GIT_REF)
image.push('latest-release')
}
}
} }
}
} // stages
post {
success { script {
discord.send(
header: '**Nim-Waku deployment successful!**',
cred: 'discord-waku-deployments-webhook',
descPrefix: "Image: [`${IMAGE_NAME}:${IMAGE_TAG}`](https://hub.docker.com/r/${IMAGE_NAME}/tags?name=${IMAGE_TAG})"
)
} }
always { sh 'docker image prune -f' }
} // post
} // pipeline
def getDefaultImageTag() {
switch (env.JOB_BASE_NAME) {
case 'docker-latest': return 'latest'
case 'docker-release': return 'stable'
default: return env.JOB_BASE_NAME
}
}