.gitlab-ci.yml 9.32 KB
Newer Older
1
2
# CI/CD Pipeline
# dev branch -> staging
3
# master branch -> internal (Custom Downloads)
4
5
6
# master branch -> live

# Define stages for the CI/CD pipeline
7
8
9
10
11
stages:
  - test
  - test_build_static
  - build_docker_images
  - deploy
Andrey Azov's avatar
Andrey Azov committed
12

13
variables:
14
15
  CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_SHORT_SHA}
  CONTAINER_NODE_IMAGE: ${CI_REGISTRY_IMAGE}:node-${CI_COMMIT_SHORT_SHA}
16
  KUBE_CONTEXT: ens-dev-ctx
17
  DEPLOYENV: dev
18
  ENVIRONMENT: production
19
  DOCKER_TLS_CERTDIR: ""
Andrey Azov's avatar
Andrey Azov committed
20

21
22
23
# Template to build static assets
.build-static:
  stage: test_build_static
24
  image: node:14.17.0
25
26
27

  before_script:
  - cd src/ensembl
28
  - npm install --global npm@7.12.1
29
30
31
32
33
34
35
  - npm ci

  script:
  - npm run test
  - npm run build

  artifacts:
36
    name: build_artifacts
37
38
    paths:
    - src/ensembl/dist/
39
40
    - src/ensembl/package.json
    - src/ensembl/package-lock.json
41
42
43

# Template to build nginx docker image for WP k8s cluster
# WP k8s cluster uses ingress
44
.build-nginx:
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  image: docker

  services:
    - docker:dind

  stage: build_docker_images

  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

  script:
    - apk update && apk add git
    - git clone --depth 1 https://github.com/Ensembl/ensembl-2020-static-assests.git
    - git clone https://gitlab.ebi.ac.uk/kamal/ensembl-client-nginx.git
59
    - git -C ensembl-client-nginx checkout migration/ssr
60
61
62
63
64
    - docker build -t ${CONTAINER_IMAGE} -f ensembl-client-nginx/Dockerfile --no-cache .
    - docker push ${CONTAINER_IMAGE}
    - docker rmi ${CONTAINER_IMAGE}
    - docker logout $CI_REGISTRY

65
66
67
# Template to build node docker image for WP k8s cluster
# WP k8s cluster uses ingress
.build-node:
68
69
70
71
72
73
74
75
76
77
78
  image: docker

  services:
    - docker:dind

  stage: build_docker_images

  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

  script:
79
80
81
82
    - docker build -t ${CONTAINER_NODE_IMAGE} -f src/ensembl/Dockerfile.node --no-cache .
    - docker push ${CONTAINER_NODE_IMAGE}
    - docker rmi ${CONTAINER_NODE_IMAGE}
    - docker logout $CI_REGISTRY
83

84
# Template to deploy to WP k8s cluster
85
.deploy:
86
  stage: deploy
87
  image: dockerhub.ebi.ac.uk/ensembl-web/deploy-tools:0.1
88
  script:
89
90
91
92
93
94
  - git clone https://gitlab.ebi.ac.uk/ensembl-web/ensembl-k8s-manifests.git
  - git -C ensembl-k8s-manifests/ checkout wp-k8s
  - sed -i "s#<DOCKER_IMAGE>#${CONTAINER_IMAGE}#g" ensembl-k8s-manifests/ensembl_client_nginx_deployment.yaml
  - sed -i "s#<DOCKER_IMAGE>#${CONTAINER_NODE_IMAGE}#g" ensembl-k8s-manifests/ensembl_client_node_deployment.yaml
  - kubectl apply -f ensembl-k8s-manifests/ensembl_client_nginx_deployment.yaml
  - kubectl apply -f ensembl-k8s-manifests/ensembl_client_node_deployment.yaml
95

96
# Template to deploy review-app to WP k8s cluster
97
.deploy-review:
98
  stage: deploy
99
  image: dockerhub.ebi.ac.uk/ensembl-web/deploy-tools:0.1
100
  script:
101
102
103
104
105
106
107
108
  - git clone https://gitlab.ebi.ac.uk/ensembl-web/ensembl-k8s-manifests.git
  - git -C ensembl-k8s-manifests/ checkout wp-k8s-review
  - sed -i "s#<DEPLOYMENT_ENV>#${CI_COMMIT_REF_SLUG}#g" ensembl-k8s-manifests/ensembl_client_nginx_deployment.yaml
  - sed -i "s#<DOCKER_IMAGE>#${CONTAINER_IMAGE}#g" ensembl-k8s-manifests/ensembl_client_nginx_deployment.yaml
  - sed -i "s#<DEPLOYMENT_ENV>#${CI_COMMIT_REF_SLUG}#g" ensembl-k8s-manifests/ensembl_client_node_deployment.yaml
  - sed -i "s#<DOCKER_IMAGE>#${CONTAINER_NODE_IMAGE}#g" ensembl-k8s-manifests/ensembl_client_node_deployment.yaml
  - kubectl apply -f ensembl-k8s-manifests/ensembl_client_nginx_deployment.yaml
  - kubectl apply -f ensembl-k8s-manifests/ensembl_client_node_deployment.yaml
