From 867ce6812a55b2ecd1ddf831fd2588a464977386 Mon Sep 17 00:00:00 2001 From: Shahzeb khan <08bitshahzebk@seecs.edu.pk> Date: Thu, 31 Aug 2017 18:44:54 +0200 Subject: [PATCH 1/9] Update Jenkinsfile --- Jenkinsfile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d8f390c5..2ec64caa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,13 +2,6 @@ pipeline { - agent { - docker { - image 'node' - args '-u root' - } - } - stages { stage('Build') { steps { From e59826995df6f77f9bdabae5d0dd63fbe43a067f Mon Sep 17 00:00:00 2001 From: Shahzeb khan <08bitshahzebk@seecs.edu.pk> Date: Thu, 31 Aug 2017 19:29:31 +0200 Subject: [PATCH 2/9] Update Jenkinsfile --- Jenkinsfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 2ec64caa..d8f390c5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,6 +2,13 @@ pipeline { + agent { + docker { + image 'node' + args '-u root' + } + } + stages { stage('Build') { steps { From 6ae0b72c78792608417c2d11dfada90b6444833a Mon Sep 17 00:00:00 2001 From: Shahzeb khan <08bitshahzebk@seecs.edu.pk> Date: Thu, 31 Aug 2017 19:51:04 +0200 Subject: [PATCH 3/9] Update app.js --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index d470d3bf..d7078222 100644 --- a/app.js +++ b/app.js @@ -15,7 +15,7 @@ Server.route({ } }); -// don't start server if this file was required +// don't start server if this file was required YESSSSS if (!module.parent) { From 7a158fec195910d2db74c045bd4116902e5115ef Mon Sep 17 00:00:00 2001 From: Shahzeb khan <08bitshahzebk@seecs.edu.pk> Date: Thu, 31 Aug 2017 19:56:58 +0200 Subject: [PATCH 4/9] Update Jenkinsfile --- Jenkinsfile | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d8f390c5..2ec64caa 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,13 +2,6 @@ pipeline { - agent { - docker { - image 'node' - args '-u root' - } - } - stages { stage('Build') { steps { From 2dca28c8071cdd2ef19ad80ae2fda55b8b5cdaa9 Mon Sep 17 00:00:00 2001 From: Shahzeb khan <08bitshahzebk@seecs.edu.pk> Date: Thu, 31 Aug 2017 19:57:40 +0200 Subject: [PATCH 5/9] Update Jenkinsfile --- Jenkinsfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2ec64caa..0fb8d7f9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,12 @@ #!/usr/bin/env groovy pipeline { - + agent { + docker { + image 'node' + args '-u root' + } + } stages { stage('Build') { steps { From 4511cc5ae622be70c635a5776a9bd28c37521469 Mon Sep 17 00:00:00 2001 From: Shahzeb khan <08bitshahzebk@seecs.edu.pk> Date: Thu, 31 Aug 2017 20:05:27 +0200 Subject: [PATCH 6/9] Update Jenkinsfile --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0fb8d7f9..d5467c4c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,6 @@ pipeline { agent { docker { image 'node' - args '-u root' } } stages { From 3cb49cf6803288ef40d82e203ac60f4653d7dfbd Mon Sep 17 00:00:00 2001 From: Shahzeb khan <08bitshahzebk@seecs.edu.pk> Date: Thu, 31 Aug 2017 20:06:21 +0200 Subject: [PATCH 7/9] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index d5467c4c..fcabcb39 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { stages { stage('Build') { steps { - echo 'Building...' + echo 'Building NPM...' sh 'npm install' } } From 096a1c102084ca9b339ccf3cf33bea50b1a4474b Mon Sep 17 00:00:00 2001 From: Shahzeb khan <08bitshahzebk@seecs.edu.pk> Date: Thu, 31 Aug 2017 20:07:30 +0200 Subject: [PATCH 8/9] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index fcabcb39..14b4caa6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { stages { stage('Build') { steps { - echo 'Building NPM...' + echo 'Building NPM yessss...' sh 'npm install' } } From 67c6f0c75d5ba3d8ce232e04bffd51619136363a Mon Sep 17 00:00:00 2001 From: Shahzeb khan <08bitshahzebk@seecs.edu.pk> Date: Thu, 31 Aug 2017 20:51:59 +0200 Subject: [PATCH 9/9] Update Jenkinsfile --- Jenkinsfile | 69 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 14b4caa6..156f2c86 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,23 +1,50 @@ -#!/usr/bin/env groovy +node { + def project = 'REPLACE_WITH_YOUR_PROJECT_ID' + def appName = 'gceme' + def feSvcName = "${appName}-frontend" + def imageTag = "gcr.io/${project}/${appName}:${env.BRANCH_NAME}.${env.BUILD_NUMBER}" -pipeline { - agent { - docker { - image 'node' - } - } - stages { - stage('Build') { - steps { - echo 'Building NPM yessss...' - sh 'npm install' - } - } - stage('Test') { - steps { - echo 'Testing...' - sh 'npm test' - } - } - } + checkout scm + + stage 'Build image' + sh("docker build -t ${imageTag} .") + + stage 'Run Go tests' + sh("docker run ${imageTag} go test") + + stage 'Push image to registry' + sh("gcloud docker -- push ${imageTag}") + + stage "Deploy Application" + switch (env.BRANCH_NAME) { + // Roll out to canary environment + case "canary": + // Change deployed image in canary to the one we just built + sh("sed -i.bak 's#gcr.io/cloud-solutions-images/gceme:1.0.0#${imageTag}#' ./k8s/canary/*.yaml") + sh("kubectl --namespace=production apply -f k8s/services/") + sh("kubectl --namespace=production apply -f k8s/canary/") + sh("echo http://`kubectl --namespace=production get service/${feSvcName} --output=json | jq -r '.status.loadBalancer.ingress[0].ip'` > ${feSvcName}") + break + + // Roll out to production + case "master": + // Change deployed image in canary to the one we just built + sh("sed -i.bak 's#gcr.io/cloud-solutions-images/gceme:1.0.0#${imageTag}#' ./k8s/production/*.yaml") + sh("kubectl --namespace=production apply -f k8s/services/") + sh("kubectl --namespace=production apply -f k8s/production/") + sh("echo http://`kubectl --namespace=production get service/${feSvcName} --output=json | jq -r '.status.loadBalancer.ingress[0].ip'` > ${feSvcName}") + break + + // Roll out a dev environment + default: + // Create namespace if it doesn't exist + sh("kubectl get ns ${env.BRANCH_NAME} || kubectl create ns ${env.BRANCH_NAME}") + // Don't use public load balancing for development branches + sh("sed -i.bak 's#LoadBalancer#ClusterIP#' ./k8s/services/frontend.yaml") + sh("sed -i.bak 's#gcr.io/cloud-solutions-images/gceme:1.0.0#${imageTag}#' ./k8s/dev/*.yaml") + sh("kubectl --namespace=${env.BRANCH_NAME} apply -f k8s/services/") + sh("kubectl --namespace=${env.BRANCH_NAME} apply -f k8s/dev/") + echo 'To access your environment run `kubectl proxy`' + echo "Then access your service via http://localhost:8001/api/v1/proxy/namespaces/${env.BRANCH_NAME}/services/${feSvcName}:80/" + } }