MassiveBox
ad89006cc4
Some checks failed
ecodash/pipeline/head There was a failure building this commit
89 lines
3 KiB
Groovy
89 lines
3 KiB
Groovy
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 {
|
|
checkout scm
|
|
sh 'curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin'
|
|
sh 'go mod tidy'
|
|
sh 'golangci-lint run'
|
|
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'
|
|
stash includes: 'jenkins/Dockerfile', name: 'dockerfile'
|
|
stash includes: 'templates/**', name: 'templates'
|
|
}
|
|
}
|
|
|
|
stage('Prepare buildx') {
|
|
steps {
|
|
sh """
|
|
docker run --privileged --rm tonistiigi/binfmt --install all
|
|
|
|
docker context create $BUILDER_NAME
|
|
docker context use $BUILDER_NAME
|
|
docker buildx create $BUILDER_NAME
|
|
docker buildx use $BUILDER_NAME
|
|
docker buildx inspect --bootstrap
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('Build multi-arch container') {
|
|
steps {
|
|
unstash 'dockerfile'
|
|
unstash 'ecodash_x86'
|
|
unstash 'ecodash_arm'
|
|
unstash 'templates'
|
|
sh 'cp jenkins/Dockerfile ./Dockerfile; docker buildx build --platform linux/amd64,linux/arm64 -t ecodash .'
|
|
}
|
|
}
|
|
|
|
stage('Publish built files') {
|
|
steps {
|
|
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"
|
|
}
|
|
}
|
|
|
|
stage('Publish container on tag latest') {
|
|
when { branch 'master' }
|
|
steps {
|
|
withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
|
|
sh 'docker login -u $USERNAME -p $PASSWORD $DOCKER_REGISTRY'
|
|
}
|
|
sh """
|
|
docker image tag ecodash $DOCKER_REGISTRY/$SERVICE:latest
|
|
docker push $DOCKER_REGISTRY/$SERVICE:latest
|
|
"""
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
post {
|
|
always {
|
|
// cleanup
|
|
sh """
|
|
docker context rm -f $BUILDER_NAME
|
|
docker buildx use default
|
|
"""
|
|
}
|
|
}
|
|
|
|
}
|
|
|