This repository was archived by the owner on Aug 28, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathJenkinsfile
More file actions
114 lines (114 loc) · 3.34 KB
/
Copy pathJenkinsfile
File metadata and controls
114 lines (114 loc) · 3.34 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
pipeline {
agent {
kubernetes {
label 'helm-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: python
image: python:3.6.5
command:
- cat
tty: true
- 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')
CODECOV_TOKEN = credentials('cidc-taskmanager-codecov-token')
CA_CERT_PEM = credentials("ca.cert.pem")
HELM_CERT_PEM = credentials("helm.cert.pem")
HELM_KEY_PEM = credentials("helm.key.pem")
}
stages {
stage('Run unit tests') {
steps {
container('python') {
checkout scm
sh 'pip3 install -r requirements.txt'
sh 'pytest --cov-report xml:coverage.xml --cov ./'
sh 'curl -s https://codecov.io/bash | bash -s - -t ${CODECOV_TOKEN}'
}
}
}
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 (master)') {
when {
branch 'master'
}
steps {
container('docker') {
sh 'docker build -t celery-taskmanager .'
sh 'docker tag celery-taskmanager gcr.io/cidc-dfci/celery-taskmanager:production'
sh 'docker push gcr.io/cidc-dfci/celery-taskmanager:production'
}
}
}
stage('Docker build (staging)') {
when {
branch 'staging'
}
steps {
container('docker') {
sh 'docker build -t celery-taskmanager . --no-cache'
sh 'docker tag celery-taskmanager gcr.io/cidc-dfci/celery-taskmanager:staging'
sh 'docker push gcr.io/cidc-dfci/celery-taskmanager:staging'
}
}
}
stage('Helm 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 fetch cidc/celery-taskmanager --version=0.1.0-staging --untar'
sh 'helm upgrade celery-taskmanager celery-taskmanager/ -f celery-taskmanager/values_staging.yaml --set imageSHA=$(gcloud container images list-tags --format="get(digest)" --filter="tags:staging" gcr.io/cidc-dfci/celery-taskmanager) --set image.tag=staging --tls'
sh 'sleep 10'
sh 'kubectl wait pod -l app=celery-taskmanager --for=condition=Ready --timeout=180s'
}
}
}
}
}