mirror of https://github.com/status-im/go-waku.git
126 lines
3.2 KiB
Docker
126 lines
3.2 KiB
Docker
pipeline {
|
|
agent {
|
|
label 'linux && x86_64'
|
|
}
|
|
|
|
parameters {
|
|
string(
|
|
name: 'GIT_REF',
|
|
defaultValue: 'master',
|
|
description: 'Branch, tag, or commit to build.'
|
|
)
|
|
string(
|
|
name: 'IMAGE_NAME',
|
|
description: 'Docker image name.',
|
|
defaultValue: params.IMAGE_NAME ?: 'waku-org/go-waku',
|
|
)
|
|
string(
|
|
name: 'IMAGE_TAG',
|
|
description: 'Docker image tag.',
|
|
defaultValue: getDefaultImageTag(params.IMAGE_TAG)
|
|
)
|
|
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'
|
|
)
|
|
|
|
}
|
|
|
|
options {
|
|
timestamps()
|
|
buildDiscarder(logRotator(
|
|
numToKeepStr: '10',
|
|
daysToKeepStr: '30',
|
|
))
|
|
}
|
|
|
|
stages {
|
|
stage('Build') {
|
|
steps { script {
|
|
image = docker.build(
|
|
"${params.IMAGE_NAME}:${params.IMAGE_TAG ?: GIT_COMMIT.take(8)}",
|
|
"--build-arg='GIT_COMMIT=${GIT_COMMIT.take(8)}' ."
|
|
)
|
|
} }
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
} }
|
|
}
|
|
}
|
|
post {
|
|
success { script {
|
|
discordNotify(
|
|
header: 'Go-Waku build successful!',
|
|
cred: 'discord-waku-deployments-webhook',
|
|
)
|
|
} }
|
|
always { cleanWs() }
|
|
}
|
|
}
|
|
|
|
def discordNotify(Map args=[:]) {
|
|
def opts = [
|
|
header: args.header ?: 'Deployment successful!',
|
|
cred: args.cred ?: null,
|
|
]
|
|
def repo = [
|
|
url: GIT_URL.minus('.git'),
|
|
branch: GIT_BRANCH.minus('origin/'),
|
|
commit: GIT_COMMIT.take(8),
|
|
prev: (
|
|
env.GIT_PREVIOUS_SUCCESSFUL_COMMIT ?: env.GIT_PREVIOUS_COMMIT ?: 'master'
|
|
).take(8),
|
|
]
|
|
wrap([$class: 'BuildUser']) {
|
|
BUILD_USER_ID = env.BUILD_USER_ID
|
|
}
|
|
withCredentials([
|
|
string(
|
|
credentialsId: opts.cred,
|
|
variable: 'DISCORD_WEBHOOK',
|
|
),
|
|
]) {
|
|
discordSend(
|
|
link: env.BUILD_URL,
|
|
result: currentBuild.currentResult,
|
|
webhookURL: env.DISCORD_WEBHOOK,
|
|
title: "${env.JOB_NAME}#${env.BUILD_NUMBER}",
|
|
description: """
|
|
${opts.header}
|
|
Image: [`${IMAGE_NAME}:${IMAGE_TAG}`](https://hub.docker.com/r/${IMAGE_NAME}/tags?name=${IMAGE_TAG})
|
|
Branch: [`${repo.branch}`](${repo.url}/commits/${repo.branch})
|
|
Commit: [`${repo.commit}`](${repo.url}/commit/${repo.commit})
|
|
Diff: [`${repo.prev}...${repo.commit}`](${repo.url}/compare/${repo.prev}...${repo.commit})
|
|
By: [`${BUILD_USER_ID}`](${repo.url}/commits?author=${BUILD_USER_ID})
|
|
""",
|
|
)
|
|
}
|
|
}
|
|
|
|
def getDefaultImageTag(currentValue) {
|
|
switch (env.JOB_BASE_NAME) {
|
|
case 'docker-latest': return 'latest'
|
|
case 'docker-release': return 'stable'
|
|
case 'docker-manual': return ''
|
|
default: return currentValue
|
|
}
|
|
}
|