forked from skilld-labs/skilld-docker-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
466 lines (433 loc) · 12.7 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
# Variables to add in Gitalb UI : Settings > CI/CD
# - SONAR_HOST // Optional
# - SONAR_TOKEN // Optional
# - NEW_RELIC_LICENSE_KEY // Optional
# - RUN_HOOKUPDATE_CI_JOB // Optional
variables:
GIT_DEPTH: "10"
THEME_PATH: "" # Update to enable front jobs (web/themes/custom/XXX)
STORYBOOK_PATH: "" # Update to enable storybook job (themes/custom/XXX/dist/storybook/index.html)
GIT_STRATEGY: fetch
REVIEW_DOMAIN: "XXX.XXX.com" # Mandatory, should equal to DNS of available runner server with docker + docker-compose + traefik
image: skilldlabs/php:74
# Tags defines which runner to use (expected shell runner)
.runner_tag_selection:
tags:
- XXX # Mandatory, should equal to tag of available runner server with docker + docker-compose + traefik
before_script:
- date
- pwd
stages:
- sniffers
- prepare
- deploy
- storybook
- tests
- reports
sniffers:clang:
stage: sniffers
script:
- make clang
only:
- branches
- merge_requests
sniffers:compose:
stage: sniffers
script:
- composer -vvv -V
# Can't use --strict cause we need dev versions for d9 compatibility
- time composer validate --profile
only:
- branches
- merge_requests
sniffers:front:
stage: sniffers
before_script:
- date
- pwd
script:
- make front-install # Dependencies are required for js imports to pass linters
- make lintval
cache:
key:
files:
# Until https://gitlab.com/gitlab-org/gitlab/issues/118466 lands ...
- web/themes/custom/XXX/package.json # ... this path has to be hardcoded
- web/themes/custom/XXX/yarn.lock # ... this path has to be hardcoded
paths:
- ${THEME_PATH}/node_modules/ # Populated during yarn install
artifacts:
name: "$CI_COMMIT_REF_NAME:$CI_COMMIT_SHA:front"
expire_in: 1d
paths:
- ${THEME_PATH}/node_modules/ # Populated during yarn install
extends: .runner_tag_selection
only:
refs:
- branches
- merge_requests
- tags
variables:
- $THEME_PATH
sniffers:phpcs:
stage: sniffers
image: skilldlabs/docker-phpcs-drupal
script:
- docker -v
- make phpcs
extends: .runner_tag_selection
only:
- branches
- merge_requests
sniffers:newlineeof:
stage: sniffers
script:
- make newlineeof
only:
- branches
- merge_requests
sniffers:hookupdate:
stage: sniffers
script:
- make hookupdateval
only:
refs:
- branches
- merge_requests
variables:
- $RUN_HOOKUPDATE_CI_JOB == "TRUE" # To enable once site is live and cannot be rebuilt anymore
sniffers:sonarqube:
stage: sniffers
image: skilldlabs/sonar-scanner:3.3
script:
- sonar-scanner
-Dsonar.projectKey=$CI_PROJECT_PATH_SLUG
-Dsonar.projectName=$CI_PROJECT_NAME
-Dsonar.host.url=${SONAR_HOST}
-Dsonar.login=${SONAR_TOKEN}
-Dsonar.projectBaseDir=.
-Dsonar.sources=.
-Dsonar.inclusions=settings/**,web/modules/custom/**,web/profiles/sdd/**,web/themes/custom/**
only:
- master
- main
allow_failure: true
prepare:back:
stage: prepare
script:
- docker --version
- pwd
- ls -la
- docker run -e "COMPOSER_MEMORY_LIMIT=-1" --user 1000:1000 --rm --init -v `pwd`:`pwd` -w `pwd` skilldlabs/php:74-fpm /bin/ash -c "composer2 --version && composer2 install --no-interaction --prefer-dist -o --ignore-platform-reqs && composer2 create-required-files" # Make back on the fly
cache:
key:
files:
- composer.json
- composer.lock
paths:
- vendor/
- web/core/
- web/libraries/
- web/modules/contrib/
- web/profiles/contrib/
- web/themes/contrib/
- drush/contrib/
dependencies: []
artifacts:
name: "$CI_COMMIT_REF_NAME:$CI_COMMIT_SHA:back"
expire_in: 12 hrs
paths:
- vendor/
- web/
- drush/
exclude:
- web/modules/custom/
- web/themes/custom/
- web/profiles/sdd/
extends: .runner_tag_selection
only:
- branches
- merge_requests
- tags
retry: 2
prepare:front:
stage: prepare
script:
- make front-install
- make front-build
dependencies:
- sniffers:front
artifacts:
name: "$CI_COMMIT_REF_NAME:$CI_COMMIT_SHA:front"
expire_in: 12 hrs
paths:
- ${THEME_PATH}/dist/ # Populated during yarn build
extends: .runner_tag_selection
only:
refs:
- branches
- merge_requests
- tags
variables:
- $THEME_PATH
.deploy_template: &deploy_template
stage: deploy
script:
- echo "Deploy ${CI_ENVIRONMENT_URL} review app to ${BUILD_DIR}."
- echo "CI_ENVIRONMENT_NAME=${CI_ENVIRONMENT_NAME}"
- echo "CI_ENVIRONMENT_SLUG=${CI_ENVIRONMENT_SLUG}"
- echo "CI_COMMIT_REF_SLUG=${CI_COMMIT_REF_SLUG}"
- echo "CI_ENVIRONMENT_URL=${CI_ENVIRONMENT_URL}"
- echo "CI_PROJECT_PATH_SLUG=${CI_PROJECT_PATH_SLUG}"
- echo "CI_PROJECT_NAME=${CI_PROJECT_NAME}"
- echo "REVIEW_DOMAIN=${REVIEW_DOMAIN}"
- mkdir -p ${BUILD_DIR}
- rsync -ah --exclude=.git --exclude=.cache --delete ./ ${BUILD_DIR}
- cd ${BUILD_DIR}
- echo "COMPOSE_PROJECT_NAME=${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}" >> .env.default
- echo "MAIN_DOMAIN_NAME=${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}" >> .env.default
- docker --version
- docker-compose --version
- make all_ci
after_script:
- docker network prune -f
- docker container prune -f
- echo "Started ${CI_ENVIRONMENT_URL} composition in ${BUILD_DIR} from Makefile."
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
dependencies:
- prepare:back
- prepare:front
allow_failure: false # https://gitlab.com/gitlab-org/gitlab-foss/-/issues/25892#note_26909808
extends: .runner_tag_selection
only:
- branches
- merge_requests
deploy:review:
<<: *deploy_template
when: manual
except:
- master
- main
deploy:master:
<<: *deploy_template
when: always
only:
- master
- main
stop_review:
stage: deploy
dependencies: []
script:
- date; pwd; ls -lahq;
- echo "Clean-up build dir ${BUILD_DIR}"
- (if [ -d ${BUILD_DIR} ]; then date; cd ${BUILD_DIR}; pwd; make clean; cd -; rm -rf ${BUILD_DIR}; fi)
- echo "Removed previous review app ${CI_ENVIRONMENT_URL} from ${BUILD_DIR}."
variables:
GIT_STRATEGY: none
when: manual
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
extends: .runner_tag_selection
only:
- branches
- merge_requests
deploy:storybook:
stage: storybook
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
script:
- cd ${BUILD_DIR}
- make build-storybook
- echo "- Storybook is accessible here :" && echo "${CI_ENVIRONMENT_URL}/${STORYBOOK_PATH}"
except:
- tags
extends: .runner_tag_selection
only:
refs:
- branches
- merge_requests
variables:
- $STORYBOOK_PATH
test:behat:
stage: tests
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
script:
- echo "Starting job script in ${BUILD_DIR}"
- cd ${BUILD_DIR}
- BEHAT_ARGS='--colors -f pretty -o std -f junit -o features/junit' make behat
after_script:
- cd ${BUILD_DIR}
- make browser_driver_stop
- rm -rf web/screenshots
- mkdir web/screenshots
- mv features/*.png web/screenshots/
- echo "- Screenshots are available here :" && cd web/screenshots && ls -h *.png | xargs -i echo "${CI_ENVIRONMENT_URL}/screenshots/{}"
- mv ${BUILD_DIR}/features/junit ${CI_PROJECT_DIR}
retry:
max: 2
when: script_failure
dependencies:
- deploy:review
extends: .runner_tag_selection
only:
- branches
- merge_requests
artifacts:
expire_in: 1 week
when: always
paths:
- junit/*.xml
reports:
junit: junit/*.xml
test:cinsp:
stage: tests
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
script:
- echo "Starting job script in ${BUILD_DIR}"
- cd ${BUILD_DIR}
- make cinsp
dependencies:
- deploy:review
extends: .runner_tag_selection
only:
- branches
- merge_requests
test:drupalrector:
stage: tests
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
script:
- echo "Starting job script in ${BUILD_DIR}"
- cd ${BUILD_DIR}
- make drupalrectorval
dependencies:
- deploy:review
extends: .runner_tag_selection
only:
- branches
- merge_requests
test:lighthouse:
stage: tests
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
script:
- echo "Starting job script in ${BUILD_DIR}"
- cd ${BUILD_DIR}
- cat lighthouserc.yml
- docker run --tty --rm --init -d -v `pwd`:`pwd` -w `pwd` -u $(id -u):$(id -g) --entrypoint="/bin/bash" --name "${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}_lighthouse" cypress/browsers:node14.15.0-chrome86-ff82
- docker exec --tty ${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}_lighthouse node -v
- docker exec --tty ${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}_lighthouse npm -v
- docker exec --tty -u root ${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}_lighthouse npm install -g @lhci/[email protected]
- docker exec --tty ${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}_lighthouse lhci --version
- docker exec --tty ${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}_lighthouse lhci healthcheck
- docker exec --tty ${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}_lighthouse lhci collect --url=https://${RA_BASIC_AUTH_USERNAME}:${RA_BASIC_AUTH_PASSWORD}@${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
- docker exec --tty ${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}_lighthouse lhci assert
after_script:
- if [ -n `docker ps -f 'name=${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}_lighthouse' --format '{{.Names}}'` ]; then echo 'Stopping container'; docker rm --force ${CI_PROJECT_NAME}-review-${CI_COMMIT_REF_SLUG}_lighthouse; fi
- cd ${BUILD_DIR}
- if [ -d .lighthouseci ]; then mv .lighthouseci web/lighthouseci; echo "- Reports are available here :" && for i in $(find web/lighthouseci/ -name "*.html"); do basename $i;done | xargs -i echo "${CI_ENVIRONMENT_URL}/lighthouseci/{}"; fi
dependencies:
- deploy:review
extends: .runner_tag_selection
only:
- branches
- merge_requests
test:contentgen:
stage: tests
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
script:
- echo "Starting job script in ${BUILD_DIR}"
- cd ${BUILD_DIR}
- make contentgen
dependencies:
- deploy:review
extends: .runner_tag_selection
only:
- branches
- merge_requests
when: manual
test:patch:
stage: tests
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
script:
- echo "Starting job script in ${BUILD_DIR}"
- cd ${BUILD_DIR}
- make patchval
extends: .runner_tag_selection
except:
variables:
- $RUN_PATCHVAL_CI_JOB == "FALSE" # To use only in case of private packages and if patching upstream is not possible at all
only:
refs:
- branches
- merge_requests
report:statusreportval:
stage: reports
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
script:
- echo "Starting job script in ${BUILD_DIR}"
- cd ${BUILD_DIR}
- make statusreportval
dependencies:
- deploy:review
extends: .runner_tag_selection
only:
- branches
- merge_requests
test:upgradestatus:
stage: reports
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
script:
- echo "Starting job script in ${BUILD_DIR}"
- cd ${BUILD_DIR}
- make upgradestatusval
dependencies:
- deploy:review
extends: .runner_tag_selection
only:
- branches
- merge_requests
report:watchdog:
stage: reports
environment:
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_PATH_SLUG}.${REVIEW_DOMAIN}
name: review/$CI_COMMIT_REF_NAME
on_stop: stop_review
script:
- echo "Starting job script in ${BUILD_DIR}"
- cd ${BUILD_DIR}
- make watchdogval
dependencies:
- deploy:review
extends: .runner_tag_selection
only:
- branches
- merge_requests