-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
411 lines (360 loc) · 11.3 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
stages:
- lint
- build
- test
- release
- docs
- configure
- deploy
# https://docs.gitlab.com/ee/ci/yaml/workflow.html#switch-between-branch-pipelines-and-merge-request-pipelines
.if-default-branch-refs: &if-default-branch-refs
if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
.if-tag: &if-tag
if: '$CI_COMMIT_TAG'
.if-merge-request: &if-merge-request
if: '$CI_MERGE_REQUEST_IID'
# 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
include:
- project: 'labs/salt-automation'
file:
- '/gitlab-ci-templates/common/rules.v1.yml'
- '/gitlab-ci-templates/common/saltbert.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-meta.v1.yml'
- "/gitlab-ci-templates/common/conventional-commits-meta.v1.yml"
- "/gitlab-ci-templates/common/conventional-commits-changelog-meta.v1.yml"
.releaserc:
before_script:
- |
cat <<EOF > .releaserc.yaml
branches:
- master
tagFormat: "\${version}-rc1"
plugins:
- - "@semantic-release/commit-analyzer"
- preset: angular
releaseRules:
- type: chore
scope: deps-dev
release: patch
- type: chore
scope: deps
release: patch
- type: build
scope: deps-dev
release: patch
- type: build
scope: deps
release: patch
- "@semantic-release/release-notes-generator"
- "@semantic-release/changelog"
- - "@semantic-release/gitlab"
- assets:
- path: CHANGELOG.md
label: Changelog
EOF
variables:
# Project variables
RELEASE_REGISTRY: docker.io
RELEASE_REGISTRY_IMAGE: index.docker.io/magentaaps/kas
KAS_IMAGE_SHA: ${CI_REGISTRY_IMAGE}/kas:${CI_COMMIT_SHA}
KAS_IMAGE_DEV: magentaaps/kas:dev
KAS_IMAGE_TAG: magentaaps/kas:${CI_COMMIT_TAG}
SELF_IMAGE_SHA: ${CI_REGISTRY_IMAGE}/self:${CI_COMMIT_SHA}
SELF_IMAGE_DEV: magentaaps/kas-self:dev-self
SELF_IMAGE_TAG: magentaaps/kas-self:${CI_COMMIT_TAG}
ER_IMAGE_SHA: ${CI_REGISTRY_IMAGE}/er:${CI_COMMIT_SHA}
ER_IMAGE_DEV: magentaaps/kas-er:dev
ER_IMAGE_TAG: magentaaps/kas-er:${CI_COMMIT_TAG}
VERSION: PIPELINE
# Lint stage
#############
.lint-default: &lint-default
stage: lint
needs: []
image: python:3.8
Lint Commits:
extends: .lint:commits
variables:
CONFIG: '{ extends: [''@commitlint/config-conventional''], ignores: [(message) => message.includes(''suggestion(s)'')], }'
Lint Python:
<<: *lint-default
before_script:
- pip3 install flake8==7.1.0
- pip3 install black==24.4.1
- pip3 install isort==5.12.0
#- pip3 install -r django/requirements.txt
script:
- flake8 --max-line-length 88 --exclude=tests,migrations,reportgeneration --extend-ignore E226,E203 kas/
- flake8 --max-line-length 88 --exclude=tests,migrations --extend-ignore E226,E203 selvbetjening/
- black --check --diff --exclude=migrations kas/
- black --check --diff --exclude=migrations selvbetjening/
- isort -c --diff -l 88 --skip migrations kas/
- isort -c --diff -l 88 --skip migrations selvbetjening/
Lint Dockerfiles:
<<: *lint-default
image: hadolint/hadolint:latest-debian
before_script:
- apt-get -y update
- apt-get -y install --no-install-recommends git
script:
- git ls-files --exclude='Dockerfile*' --ignored | xargs --max-lines=1 hadolint
Lint REUSE compliance:
extends: .lint-default
image:
name: fsfe/reuse:latest
entrypoint: [""]
script:
- reuse lint
# Build stage
#############
Build KAS image:
extends: .build-docker
variables:
CI_IMAGE: ${KAS_IMAGE_SHA}
DOCKERFILE: $CI_PROJECT_DIR/docker/Dockerfile.kas
Build Selvbetjening image:
extends: .build-docker
variables:
CI_IMAGE: ${SELF_IMAGE_SHA}
DOCKERFILE: $CI_PROJECT_DIR/docker/Dockerfile.selvbetjening
Build ER image:
extends: .build-docker
variables:
CI_IMAGE: ${ER_IMAGE_SHA}
DOCKERFILE: $CI_PROJECT_DIR/docker/Dockerfile.er
# Test stage
############
.test-default: &test-default
stage: test
dependencies: []
.test-admin: &test-admin
<<: *test-default
needs: ["Build KAS image"]
image: ${KAS_IMAGE_SHA}
services:
- name: postgres:13
alias: kas-db
variables:
DJANGO_SECRET_KEY: e$s6@0(hs5ja79-&!l7vt^onoe4h^*bv_e4hj&wt5^8*&x76-$
DJANGO_TIMEZONE: Europe/Copenhagen
DJANGO_ADMIN_GROUP: admins
POSTGRES_USER: kas
POSTGRES_PASSWORD: kas
POSTGRES_DB: kas
POSTGRES_HOST: kas-db
HOST_DOMAIN: http://localhost
REST_HOST: http://kas:8000
REST_TOKEN: 1799c88d-10e6-489d-8fe9-adeb2fd8a36f
SELVBETJENING_REPRESENTATION_START: http://kas-selvbetjening:8080/represent-start/
SELVBETJENING_REPRESENTATION_STOP: http://kas-selvbetjening:8000/represent-stop/
SELVBETJENING_REPRESENTATION_TOKEN_MAX_AGE: 60
EBOKS_DISPATCH_BULK_SIZE: 100
EBOKS_MOCK: 'True'
# No access to the eskat database, so give it dummy environment variables
ESKAT_HOST: ""
ESKAT_PORT: ""
ESKAT_DB: ""
ESKAT_USER: ""
ESKAT_PASSWORD: ""
GENERATE_DB_DOCUMENTATION: "false"
# No fiddling with sftp server during testing
TENQ_HOST: ""
TENQ_PORT: 22
TENQ_USER: ""
TENQ_PASSWORD: ""
TENQ_KNOWN_HOSTS: ""
TENQ_PROJECT_ID: "KAS"
TENQ_PROD_PATH: ""
TENQ_TEST_PATH: ""
# Simulate development environment while running tests so we use mockup data
ENVIRONMENT: development
DISABLE_METRICS: 'True'
Admin Unittest:
<<: *test-admin
script:
- cd /app
- coverage run manage.py test --parallel 4
- coverage combine
- coverage report --show-missing --fail-under=72
- coverage xml
coverage: '/^TOTAL.+?(\d+\%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: /app/coverage.xml
Admin Django check:
<<: *test-admin
script:
- cd /app
- python manage.py check kas eskat prisme worker
.test-selvbetjening: &test-selvbetjening
<<: *test-default
needs: ["Build Selvbetjening image"]
image: ${SELF_IMAGE_SHA}
services:
- name: postgres:13
alias: kas-db
variables:
DJANGO_SECRET_KEY: e$s6@0(hs5ja79-&!l7vt^onoe4h^*bv_e4hj&wt5^8*&x76-$
DJANGO_TIMEZONE: Europe/Copenhagen
POSTGRES_USER: kas
POSTGRES_PASSWORD: kas
POSTGRES_DB: selvbetjening
POSTGRES_HOST: kas-db
DJANGO_LANGUAGE_COOKIE_DOMAIN: localhost
REST_HOST: http://kas:8000
REST_TOKEN: 1799c88d-10e6-489d-8fe9-adeb2fd8a36f
KAS_REPRESENTATION_STOP: http://kas:8000/represent-stop
CLOSE_AT_MONTH: 5
CLOSE_AT_DATE: 6
SAML_ENABLED: "true"
SAML_SP_ENTITY_ID: http://localhost:8040/saml/metadata/
SAML_SP_LOGIN_CALLBACK_URI: http://localhost:8040/login/callback
SAML_SP_LOGOUT_CALLBACK_URI: http://localhost:8040/logout/callback/
SAML_SP_CERTIFICATE: /ssl/sp/selfsigned.crt
SAML_SP_KEY: /ssl/sp/selfsigned.key
SAML_IDP_ENTITY_ID: http://localhost:8080/simplesaml/saml2/idp/metadata.php
SAML_IDP_LOGIN_URI: http://localhost:8080/simplesaml/saml2/idp/SSOService.php
SAML_IDP_LOGOUT_URI: http://localhost:8080/simplesaml/saml2/idp/SingleLogoutService.php
SAML_IDP_CERTIFICATE: /ssl/idp/selfsigned.crt
SAML_IDP_METADATA: http://localhost:8080/simplesaml/saml2/idp/metadata.php
SAML_CONTACT_TECHNICAL_NAME: Tester
SAML_CONTACT_TECHNICAL_EMAIL: [email protected]
SAML_CONTACT_SUPPORT_NAME: Tester
SAML_CONTACT_SUPPORT_EMAIL: [email protected]
SKIP_IDP_METADATA: "true"
Selvbetjening Unittest:
<<: *test-selvbetjening
script:
- cd /app
- coverage run manage.py test --parallel 4
- coverage combine
- coverage report --show-missing --fail-under=25
- coverage xml
coverage: '/^TOTAL.+?(\d+\%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: /app/coverage.xml
Selvbetjening Django check:
<<: *test-selvbetjening
script:
- cd /app
- python manage.py check selvbetjening
# Release stage
###############
.release:
stage: release
image: alpine
variables:
GIT_STRATEGY: none # We do not need the source code
dependencies: []
before_script:
# install skopeo
- apk add skopeo
Release Admin image:
# Releases both stable and RC releases.
extends:
- .rules:semver-all
- .release
needs: ["Admin Unittest"]
script:
- skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${KAS_IMAGE_SHA}"
"docker://${KAS_IMAGE_TAG}"
Release Selvbetjening image:
extends:
- .rules:semver-all
- .release
needs: ["Selvbetjening Unittest"]
script:
- skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${SELF_IMAGE_SHA}"
"docker://${SELF_IMAGE_TAG}"
Release ER image:
extends:
- .rules:semver-all
- .release
needs: ["Admin Unittest"]
script:
- skopeo copy
--src-creds=${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}
--dest-creds=${RELEASE_REGISTRY_USER}:${RELEASE_REGISTRY_PASSWORD}
"docker://${ER_IMAGE_SHA}"
"docker://${ER_IMAGE_TAG}"
Release Semantic commit:
extends: .release:semantic-commit
Release Generate changelog:
extends: .release:generate-changelog
Docs Export changelog:
extends:
- .rules:semver-all
- .docs:export-changelog
variables:
CHANGELOG_EXTRA_FLAGS: "--merge-prerelease"
# Configure stage
#################
Configure Test:
stage: configure
extends:
- .rules:semver-all
- .config:endpoint-with-tag
needs: ["Release Admin image", "Release Selvbetjening image"]
variables:
# Matches routing in config-updater/config_updater/kas/main.py in salt repo
ENDPOINT: kas/salt/update-test
Configure Production:
stage: configure
extends:
- .rules:semver-core
- .config:endpoint-with-tag
needs: ["Release Admin image", "Release Selvbetjening image"]
variables:
# Matches routing in config-updater/config_updater/kas/main.py in salt repo
ENDPOINT: kas/salt/update-production
# Deploy stage
##############
Deploy to Staging:
stage: deploy
extends:
- .rules:semver-all
- .saltbert
needs: ["Release Admin image", "Release Selvbetjening image", "Release ER image", "Configure Test"]
variables:
SALTBERT_ORCHESTRATION: groenland.kas.service-test
SALTBERT_URL: https://saltmaster.groenland.magentahosted.dk
environment:
name: test
url: "https://test.kas.aka.nanoq.gl"
Deploy to Production:
stage: deploy
extends:
- .rules:semver-core
- .saltbert
needs: ["Release Admin image", "Release Selvbetjening image", "Configure Production"]
variables:
SALTBERT_ORCHESTRATION: groenland.kas.service-prod
SALTBERT_URL: https://saltmaster.groenland.magentahosted.dk
when: manual
environment:
name: production
url: "https://kas.aka.nanoq.gl"