-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
532 lines (520 loc) · 21 KB
/
.gitlab-ci.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
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
stages:
- Test
- build
- development
- development-postdeploy
- preproduction
- preproduction-postdeploy
- production
- production-postdeploy
Test:Required:
stage: Test
image: wodby/php:8.1
before_script:
- ''
script:
- composer install && composer tests-required
allow_failure: false
build-and-push-images:
stage: build
image: docker:20.10.16
services:
- docker:20.10.16-dind
variables:
DOCKER_PASS: ""
before_script:
- docker login -u${DOCKER_USER} -p${DOCKER_PASSWORD} ${DOCKER_REGISTRY}
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker pull ${DOCKER_REGISTRY}/intranet-nginx-drupal || true
- docker pull ${DOCKER_REGISTRY}/intranet-drupal-fpm || true
- docker build -t ${DOCKER_REGISTRY}/intranet-drupal-fpm -t ${DOCKER_REGISTRY}/intranet-drupal-fpm${tag} -t intranet-drupal-fpm -f Dockerfile-drupal .
- docker build -t ${DOCKER_REGISTRY}/intranet-nginx-drupal -t ${DOCKER_REGISTRY}/intranet-nginx-drupal${tag} -t intranet-nginx-drupal -f Dockerfile-nginx .
- docker push ${DOCKER_REGISTRY}/intranet-nginx-drupal${tag}
- docker push ${DOCKER_REGISTRY}/intranet-drupal-fpm${tag}
generate-sbom:
stage: build
image: docker:24
services:
- docker:24-dind
variables:
DOCKER_PASS: ""
before_script:
- docker login -u${DOCKER_USER} -p${DOCKER_PASSWORD} ${DOCKER_REGISTRY}
- apk add bash curl --update-cache
- curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
script:
- docker pull ${DOCKER_REGISTRY}/intranet-drupal-fpm${tag}
- syft docker:${DOCKER_REGISTRY}/intranet-drupal-fpm${tag} -o json=dockerimage.sbom.json
only:
- develop
- /^release\//
artifacts:
paths:
- dockerimage.sbom.json
expire_in: 12 weeks
needs:
- job: build-and-push-images
allow_failure: true
environment:
name: DEV
action: access
analyse-sbom:
stage: build
image: ubuntu:latest
before_script:
- apt update
- apt install -y curl
- curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
script:
- grype sbom:./dockerimage.sbom.json --only-fixed --add-cpes-if-none --fail-on critical
only:
- develop
- /^release\//
needs:
- job: generate-sbom
artifacts: true
allow_failure: true
deploy-to-dev:
image: mcr.microsoft.com/azure-cli
stage: development
needs:
- job: build-and-push-images
environment:
name: development
url: https://dev.essex-intranet.nomensa.xyz/
before_script:
- az extension add --name containerapp
- az login --service-principal -u${ARM_CLIENT_ID} -p${ARM_CLIENT_SECRET} -t${ARM_TENANT_ID}
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- echo "Creating new revision of Container App"
- |
cat > revision.yml <<EOF
properties:
template:
revisionSuffix: ${CI_PIPELINE_ID}
scale:
minReplicas: 0
maxReplicas: 1
rules:
- name: "http-rule"
http:
metadata:
concurrentRequests: 40
containers:
- image: acreccuksdev.azurecr.io/intranet-nginx-drupal$tag
name: nginx
resources:
cpu: 0.25
memory: 0.5Gi
volumeMounts:
- mountPath: /drupal/web/sites/default/files
volumeName: filesharevol
env:
- name: X_ROBOTS_TAG
value: noindex
- name: LIMITED_BETA_MODE
value: 0
probes:
- type: liveness
httpGet:
path: "/08b5d5dc-f2de-4c78-86a7-d3ea80037430"
port: 80
initialDelaySeconds: 5
periodSeconds: 3
- image: acreccuksdev.azurecr.io/intranet-drupal-fpm$tag
name: drupal
resources:
cpu: 0.75
memory: 1.5Gi
volumeMounts:
- mountPath: /drupal/web/sites/default/files
volumeName: filesharevol
env:
- name: MYSQL_HOST
value: mariadb-ecc-uks-dev.mariadb.database.azure.com
- name: MYSQL_USER
value: mariadb-root
- name: MYSQL_DATABASE
value: drupal_intranet
- name: MYSQL_PASSWORD
secretRef: mysql-password
- name: OPENID_CONNECT_PARAMS
secretRef: openid-connect-params
- name: NOMENSA_AAD_CLIENT_SECRET
secretRef: nomensa-aad-client-secret
- name: CLIENT_AAD_CLIENT_SECRET
secretRef: client-aad-client-secret
- name: ENVIRONMENT
value: dev
- name: FATHOM_ID
value: ''
probes:
- type: liveness
tcpSocket:
port: 9000
initialDelaySeconds: 5
periodSeconds: 3
EOF
- az containerapp revision copy --name intranet --resource-group rg-ecc-intranet-uks-dev --yaml revision.yml --subscription "Essex County Council (intranet)" --debug
- az containerapp update --name intranet --resource-group rg-ecc-intranet-uks-dev --subscription "Essex County Council (intranet)" --container-name drupal --set-env-vars "ENVIRONMENT=${ENVIRONMENT}" "FATHOM_ID=${FATHOM_ID}"
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
- when: manual
drush-deploy-dev:
image: mcr.microsoft.com/azure-cli
stage: development-postdeploy
needs: ["deploy-to-dev"]
before_script:
- tdnf -y install socat
- az extension add --name containerapp
- az login --service-principal -u${ARM_CLIENT_ID} -p${ARM_CLIENT_SECRET} -t${ARM_TENANT_ID}
- az account set --subscription "Essex County Council (intranet)"
script:
- timeout 1200 socat EXEC:'az containerapp exec --command /drupal/deploy.sh --name intranet --container drupal --resource-group rg-ecc-intranet-uks-dev',pty,setsid,ctty STDIO,ignoreeof
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
- when: manual
deploy-to-preprod:
image: mcr.microsoft.com/azure-cli
stage: preproduction
needs:
- job: build-and-push-images
environment:
name: preproduction
url: https://preprod.essex-intranet.nomensa.xyz/
before_script:
- az extension add --name containerapp
- az login --service-principal -u${ARM_CLIENT_ID} -p${ARM_CLIENT_SECRET} -t${ARM_TENANT_ID}
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag=""
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- echo "Importing image from Development into Pre-Production"
- az acr import --force --name acreccukspre --source acreccuksdev.azurecr.io/intranet-nginx-drupal$tag --image intranet-nginx-drupal$tag --subscription "Essex County Council (Common)"
- az acr import --force --name acreccukspre --source acreccuksdev.azurecr.io/intranet-nginx-drupal$tag --image intranet-nginx-drupal:latest --subscription "Essex County Council (Common)"
- az acr import --force --name acreccukspre --source acreccuksdev.azurecr.io/intranet-drupal-fpm$tag --image intranet-drupal-fpm$tag --subscription "Essex County Council (Common)"
- az acr import --force --name acreccukspre --source acreccuksdev.azurecr.io/intranet-drupal-fpm$tag --image intranet-drupal-fpm:latest --subscription "Essex County Council (Common)"
- |
cat > revision.yml <<EOF
properties:
template:
revisionSuffix: ${CI_PIPELINE_ID}
scale:
minReplicas: 1
maxReplicas: 3
rules:
- name: "http-rule"
http:
metadata:
concurrentRequests: 40
containers:
- image: acreccukspre.azurecr.io/intranet-nginx-drupal$tag
name: nginx
resources:
cpu: 0.25
memory: 0.5Gi
volumeMounts:
- mountPath: /drupal/web/sites/default/files
volumeName: filesharevol
env:
- name: X_ROBOTS_TAG
value: noindex
- name: LIMITED_BETA_MODE
value: 0
probes:
- type: liveness
httpGet:
path: "/08b5d5dc-f2de-4c78-86a7-d3ea80037430"
port: 80
initialDelaySeconds: 5
periodSeconds: 3
- image: acreccukspre.azurecr.io/intranet-drupal-fpm$tag
name: drupal
resources:
cpu: 0.75
memory: 1.5Gi
volumeMounts:
- mountPath: /drupal/web/sites/default/files
volumeName: filesharevol
env:
- name: MYSQL_HOST
value: mariadb-ecc-uks-pre.mariadb.database.azure.com
- name: MYSQL_USER
value: mariadb-root
- name: MYSQL_DATABASE
value: drupal_intranet
- name: MYSQL_PASSWORD
secretRef: mysql-password
- name: OPENID_CONNECT_PARAMS
secretRef: openid-connect-params
- name: NOMENSA_AAD_CLIENT_SECRET
secretRef: nomensa-aad-client-secret
- name: CLIENT_AAD_CLIENT_SECRET
secretRef: client-aad-client-secret
- name: ENVIRONMENT
value: pre
- name: FATHOM_ID
value: ''
probes:
- type: liveness
tcpSocket:
port: 9000
initialDelaySeconds: 5
periodSeconds: 3
EOF
- echo "Creating new revision of Container App"
- az containerapp revision copy --name intranet --resource-group rg-ecc-intranet-uks-pre --yaml revision.yml --subscription "Essex County Council (intranet)"
- az containerapp update --name intranet --resource-group rg-ecc-intranet-uks-pre --subscription "Essex County Council (intranet)" --container-name drupal --set-env-vars "FATHOM_ID=${FATHOM_ID}"
rules:
- when: manual
drush-deploy-preprod:
image: mcr.microsoft.com/azure-cli
stage: preproduction-postdeploy
needs: ["deploy-to-preprod"]
before_script:
- tdnf -y install socat
- az extension add --name containerapp
- az login --service-principal -u${ARM_CLIENT_ID} -p${ARM_CLIENT_SECRET} -t${ARM_TENANT_ID}
- az account set --subscription "Essex County Council (intranet)"
script:
- timeout 1200 socat EXEC:'az containerapp exec --command /drupal/deploy.sh --name intranet --container drupal --resource-group rg-ecc-intranet-uks-pre',pty,setsid,ctty STDIO,ignoreeof
rules:
- when: manual
deploy-to-prod:
image: mcr.microsoft.com/azure-cli
stage: production
needs: ["deploy-to-preprod"]
environment:
name: production
url: https://intranet.essex.gov.uk/
before_script:
- az extension add --name containerapp
- az login --service-principal -u${ARM_CLIENT_ID} -p${ARM_CLIENT_SECRET} -t${ARM_TENANT_ID}
script:
- echo "Importing image from Pre-Production into Production"
- az acr import --force --name acreccuksprod --source acreccukspre.azurecr.io/intranet-nginx-drupal:${CI_COMMIT_REF_SLUG} --image intranet-nginx-drupal:${CI_COMMIT_REF_SLUG} --subscription "Essex County Council (Common)"
- az acr import --force --name acreccuksprod --source acreccukspre.azurecr.io/intranet-nginx-drupal:${CI_COMMIT_REF_SLUG} --image intranet-nginx-drupal:latest --subscription "Essex County Council (Common)"
- az acr import --force --name acreccuksprod --source acreccukspre.azurecr.io/intranet-drupal-fpm:${CI_COMMIT_REF_SLUG} --image intranet-drupal-fpm:${CI_COMMIT_REF_SLUG} --subscription "Essex County Council (Common)"
- az acr import --force --name acreccuksprod --source acreccukspre.azurecr.io/intranet-drupal-fpm:${CI_COMMIT_REF_SLUG} --image intranet-drupal-fpm:latest --subscription "Essex County Council (Common)"
- echo "Creating new revision of Container App"
- |
cat > revision.yml <<EOF
properties:
template:
revisionSuffix: ${CI_PIPELINE_ID}
scale:
minReplicas: 1
maxReplicas: 3
rules:
- name: "http-rule"
http:
metadata:
concurrentRequests: 40
containers:
- image: acreccuksprod.azurecr.io/intranet-nginx-drupal:${CI_COMMIT_REF_SLUG}
name: nginx
resources:
cpu: 0.25
memory: 0.5Gi
volumeMounts:
- mountPath: /drupal/web/sites/default/files
volumeName: filesharevol
env:
- name: X_ROBOTS_TAG
value: none
- name: CANONICAL_HOST
value: intranet.essex.gov.uk
probes:
- type: liveness
httpGet:
path: "/08b5d5dc-f2de-4c78-86a7-d3ea80037430"
port: 80
initialDelaySeconds: 5
periodSeconds: 3
- image: acreccuksprod.azurecr.io/intranet-drupal-fpm:${CI_COMMIT_REF_SLUG}
name: drupal
resources:
cpu: 0.75
memory: 1.5Gi
volumeMounts:
- mountPath: /drupal/web/sites/default/files
volumeName: filesharevol
env:
- name: MYSQL_HOST
value: mariadb-ecc-uks-prod.mariadb.database.azure.com
- name: MYSQL_USER
value: mariadb-root
- name: MYSQL_DATABASE
value: drupal_intranet
- name: MYSQL_PASSWORD
secretRef: mysql-password
- name: OPENID_CONNECT_PARAMS
secretRef: openid-connect-params
- name: NOMENSA_AAD_CLIENT_SECRET
secretRef: nomensa-aad-client-secret
- name: CLIENT_AAD_CLIENT_SECRET
secretRef: client-aad-client-secret
- name: ENVIRONMENT
value: prod
- name: FATHOM_ID
value: ''
probes:
- type: liveness
tcpSocket:
port: 9000
initialDelaySeconds: 5
periodSeconds: 3
EOF
- az containerapp revision copy --name intranetrb --resource-group rg-ecc-intranet-uks-prod --yaml revision.yml --subscription "Essex County Council (intranet)"
- az containerapp update --name intranetrb --resource-group rg-ecc-intranet-uks-prod --subscription "Essex County Council (intranet)" --container-name drupal --set-env-vars "ENVIRONMENT=${ENVIRONMENT}" "FATHOM_ID=${FATHOM_ID}"
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: manual
- if: '$CI_COMMIT_BRANCH =~ /^release\//'
when: manual
drush-deploy-prod:
image: mcr.microsoft.com/azure-cli
stage: production-postdeploy
needs: ["deploy-to-prod"]
before_script:
- tdnf -y install socat
- az extension add --name containerapp
- az login --service-principal -u${ARM_CLIENT_ID} -p${ARM_CLIENT_SECRET} -t${ARM_TENANT_ID}
- az account set --subscription "Essex County Council (intranet)"
script:
- timeout 1200 socat EXEC:'az containerapp exec --command /drupal/deploy.sh --name intranetrb --container drupal --resource-group rg-ecc-intranet-uks-prod',pty,setsid,ctty STDIO,ignoreeof
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: manual
- if: '$CI_COMMIT_BRANCH =~ /^release\//'
when: manual
deploy-straight-to-prod:
image: mcr.microsoft.com/azure-cli
stage: production
needs:
- job: build-and-push-images
environment:
name: production
url: https://intranet.essex.gov.uk/
before_script:
- az extension add --name containerapp
- az login --service-principal -u${ARM_CLIENT_ID} -p${ARM_CLIENT_SECRET} -t${ARM_TENANT_ID}
script:
- echo "Importing image from Development into Production"
- az acr import --force --name acreccuksprod --source acreccuksdev.azurecr.io/intranet-nginx-drupal:${CI_COMMIT_REF_SLUG} --image intranet-nginx-drupal:${CI_COMMIT_REF_SLUG} --subscription "Essex County Council (Common)"
- az acr import --force --name acreccuksprod --source acreccuksdev.azurecr.io/intranet-nginx-drupal:${CI_COMMIT_REF_SLUG} --image intranet-nginx-drupal:latest --subscription "Essex County Council (Common)"
- az acr import --force --name acreccuksprod --source acreccuksdev.azurecr.io/intranet-drupal-fpm:${CI_COMMIT_REF_SLUG} --image intranet-drupal-fpm:${CI_COMMIT_REF_SLUG} --subscription "Essex County Council (Common)"
- az acr import --force --name acreccuksprod --source acreccuksdev.azurecr.io/intranet-drupal-fpm:${CI_COMMIT_REF_SLUG} --image intranet-drupal-fpm:latest --subscription "Essex County Council (Common)"
- echo "Creating new revision of Container App"
- |
cat > revision.yml <<EOF
properties:
template:
revisionSuffix: ${CI_PIPELINE_ID}
scale:
minReplicas: 1
maxReplicas: 3
rules:
- name: "http-rule"
http:
metadata:
concurrentRequests: 40
containers:
- image: acreccuksprod.azurecr.io/intranet-nginx-drupal:${CI_COMMIT_REF_SLUG}
name: nginx
resources:
cpu: 0.25
memory: 0.5Gi
volumeMounts:
- mountPath: /drupal/web/sites/default/files
volumeName: filesharevol
env:
- name: X_ROBOTS_TAG
value: none
- name: CANONICAL_HOST
value: intranet.essex.gov.uk
probes:
- type: liveness
httpGet:
path: "/08b5d5dc-f2de-4c78-86a7-d3ea80037430"
port: 80
initialDelaySeconds: 5
periodSeconds: 3
- image: acreccuksprod.azurecr.io/intranet-drupal-fpm:${CI_COMMIT_REF_SLUG}
name: drupal
resources:
cpu: 0.75
memory: 1.5Gi
volumeMounts:
- mountPath: /drupal/web/sites/default/files
volumeName: filesharevol
env:
- name: MYSQL_HOST
value: mariadb-ecc-uks-prod.mariadb.database.azure.com
- name: MYSQL_USER
value: mariadb-root
- name: MYSQL_DATABASE
value: drupal_intranet
- name: MYSQL_PASSWORD
secretRef: mysql-password
- name: OPENID_CONNECT_PARAMS
secretRef: openid-connect-params
- name: NOMENSA_AAD_CLIENT_SECRET
secretRef: nomensa-aad-client-secret
- name: CLIENT_AAD_CLIENT_SECRET
secretRef: client-aad-client-secret
- name: ENVIRONMENT
value: prod
- name: FATHOM_ID
value: ''
probes:
- type: liveness
tcpSocket:
port: 9000
initialDelaySeconds: 5
periodSeconds: 3
EOF
- az containerapp revision copy --name intranetrb --resource-group rg-ecc-intranet-uks-prod --yaml revision.yml --subscription "Essex County Council (intranet)"
- az containerapp update --name intranetrb --resource-group rg-ecc-intranet-uks-prod --subscription "Essex County Council (intranet)" --container-name drupal --set-env-vars "ENVIRONMENT=${ENVIRONMENT}" "FATHOM_ID=${FATHOM_ID}"
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: manual
- if: '$CI_COMMIT_BRANCH =~ /^release\//'
when: manual
drush-deploy-straight-to-prod:
image: mcr.microsoft.com/azure-cli
stage: production-postdeploy
needs: ["deploy-straight-to-prod"]
before_script:
- tdnf -y install socat
- az extension add --name containerapp
- az login --service-principal -u${ARM_CLIENT_ID} -p${ARM_CLIENT_SECRET} -t${ARM_TENANT_ID}
- az account set --subscription "Essex County Council (intranet)"
script:
- timeout 1200 socat EXEC:'az containerapp exec --command /drupal/deploy.sh --name intranetrb --container drupal --resource-group rg-ecc-intranet-uks-prod',pty,setsid,ctty STDIO,ignoreeof
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
when: manual
- if: '$CI_COMMIT_BRANCH =~ /^release\//'
when: manual