-
Notifications
You must be signed in to change notification settings - Fork 2
/
.drone.yml
513 lines (471 loc) · 13.6 KB
/
.drone.yml
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
---
kind: pipeline
name: default
type: kubernetes
environment:
APP_NAME: ukvi-complaints
PROD_ENV: ukvi-complaints
STG_ENV: ukvi-complaints-stg
UAT_ENV: ukvi-complaints-uat
BRANCH_ENV: ukvi-complaints-branch
PRODUCTION_URL: www.ukvi-complaints.homeoffice.gov.uk
IMAGE_URL: quay.io/ukhomeofficedigital
IMAGE_REPO: ukvi-complaints
GIT_REPO: UKHomeOffice/ukvi-complaints
HOF_CONFIG: hof-services-config/UKVI_Complaints
NON_PROD_AVAILABILITY: Mon-Fri 08:00-23:00 Europe/London
READY_FOR_TEST_DELAY: 20s
NOTIFY_STUB: stub
trigger:
branch:
- feature/*
- master
linting: &linting
pull: if-not-exists
image: node:20
environment:
NOTIFY_KEY: USE_MOCK
commands:
- yarn run test:lint
unit_tests: &unit_tests
pull: if-not-exists
image: node:20
environment:
NOTIFY_KEY: USE_MOCK
commands:
- yarn run test:unit
sonar_scanner: &sonar_scanner
pull: if-not-exists
image: quay.io/ukhomeofficedigital/sonar-scanner-nodejs:latest
commands:
- sonar-scanner -Dproject.settings=./sonar-project.properties
acceptance_tests: &acceptance_tests
pull: if-not-exists
image: mcr.microsoft.com/playwright:v1.12.3-focal
steps:
- name: clone_repos
image: alpine/git
environment:
DRONE_GIT_USERNAME:
from_secret: drone_git_username
DRONE_GIT_TOKEN:
from_secret: drone_git_token
commands:
- git clone https://$${DRONE_GIT_USERNAME}:$${DRONE_GIT_TOKEN}@github.com/UKHomeOfficeForms/hof-services-config.git
when:
branch:
include:
- master
- feature/*
event: [push, pull_request]
- name: setup_deploy
pull: if-not-exists
image: node:20
environment:
NOTIFY_KEY: USE_MOCK
commands:
- yarn install --frozen-lockfile
- yarn run postinstall
when:
branch:
include:
- master
event: [push, pull_request]
- name: linting_deploy
<<: *linting
when:
branch:
include:
- master
- feature/*
event: push
- name: unit_tests_deploy
<<: *unit_tests
when:
branch:
include:
- master
event: push
- name: sonar_scanner_deploy
<<: *sonar_scanner
when:
branch:
include:
- master
event: push
- name: build_image
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- n=0; while [ "$n" -lt 60 ] && [ ! docker stats --no-stream ]; do n=$(( n + 1 )); sleep 1; done
- docker build --no-cache -t $${IMAGE_REPO}:$${DRONE_COMMIT_SHA} .
volumes:
- name: dockersock
path: /var/run
when:
branch:
include:
- master
- feature/*
event: [push, pull_request]
- name: image_to_quay
pull: if-not-exists
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
environment:
DOCKER_PASSWORD:
from_secret: DOCKER_PASSWORD
commands:
- docker login -u="ukhomeofficedigital+sas_fbis_robot" -p=$${DOCKER_PASSWORD} quay.io
- docker tag $${IMAGE_REPO}:$${DRONE_COMMIT_SHA} $${IMAGE_URL}/$${IMAGE_REPO}:$${DRONE_COMMIT_SHA}
- docker push $${IMAGE_URL}/$${IMAGE_REPO}:$${DRONE_COMMIT_SHA}
when:
branch:
include:
- master
- feature/*
event: [push, pull_request]
# Trivy Security Scannner
- name: scan-image
pull: always
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/trivy/client:latest
resources:
limits:
cpu: 1000
memory: 1024Mi
environment:
IMAGE_NAME: ukvi-complaints:${DRONE_COMMIT_SHA}
SEVERITY: MEDIUM,HIGH,CRITICAL
FAIL_ON_DETECTION: false
IGNORE_UNFIXED: true
ALLOW_CVE_LIST_FILE: hof-services-config/UKVI_Complaints/trivy-cve-exceptions.txt
when:
event:
- pull_request
- push
- tag
# Deploy to pull request UAT environment
- name: deploy_to_branch
pull: if-not-exists
image: quay.io/ukhomeofficedigital/kd:v1.14.0
environment:
# NOTIFY_STUB: stub
KUBE_SERVER:
from_secret: kube_server_dev
KUBE_TOKEN:
from_secret: kube_token_sas_dev
commands:
- bin/deploy.sh $${BRANCH_ENV}
when:
branch: master
event: pull_request
- name: setup_branch
pull: if-not-exists
image: node:20
environment:
NOTIFY_KEY: USE_MOCK
commands:
- yarn install --frozen-lockfile
- yarn run postinstall
when:
branch:
include:
- master
- feature/*
event: pull_request
- name: linting_branch
<<: *linting
when:
branch:
include:
- master
- feature/*
event: pull_request
- name: unit_tests_branch
<<: *unit_tests
when:
branch:
include:
- master
- feature/*
event: pull_request
- name: sonar_scanner_branch
<<: *sonar_scanner
when:
branch:
include:
- master
- feature/*
event: pull_request
- name: acceptance_tests_branch
<<: *acceptance_tests
commands:
- export DRONE_SOURCE_BRANCH=$(echo $DRONE_SOURCE_BRANCH | tr '[:upper:]' '[:lower:]' | tr '/' '-')
- export ACCEPTANCE_HOST_NAME=https://ukvic-$${DRONE_SOURCE_BRANCH}.internal.$${BRANCH_ENV}.homeoffice.gov.uk
- export CUCUMBER_PUBLISH_ENABLED=true
- npx playwright install
- npm run test:acceptance
when:
branch: master
event: pull_request
# Snyk security scans which run after branch deployment to prevent blocking of PR UAT tests
- name: snyk_scan
pull: if-not-exists
image: node:20
environment:
SNYK_TOKEN:
from_secret: snyk_token
commands:
- yarn run test:snyk
when:
branch:
include:
- master
- feature/*
event: pull_request
# TEST Deploy to Master UAT environment
# - name: TEST_deploy_to_uat
# pull: if-not-exists
# image: quay.io/ukhomeofficedigital/kd:v1.14.0
# environment:
# KUBE_SERVER:
# from_secret: kube_server_dev
# KUBE_TOKEN:
# from_secret: kube_token_sas_dev
# commands:
# - bin/deploy.sh $${UAT_ENV}
# when:
# branch: master
# event: pull_request
#
# # TEST Deploy to Master STG environment
# - name: TEST_deploy_to_stg
# pull: if-not-exists
# image: quay.io/ukhomeofficedigital/kd:v1.14.0
# environment:
# KUBE_SERVER:
# from_secret: kube_server_stg
# KUBE_TOKEN:
# from_secret: kube_token_stg
# commands:
# - bin/deploy.sh $${STG_ENV}
# when:
# branch: master
# event: pull_request
# Deploy to master UAT environment
- name: deploy_to_uat
pull: if-not-exists
image: quay.io/ukhomeofficedigital/kd:v1.14.0
environment:
KUBE_SERVER:
from_secret: kube_server_dev
KUBE_TOKEN:
from_secret: kube_token_sas_dev
commands:
- bin/deploy.sh $${UAT_ENV}
when:
branch: master
event: push
- name: acceptance_tests_uat
<<: *acceptance_tests
commands:
- export ACCEPTANCE_HOST_NAME=https://$${APP_NAME}.uat.internal.sas-notprod.homeoffice.gov.uk
- npx playwright install
- npm run test:acceptance
when:
branch: master
event: push
# Get pull request branch so correct PR UAT environment is torn down in the tear_down_branch step that follows
- name: get_pr_branch
pull: if-not-exists
image: drone/cli:alpine@sha256:14409f7f7247befb9dd2effdb2f61ac40d1f5fbfb1a80566cf6f2f8d21f3be11
environment:
DRONE_SERVER:
from_secret: drone_server
DRONE_TOKEN:
from_secret: drone_token
volumes:
- name: dockersock
path: /root/.dockersock
commands:
- drone build info $GIT_REPO $DRONE_BUILD_NUMBER --format {{.Message}} | grep -o '[^ ]\+$' -m1 | sed 's|UKHomeOffice/||g' | tr '[:upper:]' '[:lower:]' | tr '/' '-' > /root/.dockersock/branch_name.txt
when:
branch: master
event: push
# Tear down pull request UAT environment
- name: tear_down_branch
pull: if-not-exists
image: quay.io/ukhomeofficedigital/kd:v1.14.0
environment:
KUBE_SERVER:
from_secret: kube_server_dev
KUBE_TOKEN:
from_secret: kube_token_sas_dev
volumes:
- name: dockersock
path: /root/.dockersock
commands:
- bin/deploy.sh tear_down
when:
branch: master
event: push
# Deploy to Staging environment
- name: deploy_to_stg
pull: if-not-exists
image: quay.io/ukhomeofficedigital/kd:v1.14.0
environment:
KUBE_SERVER:
from_secret: kube_server_stg
KUBE_TOKEN:
from_secret: kube_token_stg
commands:
- bin/deploy.sh $${STG_ENV}
when:
branch: master
event: push
# Checks a build being promoted has passed, is on master which effectively means a healthy build on Staging
- name: sanity_check_build_prod
pull: if-not-exists
image: drone/cli:alpine@sha256:14409f7f7247befb9dd2effdb2f61ac40d1f5fbfb1a80566cf6f2f8d21f3be11
environment:
DRONE_SERVER:
from_secret: drone_server
DRONE_TOKEN:
from_secret: drone_token
commands:
- bin/sanity_check_build.sh
when:
target: PROD
event: promote
- name: clone_repos_prod
image: alpine/git
environment:
DRONE_GIT_USERNAME:
from_secret: drone_git_username
DRONE_GIT_TOKEN:
from_secret: drone_git_token
commands:
- git clone https://$${DRONE_GIT_USERNAME}:$${DRONE_GIT_TOKEN}@github.com/UKHomeOfficeForms/hof-services-config.git
when:
target: PROD
event: promote
# Deploy to Production environment
- name: deploy_to_prod
pull: if-not-exists
image: quay.io/ukhomeofficedigital/kd:v1.14.0
environment:
KUBE_SERVER:
from_secret: kube_server_prod
KUBE_TOKEN:
from_secret: kube_token_prod
commands:
- bin/deploy.sh $${PROD_ENV}
when:
target: PROD
event: promote
# CRON job step that tears down our pull request UAT environments
- name: cron_tear_down
pull: if-not-exists
image: quay.io/ukhomeofficedigital/kd:v1.14.0
environment:
KUBE_SERVER:
from_secret: kube_server_dev
KUBE_TOKEN:
from_secret: kube_token_dev
commands:
- bin/clean_up.sh $${BRANCH_ENV}
when:
cron: tear_down_pr_envs
event: cron
# CRON job steps that runs security scans using Snyk & Trivy
- name: cron_clone_repos
image: alpine/git
environment:
DRONE_GIT_USERNAME:
from_secret: drone_git_username
DRONE_GIT_TOKEN:
from_secret: drone_git_token
commands:
- git clone https://$${DRONE_GIT_USERNAME}:$${DRONE_GIT_TOKEN}@github.com/UKHomeOfficeForms/hof-services-config.git
when:
cron: security_scans
event: cron
- name: cron_build_image
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
- docker build --no-cache -t $${IMAGE_REPO}:$${DRONE_COMMIT_SHA} .
volumes:
- name: dockersock
path: /var/run
when:
cron: security_scans
event: cron
- name: cron_snyk_scan
pull: if-not-exists
image: node:20
environment:
SNYK_TOKEN:
from_secret: snyk_token
commands:
- yarn install --frozen-lockfile
- yarn run postinstall
- yarn run test:snyk
when:
cron: security_scans
event: cron
- name: cron_trivy_scan
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/trivy/client:latest
pull: always
environment:
IMAGE_NAME: ukvi-complaints:${DRONE_COMMIT_SHA}
SEVERITY: MEDIUM,HIGH,CRITICAL
FAIL_ON_DETECTION: false
IGNORE_UNFIXED: true
ALLOW_CVE_LIST_FILE: hof-services-config/UKVI_Complaints/trivy-cve-exceptions.txt
when:
cron: security_scans
event: cron
# Slack notification upon a CRON job fail
- name: cron_notify_slack_tear_down_pr_envs
pull: if-not-exists
image: plugins/slack
settings:
channel: sas-build
failure: ignore
icon_url: http://readme.drone.io/0.5/logo_dark.svg
icon.url: http://readme.drone.io/0.5/logo_dark.svg
template: "CRON Job {{build.deployTo}} of UKVI Complaints has {{build.status}} - <{{build.link}}|#{{build.number}}> {{#success build.status}}\n :thumbsup: :thumbsup: :thumbsup:\n{{else}}\n :x: :x: :x:\n{{/success}} Author: {{build.author}}\n\nDuration: {{since job.started}}\n\nJob: <{{build.link}}|#{{build.number}}>\n\nCommit: {{build.commit}}\n"
username: Drone
webhook:
from_secret: slack_webhook
when:
cron: tear_down_pr_envs
event: cron
status: failure
- name: cron_notify_slack_security_scans
pull: if-not-exists
image: plugins/slack
settings:
channel: sas-build
failure: ignore
icon_url: http://readme.drone.io/0.5/logo_dark.svg
icon.url: http://readme.drone.io/0.5/logo_dark.svg
template: "CRON Job {{build.deployTo}} of UKVI Complaints has {{build.status}} - <{{build.link}}|#{{build.number}}> {{#success build.status}}\n :thumbsup: :thumbsup: :thumbsup:\n{{else}}\n :x: :x: :x:\n{{/success}} Author: {{build.author}}\n\nDuration: {{since job.started}}\n\nJob: <{{build.link}}|#{{build.number}}>\n\nCommit: {{build.commit}}\n"
username: Drone
webhook:
from_secret: slack_webhook
when:
cron: security_scans
event: cron
status: failure
services:
- name: docker
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
# Redis session setup in background so integration tests can run
- name: session
image: redis
volumes:
- name: dockersock
path: /var/run
volumes:
- name: dockersock
temp: {}
...