-
Notifications
You must be signed in to change notification settings - Fork 4
/
.drone.yml
477 lines (432 loc) · 13.5 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
---
kind: pipeline
name: default
type: kubernetes
environment:
APP_NAME: certificate-enquiries
PROD_ENV: gro-form
STG_ENV: gro-form-stg
UAT_ENV: gro-form-uat
BRANCH_ENV: gro-form-branch
PRODUCTION_URL: www.certificate-enquiries.homeoffice.gov.uk
IMAGE_URL: quay.io/ukhomeofficedigital
IMAGE_REPO: gro-form
GIT_REPO: UKHomeOffice/gro
HOF_CONFIG: hof-services-config/General_Registrars_Office
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.16.0-alpine3.20@sha256:eb8101caae9ac02229bd64c024919fe3d4504ff7f329da79ca60a04db08cef52
environment:
NOTIFY_KEY: USE_MOCK
commands:
- yarn run test:lint
unit_tests: &unit_tests
pull: if-not-exists
image: node:20.16.0-alpine3.20@sha256:eb8101caae9ac02229bd64c024919fe3d4504ff7f329da79ca60a04db08cef52
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
integration_tests: &integration_tests
pull: if-not-exists
image: node:20.16.0-alpine3.20@sha256:eb8101caae9ac02229bd64c024919fe3d4504ff7f329da79ca60a04db08cef52
environment:
NOTIFY_KEY: USE_MOCK
commands:
- yarn run test:integration
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]
# Trivy Security Scannner for scanning OS related vulnerabilities in Base image of Dockerfile
- name: scan_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.16.0-alpine3.20@sha256:eb8101caae9ac02229bd64c024919fe3d4504ff7f329da79ca60a04db08cef52
SEVERITY: MEDIUM,HIGH,CRITICAL --dependency-tree
FAIL_ON_DETECTION: false
IGNORE_UNFIXED: false
ALLOW_CVE_LIST_FILE: hof-services-config/infrastructure/trivy/.trivyignore.yaml
when:
event: [push, pull_request]
- name: setup_deploy
pull: if-not-exists
image: node:20.16.0-alpine3.20@sha256:eb8101caae9ac02229bd64c024919fe3d4504ff7f329da79ca60a04db08cef52
environment:
NOTIFY_KEY: USE_MOCK
commands:
- yarn install --frozen-lockfile
- yarn run postinstall
when:
branch:
include:
- master
event: push
- name: linting_deploy
<<: *linting
when:
branch:
include:
- master
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: integration_tests_deploy
<<: *integration_tests
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: master
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+drone" -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: master
event: [push, pull_request]
# 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: gro-form:${DRONE_COMMIT_SHA}
SEVERITY: MEDIUM,HIGH,CRITICAL --dependency-tree
FAIL_ON_DETECTION: false
IGNORE_UNFIXED: false
ALLOW_CVE_LIST_FILE: hof-services-config/infrastructure/trivy/.trivyignore.yaml
when:
event: [push, pull_request]
# 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: master
event: pull_request
- name: setup_branch
pull: if-not-exists
image: node:20.16.0-alpine3.20@sha256:eb8101caae9ac02229bd64c024919fe3d4504ff7f329da79ca60a04db08cef52
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: integration_tests_branch
<<: *integration_tests
when:
branch:
include:
- master
- feature/*
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_dev
commands:
- bin/deploy.sh $${UAT_ENV}
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_dev
volumes:
- name: dockersock
path: /root/.dockersock
commands:
- bin/deploy.sh tear_down
when:
branch: master
event: push
# Deploy to Production 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 BRANCH 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
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_trivy_scan_image_os
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/trivy/client:latest
pull: always
environment:
IMAGE_NAME: node:20.16.0-alpine3.20@sha256:eb8101caae9ac02229bd64c024919fe3d4504ff7f329da79ca60a04db08cef52
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
- name: cron_trivy_scan_node_packages
image: 340268328991.dkr.ecr.eu-west-2.amazonaws.com/acp/trivy/client:latest
pull: always
environment:
IMAGE_NAME: gro-form:${DRONE_COMMIT_SHA}
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]
# 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
template: >
*✘ {{ uppercasefirst build.status }}*: Cron job `tear_down_pr_envs` failed to tear down the deployments in the BRANCH environment.
*Repo* <https://github.com/{{ repo.owner }}/{{ repo.name }}/|{{ repo.owner }}/{{ repo.name }}> | *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}}>*
webhook:
from_secret: slack_sas_hof_build_notify_webhook
when:
cron: tear_down_pr_envs
event: cron
status: [ failure ]
- name: cron_notify_slack_security_scans
pull: if-not-exists
image: plugins/slack:1.4.1
settings:
channel: sas-hof-security
failure: ignore
template: >
*✘ {{ uppercasefirst build.status }}*: Cron job `security_scans` has failed. Prioritise reviewing build logs and addressing issues.
*Repo* <https://github.com/{{ repo.owner }}/{{ repo.name }}/|{{ repo.owner }}/{{ repo.name }}> | *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}}>*
webhook:
from_secret: slack_sas_hof_security_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: {}
...