-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
465 lines (430 loc) · 9.88 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
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PYTHON_VERSION: "3-alpine"
PACKAGE_NAME: ProdManager
SCAN_KUBERNETES_MANIFESTS: "true"
SAST_EXCLUDED_PATHS: "tests, venv, ProdManager/static/external"
SECRET_DETECTION_EXCLUDED_PATHS: "venv"
DOCKER_DRIVER: overlay2
default:
interruptible: true
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_REF_PROTECTED == "true"
- if: '$CI_COMMIT_TAG'
include:
- template: Security/SAST.gitlab-ci.yml
- template: Security/SAST-IaC.gitlab-ci.yml
- template: DAST.gitlab-ci.yml
- template: DAST-API.gitlab-ci.yml
- template: Security/Secret-Detection.gitlab-ci.yml
- template: Security/Container-Scanning.gitlab-ci.yml
- template: Security/License-Scanning.gitlab-ci.yml
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Verify/Browser-Performance.gitlab-ci.yml
# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/topics/caching/
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
.python_cache: &python_cache
key: ${CI_COMMIT_REF_SLUG}-python
paths:
- .cache/pip
- venv/
.node_cache: &node_cache
key: ${CI_COMMIT_REF_SLUG}-node
paths:
- .npm/
stages:
- test
- build
- validate
- deploy
.python-tests:
stage: test
image: python:$PYTHON_VERSION
cache:
<<: *python_cache
before_script:
- apk add build-base
- python --version # For debugging
- python -m venv venv
- source venv/bin/activate
- pip install --upgrade -r requirements.txt -r requirements.dev.txt
test:
extends: .python-tests
rules:
- if: ! $CI_COMMIT_REF_PROTECTED
allow_failure: true
services:
- redis:latest
variables:
TEST_REDIS_HOSTNAME: redis
TEST_REDIS_PORT: 6379
script:
- flask db upgrade
- >
PYTHONPATH=.
python3 ProdManager/demo/init.py
- >
python3 -m pytest
-v
-n 4
--cov=${PACKAGE_NAME}
--junitxml=result.xml
--html=report.html
tests/${PACKAGE_NAME}/
- coverage html
- coverage xml
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
when: always
paths:
- coverage.xml
- result.xml
- htmlcov
- report.html
- assets
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit: result.xml
lint:
extends: .python-tests
rules:
- if: ! $CI_COMMIT_REF_PROTECTED
allow_failure: true
script:
- >
pylint
${PACKAGE_NAME}/*
| tee pylint-report.txt
artifacts:
when: always
paths:
- pylint-report.txt
.image-tag: &image-tag |
if [[ ! -z "$CI_COMMIT_TAG" ]]; then
export tag="$CI_COMMIT_TAG"
elif [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
export tag="latest"
else
export tag="$CI_COMMIT_REF_SLUG"
fi
image-build:
stage: build
image: docker:latest
services:
- docker:dind
variables:
DOCKER_BUILDKIT: 1
before_script:
- >
docker login
-u "$CI_REGISTRY_USER"
-p "$CI_REGISTRY_PASSWORD"
$CI_REGISTRY
- *image-tag
# Default branch leaves tag empty (= latest tag)
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- >
docker image build
--pull
--tag "$CI_REGISTRY_IMAGE:${tag}"
--file="docker/Dockerfile"
.
- docker image push "$CI_REGISTRY_IMAGE:${tag}"
- docker tag "$CI_REGISTRY_IMAGE:${tag}" "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
- docker image push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
build_doc:
stage: build
extends: .python-tests
needs: []
script:
- apk add -u git
- mkdocs build --verbose
artifacts:
paths:
- site/
version_check:
stage: validate
extends: .python-tests
stage: validate
cache:
<<: *python_cache
needs: []
script:
- PYTHONPATH=. python3 tests/version.py
only:
- tags
container_scanning:
stage: validate
variables:
CS_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
GIT_STRATEGY: fetch
CS_DOCKERFILE_PATH: docker/Dockerfile
CS_DISABLE_LANGUAGE_VULNERABILITY_SCAN: 'false'
.database_upgrade:
extends: .python-tests
stage: validate
cache:
<<: *python_cache
needs: []
script:
- flask db upgrade
- PYTHONPATH=. python3 ProdManager/demo/init.py
database_upgrade_postgresql:
extends: .database_upgrade
services:
- postgres:latest
variables:
POSTGRES_DB: prodmanager
POSTGRES_USER: prodmanager
POSTGRES_PASSWORD: changeit
POSTGRES_HOST_AUTH_METHOD: trust
PM_DATABASE_URI: postgresql://prodmanager:changeit@postgres/prodmanager
database_upgrade_sqlite:
extends: .database_upgrade
openapi_specs:
stage: validate
needs: []
image: node:latest
cache:
<<: *node_cache
before_script:
- npm install -g @apidevtools/swagger-cli
script:
- >
swagger-cli validate
--debug
ProdManager/static/meta/openapi.yaml
container_runtime:
stage: validate
image: alpine:latest
services:
- name: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
alias: prod-manager
variables:
PM_DEMO: "true"
PM_DISABLE_HELLO: "true"
before_script:
- >
apk add
--update
curl
script:
- >
curl -s
http://prod-manager:8080/health
- >
curl -s
http://prod-manager:8080/
| (! grep -q "Internal error")
kubernetes_manifests:
stage: validate
image:
name: garethr/kubeval:latest
entrypoint: ["/bin/sh", "-l", "-c"]
needs: []
parallel:
matrix:
- KUBE_VERSION: "1.24.9"
- KUBE_VERSION: "1.25.8"
- KUBE_VERSION: "1.26.3"
variables:
KUBEVAL_SCHEMA_LOCATION: "https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master"
before_script:
- kubeval --version
script:
- >
kubeval
--force-color
--strict
--kubernetes-version $KUBE_VERSION
deploy/kubernetes/*.yml
.dast:
dependencies:
- openapi_specs
variables:
DAST_SPIDER_MINS: 5
services:
- name: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
alias: prod-manager
variables:
PM_DEMO: "true"
PM_DISABLE_HELLO: "true"
dast:
stage: validate
extends: .dast
variables:
DAST_PATHS_FILE: url_file.txt
DAST_BROWSER_SCAN: "true"
DAST_FULL_SCAN_ENABLED: "true"
DAST_WEBSITE: http://prod-manager:8080
DAST_AUTH_URL: http://prod-manager:8080/login
DAST_AUTH_VERIFICATION_SELECTOR: "id:logout"
DAST_AUTH_REPORT: "true"
DAST_USERNAME: it
DAST_USERNAME_FIELD: secret
DAST_PASSWORD: change
DAST_PASSWORD_FIELD: secret
before_script:
- |
cat << EOF > $DAST_PATHS_FILE
/
/scope
/service
/monitor
/incident
/maintenance
/announcement
/about
/login
EOF
artifacts:
paths: [gl-dast-debug-auth-report.html]
when: always
dast_api:
stage: validate
extends: .dast
variables:
DAST_DEBUG: "true"
DAST_API_PROFILE: Quick
DAST_API_OPENAPI: ProdManager/static/meta/openapi.yaml
DAST_API_TARGET_URL: http://prod-manager:8080
DAST_API_OVERRIDES_FILE: .gitlab/ci_api_overrides.json
upload_image:
stage: deploy
image:
name: quay.io/skopeo/stable:latest
entrypoint: ["/bin/bash", "-l", "-c"]
only:
- develop
- tags
before_script:
- >
skopeo login
--username "$CI_REGISTRY_USER"
--password "$CI_REGISTRY_PASSWORD"
$CI_REGISTRY
- >
skopeo login
--username "$SCW_ACCESS_KEY"
--password "$SCW_SECRET_KEY"
$CONTAINER_REGISTRY
- *image-tag
script:
- >
skopeo copy
"docker://$CI_REGISTRY_IMAGE:${tag}"
docker://$CONTAINER_REGISTRY/prod-manager:${tag}
.deploy:
stage: deploy
image:
name: scaleway/cli:latest
entrypoint: ["/bin/bash", "-l", "-c"]
timeout: 5 minutes
needs:
- upload_image
before_script:
- >
apk add
--update
jq
- *image-tag
- mkdir -p $HOME/.config/scw
- touch $HOME/.config/scw/config.yaml
script:
- >
/scw container
container update
$SCW_CONTAINER_ID
registry-image=$CONTAINER_REGISTRY/prod-manager:${tag}
| grep -E '^(Name|Status|RegistryImage|Region)\s'
- >
/scw container
container deploy
$SCW_CONTAINER_ID
| grep -E '^(Name|Status|RegistryImage|Region)\s'
- |
while [ $(/scw container container get $SCW_CONTAINER_ID -o json | jq -r '.status') = "pending" ]; do
echo "Waiting for the container to deploy"
sleep 5
done
- test $(/scw container container get $SCW_CONTAINER_ID -o json | jq -r '.status') = "ready"
deploy_develop:
extends: .deploy
environment:
name: develop
action: start
only:
- develop
deploy_demo:
extends: .deploy
environment:
name: demo
action: start
only:
- tags
deploy_sandbox:
extends: .deploy
environment:
name: sandbox
action: start
only:
- tags
browser_performance:
stage: deploy
variables:
URL: $CI_ENVIRONMENT_URL
SITESPEED_OPTIONS: "-d 2"
only: []
browser_performance_develop:
extends: browser_performance
needs:
- deploy_develop
environment:
name: develop
action: verify
only:
- develop
browser_performance_demo:
extends: browser_performance
needs:
- deploy_demo
environment:
name: demo
action: verify
only:
- tags
browser_performance_sandbox:
extends: browser_performance
needs:
- deploy_sandbox
environment:
name: sandbox
action: verify
only:
- tags
pages:
stage: deploy
image: busybox
dependencies:
- build_doc
environment:
name: doc
action: start
url: https://prod-manager.tiwabbit.fr
only:
- tags
script:
- mv site/ public/
artifacts:
paths:
- public/