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

feat: Build docker image #96

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")
}
}
}