109
110

# Template for stopping review app - Do cleanup here 
111
.stop-review:
112
  stage: deploy
113
  image: dockerhub.ebi.ac.uk/ensembl-web/deploy-tools:0.1
114
115
116
117
118
119
120
121
  variables:
    GIT_STRATEGY: none
  when: manual
  script:
  - kubectl delete ingress ensembl-client-${CI_COMMIT_REF_SLUG}-ingress
  - kubectl delete svc ensembl-client-${CI_COMMIT_REF_SLUG}-svc
  - kubectl delete deploy ensembl-client-${CI_COMMIT_REF_SLUG}-deployment

122
Test:
Andrey Azov's avatar
Andrey Azov committed
123
  image: node:14.16.0
124
  stage: test
Andrey Azov's avatar
Andrey Azov committed
125

126
127
128
129
130
  before_script:
  - cd src/ensembl
  - npm ci

  script:
131
  - npm run check-types
132
133
  - npm run test

134
135
  only:
  - /^nodeploy\/.*$/
136
137
138
139
  except:
  - dev
  - master

140
141
142
# Job to build static asset for staging and live environment
# dev branch -> Staging
# master branch -> Live
143
Test_N_Build:
144
  extends: .build-static
145

146
147
148
149
  variables:
    GOOGLE_ANALYTICS_KEY: ${GA_KEY}
    ENVIRONMENT: production
    API_HOST: ""
150
151
152
153
154

  only:
  - dev
  - master

155
# Job to build static asset for internal environment
156
# master branch -> Internal
157
Test_N_Build:internal:
158
  extends: .build-static
159

160
161
162
163
  variables:
    GOOGLE_ANALYTICS_KEY: ${GA_KEY}
    ENVIRONMENT: internal
    API_HOST: ""
164
165

  only:
166
  - master
167

168
Test_N_Build:review:
169
170
171
172
  extends: .build-static
  variables:
    ENVIRONMENT: development
    API_HOST: ""
173

174
175
176
177
  except:
  - dev
  - master
  - /^nodeploy\/.*$/
178

179
180
181
182
# Job to build nginx docker image for staging environment
# dev branch -> Staging
Nginx:Staging:
  extends: .build-nginx
183
184
  only:
  - dev
185
186
  needs:
    - Test_N_Build
187

188
# Job to build node docker image for staging environment
189
# dev branch -> Staging
190
191
Node:Staging:
  extends: .build-node
192
193
  only:
  - dev
194
195
  needs:
    - Test_N_Build
196
197
198

# Job to build nginx docker image for live environment
# master branch -> Live
199
200
Nginx:Live:
  extends: .build-nginx
201
  variables:
202
    CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_SHORT_SHA}-prod
203
204
205
206
207
208
209
210
211
212
213
  only:
  - master
  needs:
    - Test_N_Build

# Job to build node docker image for live environment
# master branch -> Live
Node:Live:
  extends: .build-node
  variables:
    CONTAINER_NODE_IMAGE: ${CI_REGISTRY_IMAGE}:node-${CI_COMMIT_SHORT_SHA}-prod
214
  only:
215
  - master
216
217
  needs:
    - Test_N_Build
218

219
# Job to build nginx docker image for internal environment at WP
220
# master branch -> internal
221
222
Nginx:Internal:
  extends: .build-nginx
223
224
  variables:
    DEPLOYENV: internal
225
    CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_SHORT_SHA}-internal
226
  only:
227
  - master
228
229
  needs:
    - Test_N_Build:internal
230

231
# Job to build node docker image for internal environment at WP
232
# master branch -> internal
233
234
Node:Internal:
  extends: .build-node
Jyothish's avatar
Jyothish committed
235
236
  variables:
    DEPLOYENV: internal
237
    CONTAINER_NODE_IMAGE: ${CI_REGISTRY_IMAGE}:node-${CI_COMMIT_SHORT_SHA}-internal
Jyothish's avatar
Jyothish committed
238
  only:
239
  - master
240
241
  needs:
    - Test_N_Build:internal
Jyothish's avatar
Jyothish committed
242

243
244
# Job to build nginx docker image for review environment at WP
# all other branch -> dev
245
Nginx:review:
246
  extends: .build-nginx
247
248
  variables:
    DEPLOYENV: dev
249
    CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_REF_SLUG}
250
251
252
253
  except:
  - dev
  - master
  - /^nodeploy\/.*$/
254

255
  needs:
256
    - Test_N_Build:review
257

