2021-08-03 22:23:44 +02:00
|
|
|
pipeline {
|
2021-08-05 13:58:43 +02:00
|
|
|
agent any
|
2021-08-03 22:23:44 +02:00
|
|
|
environment {
|
|
|
|
SOURCE = "tomsquest/docker-radicale"
|
|
|
|
TARGET = "parrazam/radicale-with-infcloud"
|
|
|
|
MASTER_BRANCH = "master"
|
2021-08-05 13:58:43 +02:00
|
|
|
RELEASE_BRANCH = "release/*"
|
|
|
|
VERSION = ''
|
2021-08-03 22:23:44 +02:00
|
|
|
}
|
|
|
|
options {
|
|
|
|
skipStagesAfterUnstable()
|
|
|
|
}
|
|
|
|
stages {
|
2021-08-05 13:58:43 +02:00
|
|
|
stage('Configure pipeline for branch type') {
|
2021-08-03 22:23:44 +02:00
|
|
|
steps {
|
2021-08-05 13:58:43 +02:00
|
|
|
script {
|
|
|
|
if (env.BRANCH_NAME.startsWith('release/')) {
|
|
|
|
VERSION = (env.BRANCH_NAME).tokenize('/')[1]
|
|
|
|
} else if (env.BRANCH_NAME.equals('master')) {
|
|
|
|
VERSION = ''
|
|
|
|
} else {
|
|
|
|
VERSION = '-SNAPSHOT'
|
|
|
|
}
|
|
|
|
}
|
2021-08-03 22:23:44 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-05 13:58:43 +02:00
|
|
|
stage('Delete older images') {
|
2021-08-03 22:23:44 +02:00
|
|
|
steps {
|
2021-08-05 13:58:43 +02:00
|
|
|
echo "Removing existing images in local..."
|
|
|
|
sh "docker images | grep ${TARGET} | tr -s ' ' | cut -d ' ' -f 2 | xargs -I {} docker rmi ${TARGET}:{}"
|
2021-08-03 22:23:44 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-05 13:58:43 +02:00
|
|
|
stage("Build image") {
|
|
|
|
matrix {
|
|
|
|
axes {
|
|
|
|
axis {
|
|
|
|
name 'PLATFORM'
|
2021-12-21 13:32:14 +01:00
|
|
|
values 'linux/amd64', 'linux/arm', 'linux/386'
|
2021-08-05 13:58:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Build by platform') {
|
|
|
|
options {
|
|
|
|
lock( 'synchronous-matrix' )
|
|
|
|
}
|
|
|
|
steps {
|
|
|
|
echo "Building for ${PLATFORM}"
|
|
|
|
script {
|
|
|
|
stage("Build ${PLATFORM}") {
|
|
|
|
script {
|
|
|
|
SOURCE_IMAGE = SOURCE+':'+PLATFORM.tokenize('/')[1]
|
|
|
|
TARGET_IMAGE = TARGET+':'+PLATFORM.tokenize('/')[1]
|
|
|
|
if (env.BRANCH_NAME.startsWith('release/')) {
|
|
|
|
SOURCE_IMAGE += "." + VERSION
|
|
|
|
TARGET_IMAGE += "." + VERSION
|
|
|
|
} else {
|
|
|
|
TARGET_IMAGE += VERSION
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "Building ${TARGET_IMAGE} image..."
|
|
|
|
sh "docker pull ${SOURCE_IMAGE}"
|
2021-12-21 12:40:58 +01:00
|
|
|
sh "docker buildx build -t ${TARGET_IMAGE} --platform ${PLATFORM} --build-arg VERSION=${PLATFORM.tokenize('/')[1]} ."
|
2021-08-05 13:58:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-03 22:23:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Publish images to Docker Hub') {
|
|
|
|
when {
|
2021-08-05 13:58:43 +02:00
|
|
|
anyOf {
|
|
|
|
branch "${MASTER_BRANCH}"
|
|
|
|
branch "${RELEASE_BRANCH}"
|
|
|
|
}
|
2021-08-03 22:23:44 +02:00
|
|
|
}
|
|
|
|
steps {
|
|
|
|
withCredentials([usernamePassword(credentialsId: 'dockerHub', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) {
|
|
|
|
sh "echo ${env.dockerHubPassword} | docker login -u ${env.dockerHubUser} --password-stdin"
|
|
|
|
sh "docker image push --all-tags ${TARGET}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Tagging with common version') {
|
|
|
|
environment {
|
2021-08-05 13:58:43 +02:00
|
|
|
GROUPED_VERSION = "${VERSION}"
|
2021-08-03 22:23:44 +02:00
|
|
|
}
|
|
|
|
when {
|
2021-08-05 13:58:43 +02:00
|
|
|
anyOf {
|
|
|
|
branch "${MASTER_BRANCH}"
|
|
|
|
branch "${RELEASE_BRANCH}"
|
|
|
|
}
|
2021-08-03 22:23:44 +02:00
|
|
|
}
|
|
|
|
steps {
|
2021-08-05 13:58:43 +02:00
|
|
|
script {
|
|
|
|
if (VERSION.equals('')) {
|
|
|
|
GROUPED_VERSION = 'latest'
|
|
|
|
}
|
|
|
|
if (env.BRANCH_NAME.startsWith('release/')) {
|
|
|
|
VERSION = '.' + (env.BRANCH_NAME).tokenize('/')[1]
|
|
|
|
}
|
|
|
|
IMAGES = ''
|
2021-12-21 12:40:58 +01:00
|
|
|
for (ARCH in PLATFORM) {
|
2021-08-05 13:58:43 +02:00
|
|
|
IMAGES += ' -a ' + TARGET + ':' + ARCH.tokenize('/')[1] + VERSION
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "${IMAGES}"
|
|
|
|
sh "docker manifest create ${TARGET}:${GROUPED_VERSION} ${IMAGES}"
|
2021-08-03 22:23:44 +02:00
|
|
|
sh "docker manifest push ${TARGET}:${GROUPED_VERSION}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-05 13:58:43 +02:00
|
|
|
|
2021-08-03 22:23:44 +02:00
|
|
|
post {
|
|
|
|
always {
|
|
|
|
echo "Removing existing images in local..."
|
|
|
|
sh "docker images | grep ${TARGET} | tr -s ' ' | cut -d ' ' -f 2 | xargs -I {} docker rmi ${TARGET}:{}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|