This repository has been archived by the owner on Aug 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
102 lines (102 loc) · 2.74 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
pipeline {
agent {
kubernetes {
label 'docker'
defaultContainer 'jnlp'
serviceAccount 'helm'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: docker
image: docker:latest
command:
- cat
tty: true
volumeMounts:
- mountPath: /var/run/docker.sock
name: docker-volume
- name: gcloud
image: gcr.io/cidc-dfci/gcloud-helm:latest
command:
- cat
tty: true
volumes:
- name: docker-volume
hostPath:
path: /var/run/docker.sock
"""
}
}
environment {
GOOGLE_APPLICATION_CREDENTIALS = credentials('google-service-account')
CA_CERT_PEM = credentials("ca.cert.pem")
HELM_CERT_PEM = credentials("helm.cert.pem")
HELM_KEY_PEM = credentials("helm.key.pem")
}
stages {
stage('Checkout SCM') {
steps {
container('docker') {
checkout scm
}
}
}
stage('Docker login') {
steps {
container('docker') {
sh 'cat ${GOOGLE_APPLICATION_CREDENTIALS} | docker login -u _json_key --password-stdin https://gcr.io'
}
}
}
stage('Docker build') {
steps {
container('docker') {
sh 'docker build -t portal . --no-cache'
}
}
}
stage('Docker push (master)') {
when {
branch 'master'
}
steps {
container('docker') {
sh 'docker tag portal gcr.io/cidc-dfci/portal:production'
sh 'docker push gcr.io/cidc-dfci/portal:production'
}
}
}
stage('Docker build (staging)') {
when {
branch 'staging'
}
steps {
container('docker') {
sh 'docker tag portal gcr.io/cidc-dfci/portal:staging'
sh 'docker push gcr.io/cidc-dfci/portal:staging'
}
}
}
stage('Docker deploy (staging)') {
when {
branch 'staging'
}
steps {
container('gcloud') {
sh 'gcloud container clusters get-credentials cidc-cluster-staging --zone us-east1-c --project cidc-dfci'
sh 'helm init --client-only'
sh 'cat ${CA_CERT_PEM} > $(helm home)/ca.pem'
sh 'cat ${HELM_CERT_PEM} > $(helm home)/cert.pem'
sh 'cat ${HELM_KEY_PEM} > $(helm home)/key.pem'
sh 'helm repo add cidc "http://${CIDC_CHARTMUSEUM_SERVICE_HOST}:${CIDC_CHARTMUSEUM_SERVICE_PORT}" '
sh 'sleep 10'
sh 'helm upgrade portal cidc/portal --recreate-pods --version=0.1.0-staging --set imageSHA=$(gcloud container images list-tags --format="get(digest)" --filter="tags:staging" gcr.io/cidc-dfci/portal) --set image.tag=staging --tls'
sh 'sleep 10'
sh "kubectl wait pod -l app=portal --for=condition=Ready --timeout=180s"
}
}
}
}
}