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

Commit

Permalink
Merge pull request #230 from kgudel/helmDeploy
Browse files Browse the repository at this point in the history
Update Jenkins with branch deployment
  • Loading branch information
wpears authored Feb 5, 2019
2 parents e970df8 + 4deb77b commit 61bc1eb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
49 changes: 33 additions & 16 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@ volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'),
]) {
node('buildDockerContainer') {
def repo = checkout scm
def gitCommit = repo.GIT_COMMIT
def gitBranch = repo.GIT_BRANCH
def shortGitCommit = "${gitCommit[0..10]}"
sh "env | sort"

def repo = checkout scm
def gitBranch = repo.GIT_BRANCH
def gitCommit = repo.GIT_COMMIT
def shortCommit = repo.GIT_COMMIT[0..7]
def isDeployPR = sh(returnStdout: true, script: "git log -1").contains("[deploy pr]")
def gitTagged = env.TAG_NAME != null

if (gitBranch == "master") {
env.DOCKER_TAG = "latest"
} else if (gitTagged) {
env.DOCKER_TAG = env.TAG_NAME
} else {
env.DOCKER_TAG = env.BRANCH_NAME
}

println "DOCKER_TAG: ${env.DOCKER_TAG}, TAG_NAME: ${env.TAG_NAME}, gitbranch: ${gitBranch}, shortCommit: ${shortCommit}, isDeployPR: ${isDeployPR}"


stage('Build And Publish Docker Image') {
container('docker') {
Expand All @@ -19,16 +34,16 @@ volumes: [
usernameVariable: 'DTR_USER', passwordVariable: 'DTR_PASSWORD']]) {
withCredentials([string(credentialsId: 'internal-docker-registry', variable: 'DOCKER_REGISTRY_URL')]){
sh "docker build --rm -t=${env.DOCKER_HUB_USER}/hmda-pub-ui ."
if (env.TAG_NAME != null || gitBranch == "master") {
if (gitBranch == "master") {
env.DOCKER_TAG = "latest"
} else {
env.DOCKER_TAG = env.TAG_NAME
}
if (gitTagged || gitBranch == "master" || isDeployPR) {
//Push to Dockerhub
sh """
docker tag ${env.DOCKER_HUB_USER}/hmda-pub-ui ${env.DOCKER_HUB_USER}/hmda-pub-ui:${env.DOCKER_TAG}
docker login -u ${env.DOCKER_HUB_USER} -p ${env.DOCKER_HUB_PASSWORD}
docker push ${env.DOCKER_HUB_USER}/hmda-pub-ui:${env.DOCKER_TAG}
"""

//Push to Internal Docker Repo
sh """
docker tag ${env.DOCKER_HUB_USER}/hmda-pub-ui:${env.DOCKER_TAG} ${DOCKER_REGISTRY_URL}/${env.DOCKER_HUB_USER}/hmda-pub-ui:${env.DOCKER_TAG}
docker login ${DOCKER_REGISTRY_URL} -u ${env.DTR_USER} -p ${env.DTR_PASSWORD}
docker push ${DOCKER_REGISTRY_URL}/${env.DOCKER_HUB_USER}/hmda-pub-ui:${env.DOCKER_TAG}
Expand All @@ -42,14 +57,16 @@ volumes: [
}

stage('Deploy') {
if (env.BRANCH_NAME == 'master') {
if (env.BRANCH_NAME == 'master' || isDeployPR) {
container('helm') {
sh "helm upgrade --install --force \
--namespace=default \
--values=kubernetes/hmda-pub-ui/values.yaml \
--set image.tag=latest \
hmda-pub-ui \
kubernetes/hmda-pub-ui"
--namespace=default \
--values=kubernetes/hmda-pub-ui/values.yaml \
--set commitId=$shortCommit \
--set image.pullPolicy=Always \
--set image.tag=${env.DOCKER_TAG} \
hmda-pub-ui \
kubernetes/hmda-pub-ui"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions kubernetes/hmda-pub-ui/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
env:
- name: GIT_COMMIT
value: {{ .Values.commitId }}
volumeMounts:
- name: tz-config
mountPath: /etc/localtime
Expand Down
1 change: 1 addition & 0 deletions kubernetes/hmda-pub-ui/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Declare variables to be passed into your templates.

replicaCount: 1
commitId: ''

image:
repository: hmda/hmda-pub-ui
Expand Down

0 comments on commit 61bc1eb

Please sign in to comment.