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-22 08:24:01 +00: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 15:01:53 +00:00
|
|
|
stash includes: 'jenkins/Dockerfile', name: 'dockerfile'
|
2023-07-21 07:43:36 +00:00
|
|
|
stash includes: 'templates/**', name: 'templates'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-22 13:37:59 +00:00
|
|
|
stage('Prepare container build') {
|
2023-07-21 07:43:36 +00:00
|
|
|
steps {
|
|
|
|
sh """
|
2023-07-22 09:14:54 +00:00
|
|
|
docker buildx create --name $BUILDER_NAME
|
2023-07-21 07:43:36 +00:00
|
|
|
docker buildx use $BUILDER_NAME
|
|
|
|
docker buildx inspect --bootstrap
|
2023-07-22 13:37:59 +00:00
|
|
|
cp jenkins/Dockerfile ./Dockerfile
|
2023-07-21 07:43:36 +00:00
|
|
|
"""
|
2023-07-22 13:37:59 +00:00
|
|
|
withCredentials([usernamePassword(credentialsId: 'gitea-credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
|
|
|
|
sh 'docker login -u $USERNAME -p $PASSWORD $DOCKER_REGISTRY'
|
|
|
|
}
|
2023-07-21 15:01:53 +00:00
|
|
|
unstash 'dockerfile'
|
2023-07-22 08:24:01 +00:00
|
|
|
unstash 'ecodash_x86'
|
|
|
|
unstash 'ecodash_arm'
|
2023-07-21 07:43:36 +00:00
|
|
|
unstash 'templates'
|
2023-07-22 13:37:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Build and push container on push to master') {
|
|
|
|
when {
|
|
|
|
anyOf {
|
|
|
|
branch 'master'
|
|
|
|
buildingTag()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
steps {
|
|
|
|
sh 'docker buildx build --platform linux/amd64,linux/arm64 --push -t $DOCKER_REGISTRY/$SERVICE:latest .'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stage('Build and push container on tag') {
|
|
|
|
when { buildingTag() }
|
|
|
|
steps {
|
2023-07-22 13:40:00 +00:00
|
|
|
script {
|
|
|
|
def formattedTag = env.TAG_NAME.replaceFirst(/^v/, '')
|
|
|
|
sh 'docker buildx build --platform linux/amd64,linux/arm64 --push -t $DOCKER_REGISTRY/$SERVICE:$formattedTag .'
|
|
|
|
}
|
2023-07-22 08:24:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-29 17:32:35 +00:00
|
|
|
stage('Publish build artifacts on tag') {
|
|
|
|
when { buildingTag() }
|
2023-07-22 08:24:01 +00:00
|
|
|
steps {
|
2023-07-22 08:34:21 +00: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 15:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-21 07:43:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
post {
|
|
|
|
always {
|
|
|
|
// cleanup
|
2023-07-22 09:14:54 +00:00
|
|
|
sh 'docker buildx rm $BUILDER_NAME'
|
2023-07-21 07:43:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-07-21 15:01:53 +00:00
|
|
|
|