ecodash/jenkins/Jenkinsfile

82 lines
2.7 KiB
Plaintext
Raw Normal View History

2023-07-21 09:43:36 +02:00
pipeline {
agent any
environment {
DOCKER_REGISTRY='git.massivebox.net'
BUILDER_NAME='mbuilder'
SERVICE='ecodash/ecodash'
}
stages {
stage('Run linter and build') {
agent { docker { image 'golang' } }
steps {
2023-07-21 17:01:53 +02:00
checkout scm
sh 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin'
2023-07-21 09:43:36 +02:00
sh 'go mod tidy'
2023-07-21 17:01:53 +02:00
sh 'golangci-lint run'
2023-07-22 10:24:01 +02:00
sh 'env GOOS=linux GOARCH=amd64 go build -o ecodash_x86 src/main/main.go'
stash includes: 'ecodash_x86', name: 'ecodash_x86'
sh 'env GOOS=linux GOARCH=arm go build -o ecodash_arm src/main/main.go'
stash includes: 'ecodash_arm', name: 'ecodash_arm'
2023-07-21 17:01:53 +02:00
stash includes: 'jenkins/Dockerfile', name: 'dockerfile'
2023-07-21 09:43:36 +02:00
stash includes: 'templates/**', name: 'templates'
}
}
stage('Prepare buildx') {
steps {
sh """
docker buildx create --name $BUILDER_NAME
2023-07-21 09:43:36 +02:00
docker buildx use $BUILDER_NAME
docker buildx inspect --bootstrap
"""
}
}
2023-07-22 10:24:01 +02:00
stage('Build multi-arch container') {
2023-07-21 09:43:36 +02:00
steps {
2023-07-21 17:01:53 +02:00
unstash 'dockerfile'
2023-07-22 10:24:01 +02:00
unstash 'ecodash_x86'
unstash 'ecodash_arm'
2023-07-21 09:43:36 +02:00
unstash 'templates'
2023-07-22 12:27:56 +02:00
sh 'cp jenkins/Dockerfile ./Dockerfile; docker buildx build --platform linux/amd64,linux/arm64 --load -t ecodash .'
2023-07-22 10:24:01 +02:00
}
}
stage('Publish built files') {
steps {
2023-07-22 10:34:21 +02:00
sh 'mv ecodash_x86 ecodash; zip -r ecodash-x86.zip templates ecodash'
archiveArtifacts artifacts: "ecodash-x86.zip"
sh 'mv ecodash_arm ecodash; zip -r ecodash-arm.zip templates ecodash'
archiveArtifacts artifacts: "ecodash-arm.zip"
2023-07-21 17:01:53 +02:00
}
}
stage('Publish container on tag latest') {
when { branch 'master' }
steps {
withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
2023-07-21 18:46:31 +02:00
sh 'docker login -u $USERNAME -p $PASSWORD $DOCKER_REGISTRY'
2023-07-21 17:01:53 +02:00
}
sh """
2023-07-21 18:59:59 +02:00
docker image tag ecodash $DOCKER_REGISTRY/$SERVICE:latest
docker push $DOCKER_REGISTRY/$SERVICE:latest
2023-07-21 17:01:53 +02:00
"""
2023-07-21 09:43:36 +02:00
}
}
}
post {
always {
// cleanup
sh 'docker buildx rm $BUILDER_NAME'
2023-07-21 09:43:36 +02:00
}
}
}
2023-07-21 17:01:53 +02:00