forked from evandbrown/gceme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
49 lines (44 loc) · 2.33 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
node('docker') {
checkout scm
// Kubernetes cluster info
def cluster = 'bmenasha-cluster'
def zone = 'us-central1-c'
def project = 'google-platform-demo'
// Run tests
stage 'Go tests'
docker.image('golang:1.5.1').inside {
sh('go get -d -v')
sh('go test')
}
// Build image with Go binary
stage 'Build Docker image'
def img = docker.build("gcr.io/${project}/gceme:${env.BUILD_TAG}")
sh('gcloud docker -a')
img.push()
// Deploy image to cluster in dev namespace
stage 'Deploy to QA cluster'
docker.image('buildpack-deps:jessie-scm').inside {
sh('apt-get update -y ; apt-get install jq')
sh('export CLOUDSDK_CORE_DISABLE_PROMPTS=1 ; curl https://sdk.cloud.google.com | bash')
sh("/root/google-cloud-sdk/bin/gcloud container clusters get-credentials ${cluster} --zone ${zone}")
sh('curl -o /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.0.1/bin/linux/amd64/kubectl ; chmod +x /usr/bin/kubectl')
sh("kubectl --namespace=staging rollingupdate gceme-frontend --image=${img.id} --update-period=5s")
sh("kubectl --namespace=staging rollingupdate gceme-backend --image=${img.id} --update-period=5s")
sh("echo http://`kubectl --namespace=staging get service/gceme-frontend --output=json | jq -r '.status.loadBalancer.ingress[0].ip'` > staging")
}
// Deploy to prod if approved
stage 'Approve, deploy to prod'
def url = readFile('staging').trim()
input message: "Does staging at $url look good? ", ok: "Deploy to production"
sh('gcloud docker -a')
img.push('latest')
docker.image('buildpack-deps:jessie-scm').inside {
sh('apt-get update -y ; apt-get install jq')
sh('export CLOUDSDK_CORE_DISABLE_PROMPTS=1 ; curl https://sdk.cloud.google.com | bash')
sh("/root/google-cloud-sdk/bin/gcloud container clusters get-credentials ${cluster} --zone ${zone}")
sh('curl -o /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.0.1/bin/linux/amd64/kubectl ; chmod +x /usr/bin/kubectl')
sh("kubectl --namespace=production rollingupdate gceme-frontend --image=${img.id} --update-period=5s")
sh("kubectl --namespace=production rollingupdate gceme-backend --image=${img.id} --update-period=5s")
sh("echo http://`kubectl --namespace=production get service/gceme-frontend --output=json | jq -r '.status.loadBalancer.ingress[0].ip'`")
}
}