-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
357 lines (306 loc) · 8.01 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
# SPDX-FileCopyrightText: Magenta ApS <https://magenta.dk>
# SPDX-License-Identifier: MPL-2.0
stages:
- sync
- lint
- build
- test
- coverage
- prepare-release
- release
- deploy
- docs
variables:
IMAGE_SHA: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_SHA}
RELEASE_REGISTRY_IMAGE: index.docker.io/magentaaps/os2mo
PRODUCT: os2mo
COMPONENT: os2mo
PYTEST_COV_MODULE: mora
PYTEST_COV_FAIL_UNDER: 80
# Conditions
#############
# Global Conditions
.if-default-branch-refs: &if-default-branch-refs
if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
.if-tag: &if-tag
if: '$CI_COMMIT_TAG'
.if-tag-semver: &if-tag-semver
if: '$CI_COMMIT_TAG =~ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/'
.if-merge-request: &if-merge-request
if: '$CI_MERGE_REQUEST_IID'
.if-schedule: &if-schedule
if: '$CI_PIPELINE_SOURCE == "schedule"'
# Sync Conditions
.if-merge-request-labels-dont-interrupt: &if-merge-request-labels-dont-interrupt
if: "$CI_MERGE_REQUEST_LABELS =~ /Pipeline::Sync::Don't Interrupt/"
####################
# Backend patterns #
####################
.backend-patterns: &backend-patterns
- backend/**/*
- docker/**/*
- Dockerfile
- pyproject.toml
- poetry.lock
- .gitlab-ci.yml
include:
- local: ra-data-models/.gitlab-ci.yml
- local: gitlab-ci-templates/integration-test-meta.v1.yml
- project: labs/salt-automation
file:
- gitlab-ci-templates/common/no-interrupt-meta.v1.yml
- gitlab-ci-templates/common/conventional-commits.v1.yml
- gitlab-ci-templates/common/conventional-commits-changelog-meta.v1.yml
- gitlab-ci-templates/python/pytest-meta.v1.yml
- gitlab-ci-templates/common/docker-build-meta.v2.yml
- gitlab-ci-templates/common/docker-release-meta.v1.yml
- gitlab-ci-templates/common/config-updater-salt.v1.yml
- gitlab-ci-templates/common/config-updater-flux.v1.yml
- project: labs/salt-automation
file: gitlab-ci-templates/common/pre-commit.v1.yml
rules:
- <<: *if-merge-request
# Workflow
###########
workflow:
rules:
- <<: *if-tag
variables:
# Override the IMAGE_SHA variable on tag pipelines to avoid both the default
# branch pipeline and tag pipeline overriding each other's images arbitrarily when
# they are both running at the same time on master.
IMAGE_SHA: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}
- <<: *if-default-branch-refs
- <<: *if-merge-request
default:
# All jobs are interruptible by default
interruptible: true
# Sync
#######
Do not interrupt:
extends: .do-not-interrupt
rules:
- <<: *if-default-branch-refs
- <<: *if-tag
- <<: *if-schedule
- <<: *if-merge-request-labels-dont-interrupt
- when: manual
allow_failure: true
# Lint
#######
.lint-base:
stage: lint
needs: []
# TODO: Individual lint rules for each file type using 'changes' patterns
rules:
- <<: *if-merge-request
Lint Dockerfiles:
extends: .lint-base
image: hadolint/hadolint:latest-alpine
before_script:
- apk add fd
script:
- echo "Running Hadolint, a Dockerfile linter"
- echo "For more information about reported errors, visit the Hadolint wiki on https://github.com/hadolint/hadolint/wiki"
# Run fd without exec arg to produce a list of files to be linted
- fd Dockerfile
# Run hadolint on every Dockerfile
- fd Dockerfile --exec hadolint
Lint shell scripts:
# TODO: Do this as part of pre-commit instead
extends: .lint-base
image: koalaman/shellcheck-alpine:latest
before_script:
- apk update
- apk add git
script:
- git ls-files --exclude='*.sh' --ignored -c | xargs shellcheck
# Build
########
Fetch OS2mo Source Date:
stage: build
needs: []
interruptible: true
image: alpine:3
before_script:
- apk update
- apk add git
script:
- git log -1 --pretty=%ct > SOURCE_DATE_EPOCH
artifacts:
paths:
- SOURCE_DATE_EPOCH
expire_in: 1 day
rules:
- <<: *if-schedule
when: never
- when: on_success
Build OS2mo:
needs:
- Fetch OS2mo Source Date
extends:
- .build-docker
before_script:
- !reference [.build-docker, before_script]
- export BUILD_DOCKER_EXTRA_FLAGS="--build-arg=COMMIT_SHA=${CI_COMMIT_SHA} --build-arg=COMMIT_TAG=${CI_COMMIT_TAG} --reproducible --build-arg=SOURCE_DATE_EPOCH=$(cat SOURCE_DATE_EPOCH)"
rules:
- <<: *if-schedule
when: never
- when: on_success
Build OS2mo Keycloak:
extends:
- .build-docker
variables:
IMAGE_SHA: ${CI_REGISTRY_IMAGE}/keycloak:${CI_COMMIT_SHA}
before_script:
- export CONTEXT=${CI_PROJECT_DIR}/keycloak
- export DOCKERFILE=${CONTEXT}/Dockerfile
rules:
- <<: *if-schedule
when: never
- when: on_success
# Tests
########
.test-base:
stage: test
variables:
PYPROJECT_PREFIX: "backend/"
HYPOTHESIS_PROFILE: "ci"
rules:
- <<: *if-merge-request
changes: *backend-patterns
Unit-test:
extends:
- .test-base
- .pytest
variables:
PYTEST_ADDOPTS: "-m 'not integration_test' --randomly-seed=$CI_PIPELINE_IID"
Integration-test:
extends:
- .test-base
- .pytest
- .variables:mo
needs:
- Build OS2mo
parallel: 8
image: $IMAGE_SHA
variables:
PYTEST_ADDOPTS: "-m 'integration_test' -p no:randomly --cov=oio_rest" # TODO: enable randomness
services:
- !reference [.services:mo-backing, services]
before_script:
- !reference [.pytest, before_script]
- !reference [.services:mo-backing, before_script]
Export coverage:
extends:
- .test-base
- .export_coverage
needs:
- Unit-test
- Integration-test
Check coverage:
extends:
- .test-base
- .check_coverage
needs:
- Unit-test
- Integration-test
# Release
##########
Release master:
extends: .release-master
Release version:
extends: .release-version
Release Keycloak master:
extends: .release-master
variables:
CI_IMAGE: ${CI_REGISTRY_IMAGE}/keycloak:${CI_COMMIT_SHA}
RELEASE_IMAGE: ${RELEASE_REGISTRY_IMAGE}-keycloak
Release Keycloak version:
extends: .release-version
variables:
CI_IMAGE: ${CI_REGISTRY_IMAGE}/keycloak:${CI_COMMIT_SHA}
RELEASE_IMAGE: ${RELEASE_REGISTRY_IMAGE}-keycloak
# Docs
#######
.docs:rules:deploy-master-docs:
rules:
- <<: *if-schedule
when: never
- <<: *if-tag-semver
when: never
- <<: *if-default-branch-refs
.docs:rules:build-docs:
rules:
- <<: *if-merge-request
- !reference [".docs:rules:deploy-master-docs", rules]
Export GQL Schema:
stage: docs
extends:
- .docs:rules:build-docs
- .variables:mo
needs:
- Build OS2mo
image: $IMAGE_SHA
variables:
OUT: $CI_PROJECT_DIR/docs/src/tech-docs/graphql/voyager.html
QUERY_EXPORT_DIR: "/tmp"
script:
- python docs/schema_to_voyager.py
artifacts:
paths:
- $OUT
Export Changelog:
extends:
- .docs:rules:build-docs
- .docs:export-changelog
variables:
OUT: $CI_PROJECT_DIR/docs/.dynamic_changelog.md
CHANGELOG_EXTRA_FLAGS: --start-rev=12.11.1
.build-docs:
stage: docs
extends:
- .docs:rules:build-docs
needs:
- Export GQL Schema
- Export Changelog
image: python:3.10
variables:
POETRY_VERSION: 1.3.2
POETRY_VIRTUALENVS_CREATE: "false"
before_script:
- pip3 install poetry==${POETRY_VERSION}
- cd docs && poetry install --no-interaction
script:
- cat .dynamic_changelog.md .static_changelog.md >> src/changelog.md
- mkdocs build --strict --site-dir=$CI_PROJECT_DIR/site
artifacts:
paths:
- $CI_PROJECT_DIR/site
expire_in: 1 week
Build and deploy branch docs:
extends:
- .build-docs
environment:
name: docs/$CI_COMMIT_REF_SLUG
url: $CI_JOB_URL/artifacts/file/site/index.html
auto_stop_in: 1 week
rules:
- <<: *if-merge-request
Build master docs:
extends:
- .build-docs
- .docs:rules:deploy-master-docs
# To release to GitLab Pages, the job must be called 'pages'
pages:
stage: docs
extends:
- .docs:rules:deploy-master-docs
needs:
- Build master docs
image: alpine:latest
script:
- cp -r $CI_PROJECT_DIR/site public
artifacts:
paths:
- public/