2024-02-14 15:37:30 +00:00
|
|
|
#!/usr/bin/env groovy
|
2024-02-27 13:13:52 +00:00
|
|
|
library 'status-jenkins-lib@v1.8.9'
|
2024-02-14 15:37:30 +00:00
|
|
|
|
2020-11-26 02:59:36 +00:00
|
|
|
pipeline {
|
|
|
|
agent { label 'linux' }
|
|
|
|
|
2020-11-30 11:59:53 +00:00
|
|
|
options {
|
|
|
|
timestamps()
|
2022-06-08 11:48:30 +00:00
|
|
|
timeout(time: 20, unit: 'MINUTES')
|
2020-11-30 11:59:53 +00:00
|
|
|
buildDiscarder(logRotator(
|
|
|
|
numToKeepStr: '10',
|
|
|
|
daysToKeepStr: '30',
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
2020-11-26 02:59:36 +00:00
|
|
|
parameters {
|
|
|
|
string(
|
2020-11-30 11:59:53 +00:00
|
|
|
name: 'MAKE_TARGET',
|
|
|
|
description: 'Makefile target to build. Optional Parameter.',
|
|
|
|
defaultValue: params.MAKE_TARGET ?: 'wakunode2',
|
2020-11-26 02:59:36 +00:00
|
|
|
)
|
|
|
|
string(
|
|
|
|
name: 'IMAGE_TAG',
|
2020-11-30 11:59:53 +00:00
|
|
|
description: 'Name of Docker tag to push. Optional Parameter.',
|
2023-09-26 10:10:23 +00:00
|
|
|
defaultValue: getDefaultImageTag()
|
2020-11-26 02:59:36 +00:00
|
|
|
)
|
|
|
|
string(
|
|
|
|
name: 'IMAGE_NAME',
|
2020-11-30 11:59:53 +00:00
|
|
|
description: 'Name of Docker image to push.',
|
2024-02-19 10:31:34 +00:00
|
|
|
defaultValue: params.IMAGE_NAME ?: 'harbor.status.im/wakuorg/nwaku',
|
2023-09-26 10:09:20 +00:00
|
|
|
)
|
|
|
|
string(
|
|
|
|
name: 'DOCKER_CRED',
|
2023-11-16 13:57:34 +00:00
|
|
|
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'
|
2020-11-26 02:59:36 +00:00
|
|
|
)
|
|
|
|
string(
|
2022-05-17 19:11:07 +00:00
|
|
|
name: 'NIMFLAGS',
|
2020-11-30 11:59:53 +00:00
|
|
|
description: 'Flags for Nim compilation.',
|
2022-07-22 11:45:47 +00:00
|
|
|
defaultValue: params.NIMFLAGS ?: [
|
|
|
|
'--colors:off',
|
|
|
|
'-d:disableMarchNative',
|
|
|
|
'-d:chronicles_colors:none',
|
|
|
|
'-d:insecure',
|
|
|
|
].join(' ')
|
2020-11-26 02:59:36 +00:00
|
|
|
)
|
2023-11-08 12:54:55 +00:00
|
|
|
choice(
|
|
|
|
name: "LOWEST_LOG_LEVEL_ALLOWED",
|
2023-11-08 15:52:53 +00:00
|
|
|
choices: ['TRACE', 'DEGUG', 'INFO', 'NOTICE', 'WARN', 'ERROR', 'FATAL'],
|
2023-11-08 12:54:55 +00:00
|
|
|
description: "Defines the log level, which will be available at runtime (Chronicles log level)",
|
2023-05-23 08:44:57 +00:00
|
|
|
)
|
2023-05-15 16:25:25 +00:00
|
|
|
booleanParam(
|
|
|
|
name: 'DEBUG',
|
|
|
|
description: 'Enable debug features (heaptrack).',
|
|
|
|
defaultValue: false
|
|
|
|
)
|
2020-11-26 02:59:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stages {
|
|
|
|
stage('Build') {
|
|
|
|
steps { script {
|
|
|
|
image = docker.build(
|
2023-09-26 10:10:40 +00:00
|
|
|
"${params.IMAGE_NAME}:${params.IMAGE_TAG ?: env.GIT_COMMIT.take(8)}",
|
2024-02-27 13:13:52 +00:00
|
|
|
"--label=build='${env.BUILD_URL}' " +
|
|
|
|
"--label=commit='${git.commit()}' " +
|
|
|
|
"--label=version='${git.describe()}' " +
|
2020-11-30 11:59:53 +00:00
|
|
|
"--build-arg=MAKE_TARGET='${params.MAKE_TARGET}' " +
|
2024-02-02 13:13:07 +00:00
|
|
|
"--build-arg=NIMFLAGS='${params.NIMFLAGS} -d:postgres ' " +
|
2023-11-08 12:54:55 +00:00
|
|
|
"--build-arg=LOG_LEVEL='${params.LOWEST_LOG_LEVEL_ALLOWED}' " +
|
2023-05-15 16:25:25 +00:00
|
|
|
"--target=${params.DEBUG ? "debug" : "prod"} ."
|
2020-11-26 02:59:36 +00:00
|
|
|
)
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
|
2023-06-27 13:28:36 +00:00
|
|
|
stage('Check') {
|
|
|
|
steps { script {
|
|
|
|
image.inside('--entrypoint=""') { c ->
|
|
|
|
sh '/usr/bin/wakunode --version'
|
|
|
|
}
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
|
2020-11-26 02:59:36 +00:00
|
|
|
stage('Push') {
|
2023-09-26 10:10:23 +00:00
|
|
|
when { expression { params.IMAGE_TAG != '' } }
|
2020-11-26 02:59:36 +00:00
|
|
|
steps { script {
|
2023-09-26 10:09:20 +00:00
|
|
|
withDockerRegistry([
|
2023-11-16 13:57:34 +00:00
|
|
|
credentialsId: params.DOCKER_CRED, url: params.DOCKER_REGISTRY_URL
|
2023-09-26 10:09:20 +00:00
|
|
|
]) {
|
2020-11-26 02:59:36 +00:00
|
|
|
image.push()
|
2023-09-26 10:10:40 +00:00
|
|
|
/* 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)
|
2024-05-27 10:52:48 +00:00
|
|
|
image.push('latest-release')
|
2023-09-26 10:10:40 +00:00
|
|
|
}
|
2020-11-26 02:59:36 +00:00
|
|
|
}
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
} // stages
|
2023-09-26 10:10:23 +00:00
|
|
|
|
2020-11-26 02:59:36 +00:00
|
|
|
post {
|
2022-09-09 08:46:06 +00:00
|
|
|
success { script {
|
2023-09-27 14:30:20 +00:00
|
|
|
discord.send(
|
2024-02-14 15:37:30 +00:00
|
|
|
header: '**Nim-Waku deployment successful!**',
|
2022-10-12 13:31:30 +00:00
|
|
|
cred: 'discord-waku-deployments-webhook',
|
2024-02-14 15:37:30 +00:00
|
|
|
descPrefix: "Image: [`${IMAGE_NAME}:${IMAGE_TAG}`](https://hub.docker.com/r/${IMAGE_NAME}/tags?name=${IMAGE_TAG})"
|
2022-10-12 13:31:30 +00:00
|
|
|
)
|
2022-09-09 08:46:06 +00:00
|
|
|
} }
|
2020-11-26 02:59:36 +00:00
|
|
|
always { sh 'docker image prune -f' }
|
|
|
|
} // post
|
|
|
|
} // pipeline
|
2023-09-26 10:10:23 +00:00
|
|
|
|
|
|
|
def getDefaultImageTag() {
|
|
|
|
switch (env.JOB_BASE_NAME) {
|
|
|
|
case 'docker-latest': return 'latest'
|
|
|
|
case 'docker-release': return 'stable'
|
2023-10-31 16:42:53 +00:00
|
|
|
default: return env.JOB_BASE_NAME
|
2023-09-26 10:10:23 +00:00
|
|
|
}
|
|
|
|
}
|