From c55dfe3d2cfc5a9d650bf6e0650169991eb75fe9 Mon Sep 17 00:00:00 2001 From: Jenkins Date: Mon, 21 Oct 2019 09:07:41 +0000 Subject: [PATCH] Update staging file with 829376a commit --- Jenkinsfile | 46 ++++++++++++++----- .../kube/workloads/production/deployment.yaml | 24 ++++++++++ infra/kube/workloads/production/service.yaml | 4 +- infra/kube/workloads/staging/deployment.yaml | 4 +- infra/kube/workloads/staging/service.yaml | 4 +- 5 files changed, 65 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 489747271..07f4f8da4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,6 +7,18 @@ pipeline { git url: "git@github.com:azure-devops/spring-petclinic.git", credentialsId: "github_ssh_key", branch: "ignite" + + script { + env.SHA = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + env.GIT_TAG = sh(script: 'git tag -l --points-at HEAD', returnStdout: true).trim() + if (env.GIT_TAG == '') { + env.IMAGE_TAG = SHA + env.DEPLOY_TO = "staging" + } else { + env.IMAGE_TAG = env.GIT_TAG + env.DEPLOY_TO = "production" + } + } } } @@ -21,32 +33,44 @@ pipeline { stage('image build') { - environment { - sha = sh(script: 'git rev-parse --short HEAD', returnStdout: true) - } - steps { acrQuickTask azureCredentialsId: "jenkins-sp", registryName: "jenkinsdemosacr", resourceGroupName: "demo-aks", local: "", dockerfile: "Dockerfile", - imageNames: [[image: "jenkinsdemosacr.azurecr.io/pet-clinic:master-${sha}"]] + imageNames: [[image: "jenkinsdemosacr.azurecr.io/pet-clinic:pet-${IMAGE_TAG}"]] } } stage('update staging config') { - environment { - sha = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() + when { + environment name: "DEPLOY_TO", value: 'staging' } - steps { dir('infra/kube/workloads/staging') { sh ''' - sed -i -e "s/master-......./master-\${sha}/" deployment.yaml - sed -i -e "s/master-......./master-\${sha}/" service.yaml + sed -i -e "s/pet-......./pet-\${IMAGE_TAG}/" deployment.yaml + sed -i -e "s/pet-......./pet-\${IMAGE_TAG}/" service.yaml git add * - git commit -m "Update staging file with \${sha} commit" + git commit -m "Update staging file with \${IMAGE_TAG} commit" + git push origin ignite + ''' + } + } + } + + stage('update production config') { + when { + environment name: "DEPLOY_TO", value: 'production' + } + steps { + dir('infra/kube/workloads/production') { + sh ''' + sed -i -e "s/v[0-9]\\.[0-9]\\.[0-9]/\${IMAGE_TAG}/" deployment.yaml + sed -i -e "s/v[0-9]\\.[0-9]\\.[0-9]/\${IMAGE_TAG}/" service.yaml + git add * + git commit -m "Update production file with \${IMAGE_TAG} commit" git push origin ignite ''' } diff --git a/infra/kube/workloads/production/deployment.yaml b/infra/kube/workloads/production/deployment.yaml index e69de29bb..41edb5354 100644 --- a/infra/kube/workloads/production/deployment.yaml +++ b/infra/kube/workloads/production/deployment.yaml @@ -0,0 +1,24 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: pet-clinic + namespace: staging +spec: + selector: + matchLabels: + app: pet-clinic + + template: + metadata: + labels: + app: pet-clinic + version: v0.0.0 + + spec: + containers: + - name: pet-clinic + image: "jenkinsdemosacr.azurecr.io/pet-clinic:v0.0.0" + ports: + - containerPort: 8080 + imagePullSecrets: + - name: "acr-secret" diff --git a/infra/kube/workloads/production/service.yaml b/infra/kube/workloads/production/service.yaml index 2a492ebff..e4b19f7ac 100644 --- a/infra/kube/workloads/production/service.yaml +++ b/infra/kube/workloads/production/service.yaml @@ -4,11 +4,11 @@ metadata: name: pet-clinic namespace: production labels: - version: master-507549c + version: v0.0.0 spec: selector: app: auth-service - version: master-507549c + version: v0.0.0 ports: - port: 80 targetPort: 8080 diff --git a/infra/kube/workloads/staging/deployment.yaml b/infra/kube/workloads/staging/deployment.yaml index a6f0063d1..b87df6c86 100644 --- a/infra/kube/workloads/staging/deployment.yaml +++ b/infra/kube/workloads/staging/deployment.yaml @@ -12,12 +12,12 @@ spec: metadata: labels: app: pet-clinic - version: master-507549c + version: pet-829376a spec: containers: - name: pet-clinic - image: "jenkinsdemosacr.azurecr.io/pet-clinic:master-507549c" + image: "jenkinsdemosacr.azurecr.io/pet-clinic:pet-829376a" ports: - containerPort: 8080 imagePullSecrets: diff --git a/infra/kube/workloads/staging/service.yaml b/infra/kube/workloads/staging/service.yaml index 06906ab4a..9b2ee190e 100644 --- a/infra/kube/workloads/staging/service.yaml +++ b/infra/kube/workloads/staging/service.yaml @@ -4,11 +4,11 @@ metadata: name: pet-clinic namespace: staging labels: - version: master-507549c + version: pet-829376a spec: selector: app: auth-service - version: master-507549c + version: pet-829376a ports: - port: 80 targetPort: 8080