Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
feat: build Docker images (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuisathaverat authored Jun 30, 2020
1 parent 62b612b commit f1eedce
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,38 @@ pipeline {
}
}
}
/**
Publish Docker images.
*/
stage('Publish Docker image'){
when {
not { changeRequest() }
}
environment {
DOCKER_IMG_TAG = "${env.DOCKER_IMG}:${env.GIT_BASE_COMMIT}"
DOCKER_IMG_TAG_BRANCH = "${env.DOCKER_IMG}:${env.BRANCH_NAME}"
}
steps {
cleanup()
pushDockerImage()
}
}
/**
Publish PR Docker images.
*/
stage('Publish PR Docker image'){
when {
changeRequest()
}
environment {
DOCKER_IMG_TAG = "${env.DOCKER_IMG_PR}:${env.GIT_BASE_COMMIT}"
DOCKER_IMG_TAG_BRANCH = "${env.DOCKER_IMG_PR}:${env.BRANCH_NAME}"
}
steps {
cleanup()
pushDockerImage()
}
}
}
post {
cleanup {
Expand All @@ -104,3 +136,28 @@ def cleanup(){
}
unstash 'source'
}


def pushDockerImage(){
dir("${BASE_DIR}"){
dockerLogin(secret: "${env.DOCKER_REGISTRY_SECRET}",
registry: "${env.DOCKER_REGISTRY}")
sh(label: 'Build Docker image',
script: """docker build \
-t ${env.DOCKER_IMG_TAG} \
--label BRANCH_NAME=${env.BRANCH_NAME} \
--label GIT_SHA=${env.GIT_BASE_COMMIT} \
--label GO_VERSION=${env.GO_VERSION} \
--label TIMESTAMP=\$(date +%Y-%m-%d_%H:%M) \
.
""")
retryWithSleep(retries: 3, seconds: 5, backoff: true){
sh(label: 'Push Docker image sha',
script: "docker push ${env.DOCKER_IMG_TAG}")
sh(label: 'Re-tag Docker image',
script: "docker tag ${env.DOCKER_IMG_TAG} ${env.DOCKER_IMG_TAG_BRANCH}")
sh(label: 'Push Docker image name',
script: "docker push ${env.DOCKER_IMG_TAG_BRANCH}")
}
}
}

0 comments on commit f1eedce

Please sign in to comment.