258
259
260
261
# Job to build node docker image for review environment at WP
# all other branch -> dev
Node:review:
  extends: .build-node
262
  variables:
263
264
265
    DEPLOYENV: dev
    CONTAINER_NODE_IMAGE: ${CI_REGISTRY_IMAGE}:node-${CI_COMMIT_SHORT_SHA}-${CI_COMMIT_REF_SLUG}
  except:
266
  - dev
267
268
269
  - master
  - /^nodeploy\/.*$/

270
  needs:
271
    - Test_N_Build:review
272
273

# Job to deploy to staging environment (WP-HX k8s cluster)
274
275
Staging:HX:
  extends: .deploy
276
277
278
279
  environment:
    name : wp-hx-staging
  only:
  - dev
280
281
  needs:
    - Test_N_Build
282
283
    - Nginx:Staging
    - Node:Staging
284

285
286
287
# Job to deploy to staging environment (WP-HL k8s cluster)
Staging:HL:
  extends: .deploy
288
289
290
291
  environment:
    name : wp-hh-staging
  only:
  - dev
292
293
  needs:
    - Test_N_Build
294
295
    - Nginx:Staging
    - Node:Staging
296

Kamal Dodiya's avatar
Kamal Dodiya committed
297
# Job to deploy to live environment (WP-HX k8s cluster)
298
299
Live:HX:
  extends: .deploy
Kamal Dodiya's avatar
Kamal Dodiya committed
300
  variables:
301
302
    CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_SHORT_SHA}-prod
    CONTAINER_NODE_IMAGE: ${CI_REGISTRY_IMAGE}:node-${CI_COMMIT_SHORT_SHA}-prod
Kamal Dodiya's avatar
Kamal Dodiya committed
303
304
305
306
  environment:
    name : wp-hx-live
  only:
  - master
307
308
  needs:
    - Test_N_Build
309
    - Nginx:Live
310
    - Node:Live
Kamal Dodiya's avatar
Kamal Dodiya committed
311

312
313
314
# Job to deploy to live environment (WP-HL k8s cluster)
Live:HL:
  extends: .deploy
Kamal Dodiya's avatar
Kamal Dodiya committed
315
  variables:
316
317
    CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_SHORT_SHA}-prod
    CONTAINER_NODE_IMAGE: ${CI_REGISTRY_IMAGE}:node-${CI_COMMIT_SHORT_SHA}-prod
Kamal Dodiya's avatar
Kamal Dodiya committed
318
319
320
321
  environment:
    name : wp-hh-live
  only:
  - master
322
323
  needs:
    - Test_N_Build
324
    - Nginx:Live
325
    - Node:Live
326

Jyothish's avatar
Jyothish committed
327
# Job to deploy to internal environment (WP-HX k8s cluster)
328
329
Internal:HX:
  extends: .deploy
Jyothish's avatar
Jyothish committed
330
  variables:
331
332
    CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_SHORT_SHA}-internal
    CONTAINER_NODE_IMAGE: ${CI_REGISTRY_IMAGE}:node-${CI_COMMIT_SHORT_SHA}-internal
Jyothish's avatar
Jyothish committed
333
334
335
  environment:
    name : wp-hx-internal
  only:
336
  - master
337
338
  needs:
    - Test_N_Build:internal
339
    - Nginx:Internal
340
    - Node:Internal
Jyothish's avatar
Jyothish committed
341

342
343
344
# Job to deploy to internal environment (WP-HL k8s cluster)
Internal:HL:
  extends: .deploy
345
  variables:
346
347
    CONTAINER_IMAGE: ${CI_REGISTRY_IMAGE}:nginx-${CI_COMMIT_SHORT_SHA}-internal
    CONTAINER_NODE_IMAGE: ${CI_REGISTRY_IMAGE}:node-${CI_COMMIT_SHORT_SHA}-internal
348
349
350
  environment:
    name : wp-hh-internal
  only:
351
  - master
352
353
  needs:
    - Test_N_Build:internal
354
    - Nginx:Internal
355
    - Node:Internal
356

357
358
Review:HX:
  extends: .deploy-review
359
  environment:
360
361
362
363
364
365
366
367
368
    name: review/$CI_COMMIT_REF_SLUG
    url: http://$CI_COMMIT_REF_SLUG.review.ensembl.org
    on_stop: stop_review
    kubernetes:
      namespace: ensembl-dev
  except:
  - dev
  - master
  - /^nodeploy\/.*$/
369
  needs:
370
371
    - Test_N_Build:review
    - Nginx:review
372
    - Node:review
373
374

stop_review:
375
  extends: .stop-review
376
377
378
379
380
381
382
383
  environment:
    name: review/$CI_COMMIT_REF_SLUG
    action: stop
    kubernetes:
      namespace: ensembl-dev
  except:
  - dev
  - master
Andrey Azov's avatar
Andrey Azov committed
384
  - /^nodeploy\/.*$/