2023-07-21 07:43:36 +00: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 15:01:53 +00: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 07:43:36 +00:00
|
|
|
sh 'go mod tidy'
|
2023-07-21 15:01:53 +00:00
|
|
|
sh 'golangci-lint run'
|
2023-07-21 07:43:36 +00:00
|
|
|
sh 'env GOOS=linux GOARCH=amd64 go build -o app src/main/main.go'
|
|
|
|
stash includes: 'app', name: 'ecodash-x86'
|
|
|
|
sh 'env GOOS=linux GOARCH=arm go build -o app src/main/main.go'
|
|
|
|
stash includes: 'app', name: 'ecodash-arm'
|
2023-07-21 15:01:53 +00:00
|
|
|
stash includes: 'jenkins/Dockerfile', name: 'dockerfile'
|
2023-07-21 07:43:36 +00:00
|
|
|
stash includes: 'templates/**', name: 'templates'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stage('Build x86 container') {
|
|
|
|
steps {
|
2023-07-21 15:01:53 +00:00
|
|
|
unstash 'dockerfile'
|
2023-07-21 07:43:36 +00:00
|
|
|
unstash 'ecodash-x86'
|
|
|
|
unstash 'templates'
|
2023-07-21 16:10:35 +00:00
|
|
|
sh 'cp jenkins/Dockerfile ./Dockerfile; docker build -t ecodash .'
|
2023-07-21 07:43:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 arm container') {
|
|
|
|
steps {
|
2023-07-21 15:01:53 +00:00
|
|
|
unstash 'dockerfile'
|
2023-07-21 07:43:36 +00:00
|
|
|
unstash 'ecodash-arm'
|
|
|
|
unstash 'templates'
|
2023-07-21 16:10:35 +00:00
|
|
|
sh 'cp jenkins/Dockerfile ./Dockerfile; docker buildx build --platform linux/arm64 -t ecodash .'
|
2023-07-21 15:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Publish container on tag latest') {
|
|
|
|
when { branch 'master' }
|
|
|
|
steps {
|
|
|
|
withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
|
2023-07-21 16:46:31 +00:00
|
|
|
sh 'docker login -u $USERNAME -p $PASSWORD $DOCKER_REGISTRY'
|
2023-07-21 15:01:53 +00:00
|
|
|
}
|
|
|
|
sh """
|
2023-07-21 16:59:59 +00:00
|
|
|
docker image tag ecodash $DOCKER_REGISTRY/$SERVICE:latest
|
|
|
|
docker push $DOCKER_REGISTRY/$SERVICE:latest
|
2023-07-21 15:01:53 +00:00
|
|
|
"""
|
2023-07-21 07:43:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
post {
|
|
|
|
always {
|
|
|
|
// cleanup
|
|
|
|
sh """
|
|
|
|
docker context rm -f $BUILDER_NAME
|
|
|
|
docker buildx use default
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-07-21 15:01:53 +00:00
|
|
|
|