1
0
Fork 0
mirror of https://github.com/parrazam/radicale-docker.git synced 2024-11-25 03:59:11 +01:00
radicale-docker/Jenkinsfile

110 lines
3.3 KiB
Text
Raw Normal View History

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'
2022-02-27 20:29:33 +01:00
values 'linux/amd64', 'linux/arm64', 'linux/arm'
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 {
2022-02-27 20:29:33 +01:00
SOURCE_IMAGE = SOURCE
2021-08-05 13:58:43 +02:00
TARGET_IMAGE = TARGET+':'+PLATFORM.tokenize('/')[1]
if (env.BRANCH_NAME.startsWith('release/')) {
2022-02-27 20:29:33 +01:00
SOURCE_IMAGE += ":" + VERSION
2021-08-05 13:58:43 +02:00
TARGET_IMAGE += "." + VERSION
} else {
TARGET_IMAGE += VERSION
}
}
echo "Building ${TARGET_IMAGE} image..."
sh "docker pull ${SOURCE_IMAGE}"
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') {
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 = ''
2022-02-27 20:29:33 +01:00
for (ARCH in ['linux/amd64', 'linux/arm64', 'linux/arm']) {
2021-08-05 13:58:43 +02:00
IMAGES += ' -a ' + TARGET + ':' + ARCH.tokenize('/')[1] + VERSION
}
}
echo "${IMAGES}"
2022-02-27 20:29:33 +01:00
withCredentials([usernamePassword(credentialsId: 'dockerHub', passwordVariable: 'dockerHubPassword', usernameVariable: 'dockerHubUser')]) {
sh "echo ${env.dockerHubPassword} | docker login -u ${env.dockerHubUser} --password-stdin"
sh "docker manifest create ${TARGET}:${GROUPED_VERSION} ${IMAGES}"
sh "docker manifest push ${TARGET}:${GROUPED_VERSION}"
}
2021-08-03 22:23:44 +02:00
}
}
}
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}:{}"
}
}
}