-
Notifications
You must be signed in to change notification settings - Fork 0
/
.drone.yml
505 lines (463 loc) · 14.4 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
---
kind: pipeline
name: default
type: kubernetes
environment:
APP_NAME: csl
PROD_ENV: sas-csl-prod
STG_ENV: sas-csl-stg
UAT_ENV: sas-csl-uat
BRANCH_ENV: sas-csl-branch
PRODUCTION_URL: TBC
IMAGE_URL: 340268328991.dkr.ecr.eu-west-2.amazonaws.com
IMAGE_REPO: sas/csl
GIT_REPO: UKHomeOffice/controlled-substance-licence
HOF_CONFIG: hof-services-config/Controlled_Substance_License
NON_PROD_AVAILABILITY: Mon-Fri 08:00-23:00 Europe/London
READY_FOR_TEST_DELAY: 20s
NOTIFY_STUB: stub
include_default_branch: &include_default_branch
include:
- main
include_default_and_feature_branches: &include_default_and_feature_branches
include:
- main
- feature/*
trigger:
branch:
<<: *include_default_and_feature_branches
node_image: &node_image
pull: if-not-exists
image: node:20.18.0-alpine3.20@sha256:d504f23acdda979406cf3bdbff0dff7933e5c4ec183dda404ed24286c6125e60
linting: &linting
<<: *node_image
commands:
- yarn run test:lint
unit_tests: &unit_tests
<<: *node_image
environment:
NOTIFY_STUB: true
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
ui_integration_tests: &ui_integration_tests
<<: *node_image
environment:
NOTIFY_STUB: true
commands:
- yarn run test:ui-integration
accessibility_tests: &accessibility_tests
pull: if-not-exists
image: buildkite/puppeteer:8.0.0@sha256:b6cebc17bfa8e7a7abfc3ab14d6f2ddbdf42b9e81b8ad786c6693385665998d5
environment:
NOTIFY_STUB: true
ENVIRONMENT: DRONE
volumes:
- name: dockersock
path: /root/.dockersock
commands:
- yarn run test:accessibility
acceptance_tests: &acceptance_tests
pull: if-not-exists
image: mcr.microsoft.com/playwright:v1.12.3-focal
steps:
- name: clone_repos
pull: if-not-exists
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
- find hof-services-config/* | grep -v $HOF_CONFIG | grep -v 'infrastructure' | xargs rm -rf
when:
branch:
<<: *include_default_and_feature_branches
event: [push, pull_request]
# Trivy Security Scannner for scanning OS related vulnerabilities in Base image of Dockerfile
- name: scan_base_image_os
pull: always
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/trivy/client:latest
resources:
limits:
cpu: 1000
memory: 1024Mi
environment:
IMAGE_NAME: node:20.18.0-alpine3.20@sha256:d504f23acdda979406cf3bdbff0dff7933e5c4ec183dda404ed24286c6125e60
SERVICE_URL: https://acp-trivy-helm.acp-trivy.svc.cluster.local:443
SEVERITY: MEDIUM,HIGH,CRITICAL --dependency-tree
FAIL_ON_DETECTION: false
IGNORE_UNFIXED: false
ALLOW_CVE_LIST_FILE: hof-services-config/infrastructure/trivy/.trivyignore.yaml
volumes:
- name: dockersock
path: /root/.dockersock
when:
event: [push, pull_request]
depends_on:
- clone_repos
- name: setup
<<: *node_image
environment:
NOTIFY_STUB: true
commands:
- yarn install --frozen-lockfile
- yarn run postinstall
when:
branch:
<<: *include_default_and_feature_branches
event: [push, pull_request]
- name: linting
<<: *linting
when:
branch:
<<: *include_default_and_feature_branches
event: [push, pull_request]
depends_on:
- setup
- name: unit_tests
<<: *unit_tests
when:
branch:
<<: *include_default_and_feature_branches
event: [push, pull_request]
depends_on:
- setup
- name: sonar_scanner
<<: *sonar_scanner
when:
branch:
<<: *include_default_and_feature_branches
event: [push, pull_request]
- name: build_image
pull: if-not-exists
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
# wait for docker service to be up before running docker build
- /usr/local/bin/wait
- 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_default_and_feature_branches
event: [push, pull_request]
depends_on:
- linting
- unit_tests
- name: image_to_ecr
pull: if-not-exists
image: plugins/ecr
settings:
access_key:
from_secret: aws_access_key_id
secret_key:
from_secret: aws_secret_access_key
region: eu-west-2
repo: sas/csl
registry: 340268328991.dkr.ecr.eu-west-2.amazonaws.com
tags:
- ${DRONE_COMMIT_SHA}
when:
branch:
<<: *include_default_and_feature_branches
event: [push, pull_request]
depends_on:
- linting
- unit_tests
# Trivy Security Scannner for scanning nodejs packages in Yarn
- name: scan_node_packages
pull: always
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/trivy/client:latest
resources:
limits:
cpu: 1000
memory: 1024Mi
environment:
IMAGE_NAME: sas/csl:${DRONE_COMMIT_SHA}
SEVERITY: MEDIUM,HIGH,CRITICAL --dependency-tree --format table
FAIL_ON_DETECTION: false
IGNORE_UNFIXED: false
ALLOW_CVE_LIST_FILE: hof-services-config/infrastructure/trivy/.trivyignore.yaml
volumes:
- name: dockersock
path: /root/.dockersock
when:
event: [push, pull_request]
depends_on:
- build_image
# 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_DEV
commands:
- bin/deploy.sh $${BRANCH_ENV}
when:
branch:
<<: *include_default_and_feature_branches
event: pull_request
depends_on:
- clone_repos
- image_to_ecr
- 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_DEV
commands:
- sh bin/deploy.sh $${UAT_ENV}
when:
branch:
<<: *include_default_branch
event: push
depends_on:
- clone_repos
- image_to_ecr
# 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: main
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_DEV
volumes:
- name: dockersock
path: /root/.dockersock
commands:
- bin/deploy.sh tear_down
when:
branch: main
event: push
depends_on:
- get_pr_branch
# 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_PROD
KUBE_TOKEN:
from_secret: KUBE_TOKEN_PROD
commands:
- bin/deploy.sh $${STG_ENV}
when:
branch: main
event: push
depends_on:
- clone_repos
- image_to_ecr
## Checks a build being promoted has passed, is on main 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
pull: if-not-exists
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
- find hof-services-config/* | grep -v $HOF_CONFIG | grep -v 'infrastructure' | xargs rm -rf
when:
target: PROD
event: promote
depends_on:
- sanity_check_build_prod
# 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
depends_on:
- clone_repos_prod
# 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 Trivy
- name: cron_clone_repos
pull: if-not-exists
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
- find hof-services-config/* | grep -v $HOF_CONFIG | grep -v 'infrastructure' | xargs rm -rf
when:
cron: security_scans
event: cron
- name: cron_build_image
pull: if-not-exists
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
commands:
# wait for docker service to be up before running docker build
- /usr/local/bin/wait
- docker build --no-cache -t $${IMAGE_REPO}:$${DRONE_COMMIT_SHA} .
volumes:
- name: dockersock
path: /var/run
when:
cron: security_scans
event: cron
depends_on:
- cron_clone_repos
- name: cron_trivy_scan_node_packages
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/trivy/client:latest
pull: always
environment:
IMAGE_NAME: sas/csl:${DRONE_COMMIT_SHA}
SERVICE_URL: https://acp-trivy-helm.acp-trivy.svc.cluster.local:443
SEVERITY: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL --dependency-tree
FAIL_ON_DETECTION: true
IGNORE_UNFIXED: false
ALLOW_CVE_LIST_FILE: hof-services-config/infrastructure/trivy/.trivyignore.yaml
when:
cron: security_scans
event: cron
status:
- success
- failure
depends_on:
- cron_build_image
- name: cron_trivy_scan_image_os
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/trivy/client:latest
pull: always
environment:
IMAGE_NAME: node:20.18.0-alpine3.20@sha256:d504f23acdda979406cf3bdbff0dff7933e5c4ec183dda404ed24286c6125e60
SEVERITY: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL --dependency-tree
FAIL_ON_DETECTION: true
IGNORE_UNFIXED: false
ALLOW_CVE_LIST_FILE: hof-services-config/infrastructure/trivy/.trivyignore.yaml
when:
cron: security_scans
event: cron
depends_on:
- cron_clone_repos
# Slack notification upon a CRON job fail
- name: cron_notify_slack_tear_down_pr_envs
pull: if-not-exists
image: plugins/slack:1.4.1
settings:
channel: sas-hof-build-notify
failure: ignore
icon.url: https://readme.drone.io/logo.svg
template: >
*✘ {{ uppercasefirst build.status }}*: CRON Job `tear_down_pr_envs` for *Controlled Substance Licence Suite* has failed.
Branch <https://github.com/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{build.branch}}> | Commit <https://github.com/{{ repo.owner }}/{{ repo.name }}/commit/{{ build.commit }}|{{ truncate build.commit 8 }}>
*Build <{{build.link}}|#{{build.number}}>*
username: Drone_CI
webhook:
from_secret: slack_sas_hof_build_notify_webhook
when:
cron: tear_down_pr_envs
event: cron
status:
- failure
depends_on:
- cron_tear_down
- name: cron_notify_slack_security_scans
pull: if-not-exists
image: plugins/slack:1.4.1
settings:
channel: sas-hof-security
failure: ignore
icon.url: https://readme.drone.io/logo.svg
template: >
*✘ {{ uppercasefirst build.status }}*: CRON Job `security_scans` for *Controlled Substance Licence Suite* has failed.
Branch <https://github.com/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{build.branch}}> | Commit <https://github.com/{{ repo.owner }}/{{ repo.name }}/commit/{{ build.commit }}|{{ truncate build.commit 8 }}>
*Build <{{build.link}}|#{{build.number}}>*
username: Drone_CI
webhook:
from_secret: slack_sas_hof_security_webhook
when:
cron: security_scans
event: cron
status:
- failure
depends_on:
- cron_trivy_scan_image_os
- cron_trivy_scan_node_packages
services:
- name: docker
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/dind
# Redis session setup in background so ui integration tests can run
- name: session
image: redis
volumes:
- name: dockersock
path: /var/run
volumes:
- name: dockersock
temp: {}