1
0
puyopuyotetr.is/Jenkinsfile

122 lines
5.8 KiB
Plaintext
Raw Normal View History

2023-09-11 18:07:03 +09:00
pipeline {
agent none
stages {
stage('Docker') {
agent {
docker {
2023-09-16 00:07:51 +09:00
label 'docker-linux-x86_64-sif'
2023-09-11 18:07:03 +09:00
image 'docker:24-cli'
args '--privileged -v /var/run/docker.sock:/var/run/docker.sock'
}
}
when {
anyOf {
branch pattern: 'test-.*', comparator: "REGEXP";
branch 'main';
buildingTag();
}
}
environment {
DOCKER_REGISTRY = 'ghcr.io'
GITHUB_ORG = 'cloudtoys'
DOCKER_IMAGE = "${env.DOCKER_REGISTRY}/${env.GITHUB_ORG}/yurutoot"
2023-09-11 18:07:03 +09:00
GHCR_TOKEN = credentials('siliconforest-jenkins-github-pat-package-rw')
}
stages {
stage('Prepare') {
steps {
script {
if (env.BRANCH_NAME.startsWith('test-')) {
env.DOCKER_TAG = 'testing'
env.DOCKER_LATEST = 'false'
2023-09-11 18:15:36 +09:00
} else if (env.BRANCH_NAME == 'main') {
2023-09-11 18:13:11 +09:00
env.DOCKER_TAG = 'main'
env.DOCKER_LATEST = 'true'
2023-09-11 18:07:03 +09:00
} else {
env.DOCKER_TAG = env.TAG_NAME.replaceAll('\\+', '-')
env.DOCKER_LATEST = 'true'
}
env.GITHUB_REPOSITORY = "${params.URL}"
env.SOURCE_BASE_URL = "https://github.com/CloudToys/YuruToot" // I'm lazy. Will fix it later
2023-09-11 18:07:03 +09:00
env.SOURCE_TAG = "${env.BRANCH_NAME}"
}
}
}
stage('Docker login') {
steps {
sh 'echo $GHCR_TOKEN_PSW | docker login ghcr.io -u $GHCR_TOKEN_USR --password-stdin'
}
}
stage('Build') {
matrix {
axes {
axis {
name 'TARGET'
values 'amd64'
}
}
stages {
stage('Build platform specific image') {
steps {
sh "docker build -t $DOCKER_IMAGE:$DOCKER_TAG-${TARGET} --platform linux/${TARGET} --build-arg \"GITHUB_REPOSITORY=${GITHUB_REPOSITORY}\" --build-arg \"SOURCE_BASE_URL=${SOURCE_BASE_URL}\" --build-arg \"SOURCE_TAG=${SOURCE_TAG}\" ."
2023-12-29 13:37:41 +09:00
sh "docker build --no-cache -t $DOCKER_IMAGE:$DOCKER_TAG-streaming-${TARGET} --platform linux/${TARGET} --build-arg \"GITHUB_REPOSITORY=${GITHUB_REPOSITORY}\" --build-arg \"SOURCE_BASE_URL=${SOURCE_BASE_URL}\" --build-arg \"SOURCE_TAG=${SOURCE_TAG}\" -f ./streaming/Dockerfile ."
2023-09-11 18:07:03 +09:00
script {
if (env.DOCKER_LATEST == 'true') {
sh "docker tag $DOCKER_IMAGE:$DOCKER_TAG-${TARGET} $DOCKER_IMAGE:latest-${TARGET}"
2023-12-29 13:37:41 +09:00
sh "docker tag $DOCKER_IMAGE:$DOCKER_TAG-streaming-${TARGET} $DOCKER_IMAGE:latest-streaming-${TARGET}"
2023-09-11 18:07:03 +09:00
}
}
}
}
stage('Push platform specific image') {
steps {
sh "docker push $DOCKER_IMAGE:$DOCKER_TAG-${TARGET}"
2023-12-29 13:37:41 +09:00
sh "docker push $DOCKER_IMAGE:$DOCKER_TAG-streaming-${TARGET}"
2023-09-11 18:07:03 +09:00
script {
if (env.DOCKER_LATEST == 'true') {
sh "docker push $DOCKER_IMAGE:latest-${TARGET}"
2023-12-29 13:37:41 +09:00
sh "docker push $DOCKER_IMAGE:latest-streaming-${TARGET}"
2023-12-29 00:21:03 +09:00
2023-09-11 18:07:03 +09:00
}
}
}
}
}
}
}
stage('Docker manifest') {
steps {
sh "docker manifest create $DOCKER_IMAGE:$DOCKER_TAG --amend $DOCKER_IMAGE:$DOCKER_TAG-amd64"
2023-12-29 13:37:41 +09:00
sh "docker manifest create $DOCKER_IMAGE:$DOCKER_TAG-streaming --amend $DOCKER_IMAGE:$DOCKER_TAG-streaming-amd64"
2023-09-11 18:07:03 +09:00
script {
if (env.DOCKER_LATEST == 'true') {
sh "docker manifest create $DOCKER_IMAGE:latest --amend $DOCKER_IMAGE:latest-amd64"
2023-12-29 13:37:41 +09:00
sh "docker manifest create $DOCKER_IMAGE:latest-streaming --amend $DOCKER_IMAGE:latest-streaming-amd64"
2023-12-29 00:21:03 +09:00
2023-09-11 18:07:03 +09:00
}
}
}
}
stage('Docker push') {
steps {
sh "docker manifest push $DOCKER_IMAGE:$DOCKER_TAG"
2023-12-29 13:37:41 +09:00
sh "docker manifest push $DOCKER_IMAGE:$DOCKER_TAG-streaming"
2023-09-11 18:07:03 +09:00
script {
if (env.DOCKER_LATEST == 'true') {
sh "docker manifest push $DOCKER_IMAGE:latest"
2023-12-29 13:44:29 +09:00
sh "docker manifest push $DOCKER_IMAGE:latest-streaming"
2023-12-29 00:21:03 +09:00
2023-09-11 18:07:03 +09:00
}
}
}
}
}
post {
always {
sh 'docker logout "$DOCKER_REGISTRY"'
}
}
}
}
}