forked from overture-stack/arranger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
269 lines (261 loc) · 13 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
def gitHubRepo = "overture-stack/arranger"
def gitHubRegistry = "ghcr.io"
def dockerHubRepo = "overture/arranger"
def commit = "UNKNOWN"
pipeline {
agent {
kubernetes {
label 'arranger-executor'
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: node
image: node:12.6.0
tty: true
env:
- name: HOME
value: /home/jenkins/agent
- name: docker
image: docker:18-git
tty: true
env:
- name: DOCKER_HOST
value: tcp://localhost:2375
- name: HOME
value: /home/jenkins/agent
- name: dind-daemon
image: docker:18.06-dind
securityContext:
privileged: true
runAsUser: 0
volumeMounts:
- name: docker-graph-storage
mountPath: /var/lib/docker
securityContext:
runAsUser: 1000
volumes:
- name: docker-graph-storage
emptyDir: {}
"""
}
}
stages {
stage('Diagnostics') {
steps {
container('docker') {
sh "printenv; id; cat /etc/passwd"
}
container('node') {
sh "printenv; id; cat /etc/passwd"
}
}
}
stage('Prepare') {
steps {
script {
commit = sh(returnStdout: true, script: 'git describe --always').trim()
}
script {
version = sh(returnStdout: true, script: 'cat ./lerna.json | grep \\"version\\" | cut -d \':\' -f2 | sed -e \'s/"//\' -e \'s/",//\'').trim()
}
}
}
stage("Build test container") {
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId:'OvertureDockerHub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'docker login -u $USERNAME -p $PASSWORD'
}
sh "docker build --network=host --target test -f Dockerfile -t ${dockerHubRepo}-test:${commit} ."
}
}
}
stage('Run tests') {
steps {
container('docker') {
sh "docker run ${dockerHubRepo}-test:${commit}"
}
}
}
stage("Build server and ui images") {
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId:'OvertureDockerHub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'docker login -u $USERNAME -p $PASSWORD'
}
sh "docker build --network=host --target server -f Dockerfile -t ${dockerHubRepo}-server:${commit} ."
sh "docker build --network=host --target ui -f Dockerfile -t ${dockerHubRepo}-ui:${commit} ."
}
container('docker') {
withCredentials([usernamePassword(credentialsId:'OvertureBioGithub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "docker login ${gitHubRegistry} -u $USERNAME -p $PASSWORD"
}
sh "docker build --network=host --target server -f Dockerfile -t ${gitHubRegistry}/${gitHubRepo}-server:${commit} ."
sh "docker build --network=host --target ui -f Dockerfile -t ${gitHubRegistry}/${gitHubRepo}-ui:${commit} ."
}
}
}
stage('Push edge images') {
when {
branch "develop"
}
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId:'OvertureDockerHub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "docker login -u $USERNAME -p $PASSWORD"
}
sh "docker push ${dockerHubRepo}-server:${commit}"
sh "docker push ${dockerHubRepo}-ui:${commit}"
sh "docker tag ${dockerHubRepo}-server:${commit} ${dockerHubRepo}-server:edge"
sh "docker push ${dockerHubRepo}-server:edge"
sh "docker tag ${dockerHubRepo}-server:${commit} ${dockerHubRepo}-server:${version}-${commit}"
sh "docker push ${dockerHubRepo}-server:${version}-${commit}"
sh "docker tag ${dockerHubRepo}-ui:${commit} ${dockerHubRepo}-ui:edge"
sh "docker push ${dockerHubRepo}-ui:edge"
sh "docker tag ${dockerHubRepo}-ui:${commit} ${dockerHubRepo}-ui:${version}-${commit}"
sh "docker push ${dockerHubRepo}-ui:${version}-${commit}"
}
container('docker') {
withCredentials([usernamePassword(credentialsId:'OvertureBioGithub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "docker login ${gitHubRegistry} -u $USERNAME -p $PASSWORD"
}
sh "docker push ${gitHubRegistry}/${gitHubRepo}-server:${commit}"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-ui:${commit}"
sh "docker tag ${gitHubRegistry}/${gitHubRepo}-server:${commit} ${gitHubRegistry}/${gitHubRepo}-server:edge"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-server:edge"
sh "docker tag ${gitHubRegistry}/${gitHubRepo}-server:${commit} ${gitHubRegistry}/${gitHubRepo}-server:${version}-${commit}"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-server:${version}-${commit}"
sh "docker tag ${gitHubRegistry}/${gitHubRepo}-ui:${commit} ${gitHubRegistry}/${gitHubRepo}-ui:edge"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-ui:edge"
sh "docker tag ${gitHubRegistry}/${gitHubRepo}-ui:${commit} ${gitHubRegistry}/${gitHubRepo}-ui:${version}-${commit}"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-ui:${version}-${commit}"
}
}
}
stage('Push latest images') {
when {
branch "master"
}
steps {
container('docker') {
withCredentials([usernamePassword(credentialsId:'OvertureDockerHub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "docker login -u $USERNAME -p $PASSWORD"
}
sh "docker push ${dockerHubRepo}-server:${commit}"
sh "docker push ${dockerHubRepo}-ui:${commit}"
sh "docker tag ${dockerHubRepo}-server:${commit} ${dockerHubRepo}-server:latest"
sh "docker push ${dockerHubRepo}-server:latest"
sh "docker tag ${dockerHubRepo}-server:${commit} ${dockerHubRepo}-server:${version}"
sh "docker push ${dockerHubRepo}-server:${version}"
sh "docker tag ${dockerHubRepo}-server:${commit} ${dockerHubRepo}-server:${version}-${commit}"
sh "docker push ${dockerHubRepo}-server:${version}-${commit}"
sh "docker tag ${dockerHubRepo}-ui:${commit} ${dockerHubRepo}-ui:latest"
sh "docker push ${dockerHubRepo}-ui:latest"
sh "docker tag ${dockerHubRepo}-ui:${commit} ${dockerHubRepo}-ui:${version}"
sh "docker push ${dockerHubRepo}-ui:${version}"
sh "docker tag ${dockerHubRepo}-ui:${commit} ${dockerHubRepo}-ui:${version}-${commit}"
sh "docker push ${dockerHubRepo}-ui:${version}-${commit}"
}
container('docker') {
withCredentials([usernamePassword(credentialsId:'OvertureBioGithub', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "docker login ${gitHubRegistry} -u $USERNAME -p $PASSWORD"
}
sh "docker push ${gitHubRegistry}/${gitHubRepo}-server:${commit}"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-ui:${commit}"
sh "docker tag ${gitHubRegistry}/${gitHubRepo}-server:${commit} ${gitHubRegistry}/${gitHubRepo}-server:latest"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-server:latest"
sh "docker tag ${gitHubRegistry}/${gitHubRepo}-server:${commit} ${gitHubRegistry}/${gitHubRepo}-server:${version}"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-server:${version}"
sh "docker tag ${gitHubRegistry}/${gitHubRepo}-server:${commit} ${gitHubRegistry}/${gitHubRepo}-server:${version}-${commit}"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-server:${version}-${commit}"
sh "docker tag ${gitHubRegistry}/${gitHubRepo}-ui:${commit} ${gitHubRegistry}/${gitHubRepo}-ui:latest"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-ui:latest"
sh "docker tag ${gitHubRegistry}/${gitHubRepo}-ui:${commit} ${gitHubRegistry}/${gitHubRepo}-ui:${version}"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-ui:${version}"
sh "docker tag ${gitHubRegistry}/${gitHubRepo}-ui:${commit} ${gitHubRegistry}/${gitHubRepo}-ui:${version}-${commit}"
sh "docker push ${gitHubRegistry}/${gitHubRepo}-ui:${version}-${commit}"
}
}
}
stage('Publish tag to npm') {
when {
branch "master"
}
steps {
container('node') {
withCredentials([
usernamePassword(credentialsId: 'OvertureBioNPM', passwordVariable: 'NPM_PASSWORD', usernameVariable: 'NPM_USERNAME'),
string(credentialsId: 'OvertureBioContact', variable: 'EMAIL'),
usernamePassword(credentialsId: 'OvertureBioGithub', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')
]) {
sh "git pull --tags"
sh "npm ci"
sh "npm config set unsafe-perm true"
sh "npm run bootstrap"
sh "NPM_EMAIL=${EMAIL} NPM_USERNAME=${NPM_USERNAME} NPM_PASSWORD=${NPM_PASSWORD} npx npm-ci-login"
sh "npm run publish::ci"
}
}
}
}
stage('Deploy to Overture QA') {
when {
branch "develop"
}
steps {
build(job: "/Overture.bio/provision/helm", parameters: [
[$class: 'StringParameterValue', name: 'OVERTURE_ENV', value: 'qa' ],
[$class: 'StringParameterValue', name: 'OVERTURE_CHART_NAME', value: 'arranger'],
[$class: 'StringParameterValue', name: 'OVERTURE_RELEASE_NAME', value: 'arranger'],
[$class: 'StringParameterValue', name: 'OVERTURE_HELM_CHART_VERSION', value: ''], // use latest
[$class: 'StringParameterValue', name: 'OVERTURE_HELM_REPO_URL', value: "https://overture-stack.github.io/charts-server/"],
[$class: 'StringParameterValue', name: 'OVERTURE_HELM_REUSE_VALUES', value: "false" ],
[$class: 'StringParameterValue', name: 'OVERTURE_ARGS_LINE', value: "--set-string apiImage.tag=${version}-${commit} --set-string uiImage.tag=${version}-${commit}" ]
])
}
}
stage('Deploy to Overture Staging') {
when {
branch "master"
}
steps {
build(job: "/Overture.bio/provision/helm", parameters: [
[$class: 'StringParameterValue', name: 'OVERTURE_ENV', value: 'staging' ],
[$class: 'StringParameterValue', name: 'OVERTURE_CHART_NAME', value: 'arranger'],
[$class: 'StringParameterValue', name: 'OVERTURE_RELEASE_NAME', value: 'arranger'],
[$class: 'StringParameterValue', name: 'OVERTURE_HELM_CHART_VERSION', value: ''], // use latest
[$class: 'StringParameterValue', name: 'OVERTURE_HELM_REPO_URL', value: "https://overture-stack.github.io/charts-server/"],
[$class: 'StringParameterValue', name: 'OVERTURE_HELM_REUSE_VALUES', value: "false" ],
[$class: 'StringParameterValue', name: 'OVERTURE_ARGS_LINE', value: "--set-string apiImage.tag=${version}-${commit} --set-string uiImage.tag=${version}-${commit}" ]
])
}
}
}
post {
unsuccessful {
// i used node container since it has curl already
container("node") {
script {
if (env.BRANCH_NAME == "master" || env.BRANCH_NAME == "develop") {
withCredentials([string(credentialsId: 'JenkinsFailuresSlackChannelURL', variable: 'JenkinsFailuresSlackChannelURL')]) {
sh "curl -X POST -H 'Content-type: application/json' --data '{\"text\":\"Build Failed: ${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL}) \"}' ${JenkinsFailuresSlackChannelURL}"
}
}
}
}
}
fixed {
container("node") {
script {
if (env.BRANCH_NAME == "master" || env.BRANCH_NAME == "develop") {
withCredentials([string(credentialsId: 'JenkinsFailuresSlackChannelURL', variable: 'JenkinsFailuresSlackChannelURL')]) {
sh "curl -X POST -H 'Content-type: application/json' --data '{\"text\":\"Build Fixed: ${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL}) \"}' ${JenkinsFailuresSlackChannelURL}"
}
}
}
}
}
}
}