-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
501 lines (459 loc) · 14.9 KB
/
Copy path.gitlab-ci.yml
File metadata and controls
501 lines (459 loc) · 14.9 KB
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
---
default:
image: quay.io/testing-farm/python-ci-image:latest
variables:
# GitLab CI runs in world writable directory, we need to explicitely set ANSIBLE_CONFIG
# https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-world-writable-dir
ANSIBLE_CONFIG: ansible.cfg
# Used only for staging/ci environment, no-op for others
STAGING_CI_SUFFIX: $CI_MERGE_REQUEST_ID-$CI_JOB_ID
# Set USER used to derive certain dev environment resource names
USER: gitlab-ci-$CI_JOB_ID
workflow:
rules:
# for merge requests
- if: $CI_MERGE_REQUEST_ID
# for the tip of the default branch
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# for schedules
- if: $CI_PIPELINE_SOURCE == "schedule"
.rules:
not_default_branch:
# do not run for default branch
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: never
not_schedule:
# do not run for schedules
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
only_default_branch:
# run only for default branch
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: never
only_schedule:
# run only for schedule
- if: $CI_PIPELINE_SOURCE != "schedule"
when: never
gitlab_ci:
- changes:
- .gitlab-ci.yml
secrets:
- changes:
- ansible/secrets/credentials.yaml
infrastructure:
- !reference [.rules, secrets]
- !reference [.rules, gitlab_ci]
- changes:
- .envrc
- poetry.lock
- Makefile*
- setup/*
ansible:
- changes:
- ansible/files/**/*
- ansible/inventory/**/*
- ansible/requirements.yaml
- ansible/roles/**/*
- ansible/tasks/**/*
- ansible/vars/**/*
terragrunt_modules_infra:
- changes:
- terragrunt/modules/gitlab/**/*
terragrunt_modules_testing_farm:
- changes:
- terragrunt/modules/artemis/**/*
- terragrunt/modules/eks/**/*
- terragrunt/modules/localhost/**/*
- terragrunt/modules/vault/**/*
- terragrunt/modules/worker/**/*
terragrunt_infra:
- !reference [.rules, infrastructure]
- !reference [.rules, terragrunt_modules_infra]
- changes:
- terragrunt/environments/infra/**/*
terragrunt_testing_farm:
- !reference [.rules, infrastructure]
- !reference [.rules, terragrunt_modules_testing_farm]
terragrunt_dev:
- !reference [.rules, terragrunt_testing_farm]
- changes:
# NOTE: need to be explicit here, no nice excludes supported yet
# We do not run this when variables-composes changed for example
# https://gitlab.com/gitlab-org/gitlab/-/issues/198688
#
# NOTE: we do not want this run on config changes, validation is done against staging
- terragrunt/environments/dev/*/terragrunt.hcl
- terragrunt/environments/dev/artemis/**/*
- terragrunt/environments/dev/server/**/*
- terragrunt/environments/dev/worker-public/jobs/**/*
terragrunt_staging:
- !reference [.rules, terragrunt_testing_farm]
- changes:
- terragrunt/environments/staging/**/*
terragrunt_staging_ci:
- !reference [.rules, terragrunt_testing_farm]
- changes:
- terragrunt/environments/staging/artemis/**/*
- terragrunt/environments/staging/worker-local/**/*
terragrunt_production:
- !reference [.rules, infrastructure]
- changes:
- terragrunt/environments/production/**/*
public_compose_tests:
- changes:
- tests/worker/public/compose*
public_pipeline_tests:
- changes:
- tests/worker/base-scenarios/*
- tests/worker/public/tmt*
- tests/worker/public/sti*
direnv:
stage: test
before_script:
- dnf -y install direnv libffi libffi-devel
- echo -n "$VAULT_PASSWORD" > .vault_pass
script:
- direnv allow
- eval "$(direnv export bash)"
- make generate/staging/citool-config
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
.direnv:
before_script:
- dnf -y install direnv libffi libffi-devel podman rsync awk
- echo -n "$VAULT_PASSWORD" > .vault_pass
- poetry env use python3.12
- direnv allow
- eval "$(direnv export bash)"
script:
- eval "$(direnv export bash)"
artifacts:
paths:
- .direnv/envrc.log
when: always
# Workaround for after_script timing-out
.script_with_cleanup:
script:
- /bin/bash -c "${SCRIPT}" && EXIT_CODE=$? || EXIT_CODE=$?
- if [ ${EXIT_CODE} -ne 0 ] && [ -n "$ERROR_SCRIPT" ]; then /bin/bash -c "${ERROR_SCRIPT}" || true; fi
- /bin/bash -c "${AFTER_SCRIPT}"
- "[ ${EXIT_CODE} = 0 ]"
# Archive pytest-gluetool artifacts
.archive_tests:
variables:
CI_ARTIFACT_URL_PREFIX_FILE:
"https://$CI_PAGES_HOSTNAME/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts"
CI_ARTIFACT_URL_PREFIX_DIR:
"$CI_PROJECT_URL/-/jobs/$CI_JOB_ID/artifacts/browse"
artifacts:
expose_as: report
paths:
- report.html
- assets/style.css
- .pytest/
- .direnv/envrc.log
when: always
ansible-vault:
extends: .direnv
stage: test
script:
- !reference [.direnv, script]
- dnf -y install ansible-lint
- >
ansible-vault view $SECRETS_FILE | yamllint -d "rules: {line-length: {level: warning}}" -
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, secrets]
pre-commit:
extends: .direnv
stage: test
variables:
# Disable parallelism on all levels to mitigate test flakes
GOMAXPROCS: 1
TF_PARALLELISM: 1
TERRAGRUNT_PARALLELISM: 1
script:
- !reference [.direnv, script]
# Need to init the modules, or pre-commit terragrunt_validate will fail :(
- make -j4 dev/init staging/init staging/init/ci production/init
# Check if no changes after init (replacement for unstable terragrunt_validate pre-commit hook)
- "if ! git diff; then echo 'Error: terragrunt init shows some changes.'; exit 1; fi"
- pre-commit run --config .pre-commit-config-maintainer.yaml --all-files
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
- when: always
test/dev:
extends: .direnv
stage: test
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
TF_VAR_cluster_name: testing-farm-gitlab-ci-$CI_JOB_ID
SCRIPT: >-
make dev/init &&
make dev/apply &&
make wait/artemis/dev &&
make dev/create/public/worker &&
testing-farm-dev-public-developer request --git-url https://gitlab.com/testing-farm/tests --plan /testing-farm/sanity
ERROR_SCRIPT: >-
make dev/kubeconfig &&
echo &&
echo "==============================================" &&
echo "== Kubernetes Container Logs" &&
echo "==============================================" &&
echo &&
kubectl stern --no-follow --tail 100 -A . &&
echo &&
echo "==============================================" &&
echo "== Kubernetes Event Logs" &&
echo "==============================================" &&
echo &&
kubectl get events --all-namespaces -o wide
AFTER_SCRIPT: make dev/destroy > /dev/null
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, ansible]
- !reference [.rules, terragrunt_dev]
test/staging/pipeline:
extends: [.direnv, .archive_tests]
stage: test
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
SCRIPT: >-
git clone https://gitlab.com/testing-farm/profiles &&
ANSIBLE_COLLECTIONS_PATH=/etc/testing-farm/profiles make -C profiles install/local &&
make staging/apply/ci &&
PYTEST_OPTIONS="--profiles /etc/testing-farm/profiles" make test/staging/pipeline/ci
ERROR_SCRIPT: >-
make staging/kubeconfig &&
NAMESPACE="$(env -C terragrunt/environments/staging/ci/artemis terragrunt output --raw namespace)" &&
echo &&
echo "==============================================" &&
echo "== Kubernetes Container Logs" &&
echo "==============================================" &&
echo &&
kubectl stern --no-follow --tail 100 -n "$NAMESPACE" .
echo &&
echo "==============================================" &&
echo "== Kubernetes Event Logs" &&
echo "==============================================" &&
echo &&
kubectl get events -n "$NAMESPACE" -o wide
AFTER_SCRIPT: >-
make staging/destroy/ci > /dev/null &&
make test/pytest/oculus
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, terragrunt_staging_ci]
- !reference [.rules, public_pipeline_tests]
test/staging/pipeline/container:
extends: [.direnv, .archive_tests]
stage: test
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
PYTEST_PARALLEL_RUNS: 1
SCRIPT: >-
git clone https://gitlab.com/testing-farm/profiles &&
ANSIBLE_COLLECTIONS_PATH=/etc/testing-farm/profiles make -C profiles install/local &&
PYTEST_OPTIONS="--profiles /etc/testing-farm/profiles" make test/staging/pipeline/container/ci
AFTER_SCRIPT: >-
make test/pytest/oculus
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, terragrunt_staging_ci]
- !reference [.rules, public_pipeline_tests]
test/staging/compose:
extends: [.direnv, .archive_tests]
stage: test
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
SCRIPT: >-
git clone https://gitlab.com/testing-farm/profiles &&
ANSIBLE_COLLECTIONS_PATH=/etc/testing-farm/profiles make -C profiles install/local &&
make staging/apply/ci &&
PYTEST_OPTIONS="--profiles /etc/testing-farm/profiles" make test/staging/compose/ci
ERROR_SCRIPT: >-
make staging/kubeconfig &&
NAMESPACE="$(env -C terragrunt/environments/staging/ci/artemis terragrunt output --raw namespace)" &&
echo &&
echo "==============================================" &&
echo "== Kubernetes Container Logs" &&
echo "==============================================" &&
echo &&
kubectl stern --no-follow --tail 100 -n "$NAMESPACE" .
echo &&
echo "==============================================" &&
echo "== Kubernetes Event Logs" &&
echo "==============================================" &&
echo &&
kubectl get events -n "$NAMESPACE" -o wide
AFTER_SCRIPT: >-
make staging/destroy/ci > /dev/null &&
make test/pytest/oculus
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, terragrunt_staging_ci]
- !reference [.rules, public_compose_tests]
test/terraform/modules:
extends: [.direnv]
stage: test
script:
- dnf -y install golang
- make test/terraform/modules
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, terragrunt_modules_infra]
- !reference [.rules, terragrunt_modules_testing_farm]
test/infra:
extends: .direnv
stage: test
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
TERRAGRUNT_PARALLELISM: 3
SCRIPT: >-
make infra/init &&
make infra/plan
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, terragrunt_infra]
test/staging:
extends: .direnv
stage: test
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
SCRIPT: >-
make staging/plan
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, terragrunt_staging]
test/production:
extends: .direnv
stage: test
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
SCRIPT: >-
make production/plan
rules:
- !reference [.rules, not_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, terragrunt_production]
redeploy/staging:
extends: .direnv
stage: deploy
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
SCRIPT: >-
make staging/init &&
make staging/destroy &&
make staging/apply &&
make wait/artemis/staging &&
make staging/create/public/worker
rules:
- !reference [.rules, only_default_branch]
- !reference [.rules, only_schedule]
- if: '$SCHEDULED_JOB == "redeploy/staging"'
cleanup/ci:
extends: .direnv
stage: deploy
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
SCRIPT: make cleanup/ci
rules:
- !reference [.rules, only_default_branch]
- !reference [.rules, only_schedule]
- if: '$SCHEDULED_JOB == "cleanup/ci"'
cleanup/dev:
extends: .direnv
stage: deploy
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
SCRIPT: make dev/destroy/force/all
rules:
- !reference [.rules, only_default_branch]
- !reference [.rules, only_schedule]
- if: '$SCHEDULED_JOB == "cleanup/dev"'
deploy/infra:
extends: .direnv
stage: deploy
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
SCRIPT: >-
make infra/init &&
make infra/apply
rules:
- !reference [.rules, only_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, terragrunt_infra]
deploy/staging:
extends: .direnv
stage: deploy
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
SCRIPT: >-
make staging/apply
rules:
- !reference [.rules, only_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, terragrunt_staging]
deploy/production:
extends: .direnv
stage: deploy
needs:
# NOTE: prevent artifacts to be copied from dependant jobs, we want a fresh direnv setup here
- job: deploy/staging
optional: true
artifacts: false
script:
- !reference [.direnv, script]
- !reference [.script_with_cleanup, script]
variables:
SCRIPT: >-
make production/apply
rules:
- !reference [.rules, only_default_branch]
- !reference [.rules, not_schedule]
- !reference [.rules, terragrunt_production]
update/composes/public:
extends: .direnv
stage: deploy
script:
- !reference [.direnv, script]
- make compose/update/public
- git remote set-url origin https://oauth2:${GITLAB_PRIVATE_TOKEN}@gitlab.com/testing-farm/infrastructure.git
- gitlab create-merge-request --title="Update public composes $(date -u --rfc-3339=date)"
rules:
- !reference [.rules, only_schedule]
- if: '$SCHEDULED_JOB == "compose/update/public"'