-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
390 lines (369 loc) · 11.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
workflow:
auto_cancel:
on_new_commit: interruptible
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_EVENT_TYPE == 'merge_train'
- if: $CI_COMMIT_BRANCH
- if: $CI_COMMIT_TAG
stages:
- lint
- build-dev
- test
- build
- deploy
pre-commit:
stage: lint
interruptible: true
image:
name: python:3.10.16-alpine@sha256:4c4097e46608e9b9025a486e3b72d628ac8947a3caa20f142c2e8c0029a12b21
entrypoint: [""]
script:
- apk add git
- wget https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64
- wget https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64.sha256
- sha256sum -c hadolint-Linux-x86_64.sha256
- install hadolint-Linux-x86_64 /usr/local/bin/hadolint
- pip install pre-commit
- pre-commit run --all-files
lint-kubeconform:
stage: lint
image:
name: ghcr.io/yannh/kubeconform:v0.6.6-alpine@sha256:47141997365b1f6aa914b2e801cb9772b94c2696c279e2046a4517d5bfd8a09a
entrypoint: [""]
script:
- apk add curl
- mkdir -p /tmp/flux-crd-schemas/master-standalone
# - curl -sL https://github.com/fluxcd/flux2/releases/latest/download/crd-schemas.tar.gz | tar zxf - -C /tmp/flux-crd-schemas/master-standalone
- /kubeconform
-ignore-missing-schemas
-ignore-filename-pattern ".sops.yaml"
-schema-location default
-schema-location /tmp/flux-crd-schemas
-output junit
manifests/ > junit.xml || true
- /kubeconform
-ignore-missing-schemas
-verbose
-summary
-ignore-filename-pattern ".sops.yaml"
-schema-location /tmp/flux-crd-schemas
-output pretty
manifests/
artifacts:
paths:
- junit.xml
reports:
junit:
- junit.xml
rules:
- changes:
- manifests/**/*
- .gitlab-ci.yml
lint-kubeconform-strict:
stage: lint
image:
name: ghcr.io/yannh/kubeconform:v0.6.6-alpine@sha256:47141997365b1f6aa914b2e801cb9772b94c2696c279e2046a4517d5bfd8a09a
entrypoint: [""]
script:
- apk add curl
- mkdir -p /tmp/flux-crd-schemas/master-standalone-strict
# - curl -sL https://github.com/fluxcd/flux2/releases/latest/download/crd-schemas.tar.gz | tar zxf - -C /tmp/flux-crd-schemas/master-standalone-strict
# Skip Secrets in strict mode because of SOPS
- /kubeconform
-skip=Secret
-strict
-ignore-missing-schemas
-ignore-filename-pattern ".sops.yaml"
-schema-location /tmp/flux-crd-schemas
-output junit
manifests/ > junit-strict.xml || true
- /kubeconform
-skip=Secret
-strict
-ignore-missing-schemas
-verbose
-summary
-ignore-filename-pattern ".sops.yaml"
-schema-location /tmp/flux-crd-schemas
-output pretty
manifests/
artifacts:
paths:
- junit-strict.xml
reports:
junit:
- junit-strict.xml
rules:
- changes:
- manifests/**/*
- .gitlab-ci.yml
.build:
interruptible: true
image:
name: gcr.io/kaniko-project/executor:v1.21.1-debug@sha256:0818d281f155b9bb1b1f0704e55939b9c440b0155cbbf65b567ca19e19e20223
entrypoint: [""]
# parallel:
# matrix: !reference [.projects, matrix]
variables:
CONTEXT: src/$PROJECT
DOCKERFILE: src/$PROJECT/Dockerfile
IMAGE_NAME: $PROJECT
IMAGE_TAG: $CI_COMMIT_SHA
TARGET_STAGE: ""
script:
- /kaniko/executor
--context "$CI_PROJECT_DIR/${CONTEXT}"
--dockerfile "${DOCKERFILE}"
--cache=true --cache-copy-layers=true --cache-ttl=24h
--destination "$CI_REGISTRY_IMAGE/${IMAGE_NAME}:${IMAGE_TAG}"
--push-retry=5
--target "$TARGET_STAGE"
--image-name-tag-with-digest-file "digests/digest-$PROJECT.txt"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_EVENT_TYPE == 'merge_train'
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- changes:
- src/$PROJECT/**/*
- .gitlab-ci.yml
.test:
stage: test
image:
name: ${CI_REGISTRY_IMAGE}/$PROJECT:${CI_COMMIT_SHA}-dev
entrypoint: [""]
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_EVENT_TYPE == 'merge_train'
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- changes:
- src/$PROJECT/**/*
- .gitlab-ci.yml
lymphocyte:dev-build:
extends: .build
stage: build-dev
variables:
PROJECT: lymphocyte
IMAGE_TAG: $CI_COMMIT_SHA-dev
TARGET_STAGE: dev
lymphocyte:mypy:
extends: .test
needs: [lymphocyte:dev-build]
variables:
PROJECT: lymphocyte
script:
- cd src/lymphocyte
- mypy .
--no-install-types
--junit-xml reports/junit.xml
--junit-format per_file
--any-exprs-report reports
--txt-report reports
--cobertura-xml-report reports
- cat reports/index.txt
- cat reports/any-exprs.txt
- cat reports/types-of-anys.txt
- grep 'Total' reports/any-exprs.txt | sed 's/.* \([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)%.*$/mypy_expression_coverage_percentage \1/' >> reports/metrics.txt
- grep 'Total' reports/index.txt | sed 's/.* \([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)%.*$/mypy_imprecise_percentage \1/' >> reports/metrics.txt
- grep '<coverage' reports/cobertura.xml | sed 's/.*line-rate="\([^" ]*\)".*$/mypy_line_rate \1/' >> reports/metrics.txt
artifacts:
paths:
- "src/lymphocyte/reports/*"
reports:
junit: src/lymphocyte/reports/junit.xml
metrics: src/lymphocyte/reports/metrics.txt
lymphocyte:pylint:
extends: .test
needs: [lymphocyte:dev-build]
variables:
PROJECT: lymphocyte
script:
- pylint src/lymphocyte/**/*.py
--rcfile src/lymphocyte/pyproject.toml
--output-format colorized
lymphocyte:bandit:
extends: .test
needs: [lymphocyte:dev-build]
variables:
PROJECT: lymphocyte
script:
- bandit -c src/lymphocyte/pyproject.toml -r src/lymphocyte/
lymphocyte:pylic:
extends: .test
needs: [lymphocyte:dev-build]
variables:
PROJECT: lymphocyte
script:
- cd src/lymphocyte
- pylic check
lymphocyte:pylint-strict:
extends: .test
needs: [lymphocyte:dev-build]
allow_failure: true
variables:
PROJECT: lymphocyte
script:
- set -o pipefail
- pylint src/lymphocyte/**/*.py
--rcfile src/lymphocyte/pyproject.toml
--output-format colorized
--fail-under 7.1
--report y
--enable=all | tee >(grep 'Your' | sed 's|Your code has been rated at \([^/]*\).*$|pylint_rating \1|' >> metrics.txt)
artifacts:
reports:
metrics: metrics.txt
lymphocyte:test-coverage:
extends: .test
needs: [lymphocyte:dev-build]
variables:
PROJECT: lymphocyte
script:
- pytest
--cov=lymphocyte
--cov-report term
--cov-report "xml:cobertura.xml"
--junitxml junit.xml
src/lymphocyte
coverage: '/^TOTAL.*\s+(\d+\%)$/'
artifacts:
reports:
junit: junit.xml
coverage_report:
coverage_format: cobertura
path: cobertura.xml
lymphocyte:build:
extends: .build
stage: build
variables:
PROJECT: lymphocyte
TARGET_STAGE: prod
artifacts:
paths:
- "digests/digest-$PROJECT.txt"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_EVENT_TYPE == 'merge_train'
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
testapp:build:
extends: .build
stage: build
variables:
PROJECT: testapp
TARGET_STAGE: ""
artifacts:
paths:
- "digests/digest-$PROJECT.txt"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_EVENT_TYPE == 'merge_train'
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
scenario-tester:build:
extends: .build
stage: build
variables:
PROJECT: scenario-tester
TARGET_STAGE: ""
artifacts:
paths:
- "digests/digest-$PROJECT.txt"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_EVENT_TYPE == 'merge_train'
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
package:
stage: deploy
interruptible: true
image:
name: alpine:3.21.2@sha256:56fa17d2a7e7f168a043a2712e63aed1f8543aeafdcee47c58dcffe38ed51099
entrypoint: [""]
variables:
IMAGE_NAME: $CI_REGISTRY_IMAGE
IMAGE_TAG: $CI_COMMIT_SHA
script:
- ls digests/ || true
- wget https://github.com/fluxcd/flux2/releases/download/v2.4.0/flux_2.4.0_linux_amd64.tar.gz
- echo "7b70b75af20e28fc30ee66cf5372ec8d51dd466fd2ee21aa42690984de70b09b flux_2.4.0_linux_amd64.tar.gz" | sha256sum -c
- tar -xzvf flux_2.4.0_linux_amd64.tar.gz flux
- install flux /usr/local/bin/flux && rm flux
- wget https://dl.k8s.io/release/v1.32.0/bin/linux/amd64/kubectl
- echo "646d58f6d98ee670a71d9cdffbf6625aeea2849d567f214bc43a35f8ccb7bf70 kubectl" | sha256sum -c
- install kubectl /usr/local/bin/kubectl && rm kubectl
- wget https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.4.2/kustomize_v5.4.2_linux_amd64.tar.gz
- echo "881c6e9007c7ea2b9ecc214d13f4cdd1f837635dcf4db49ce4479898f7d911a3 kustomize_v5.4.2_linux_amd64.tar.gz" | sha256sum -c
- tar -xzvf kustomize_v5.4.2_linux_amd64.tar.gz kustomize
- install kustomize /usr/local/bin/kustomize && rm kustomize
- for filename in digests/digest-*.txt; do
if [[ ! -r "$filename" ]]; then
continue;
fi;
echo "$filename";
cat "$filename";
image="$(cat "$filename" )";
(cd manifests; kustomize edit set image "$image");
done
- mkdir -p kustomize-out
- kubectl kustomize ./manifests --output ./kustomize-out
- CLEANED_REPOSITORY_URL="$(echo $CI_REPOSITORY_URL | sed 's|\(.*://\).*@\(.*\)|\1\2|' )"
- echo $CLEANED_REPOSITORY_URL
# Stop here, don't push if it is not the default branch.
- if [[ "$CI_COMMIT_BRANCH" != "$CI_DEFAULT_BRANCH" ]]; then exit 0; fi
- flux push artifact oci://$CI_REGISTRY_IMAGE/manifests:$CI_COMMIT_SHA
--path="./manifests"
--source="$CLEANED_REPOSITORY_URL"
--revision="$CI_COMMIT_SHORT_SHA"
--creds="$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD"
--annotations="org.opencontainers.image.url=$CI_PROJECT_URL"
--annotations="org.opencontainers.image.title=$CI_PROJECT_NAME"
--annotations="com.gitlab.job.id=$CI_JOB_ID"
--annotations="com.gitlab.job.url=$CI_JOB_URL"
--output=json
- |
flux tag artifact oci://$CI_REGISTRY_IMAGE/manifests:$CI_COMMIT_SHA \
--creds="$CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD" \
--tag latest
artifacts:
paths:
- "kustomize-out/"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_EVENT_TYPE == 'merge_train'
exists:
- manifests/kustomization.yaml
changes:
- manifests/*
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
exists:
- manifests/kustomization.yaml
pages:
stage: deploy
image:
name: ${CI_REGISTRY_IMAGE}/$PROJECT:${CI_COMMIT_SHA}-dev
entrypoint: [""]
script:
- pdoc src/lymphocyte -o public
variables:
PROJECT: lymphocyte
artifacts:
paths:
- "public"
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
environment:
name: Production
url: "$CI_PAGES_URL"
pages-dev:
stage: deploy
image:
name: ${CI_REGISTRY_IMAGE}/$PROJECT:${CI_COMMIT_SHA}-dev
entrypoint: [""]
script:
- pdoc src/lymphocyte -o public
variables:
PROJECT: lymphocyte
artifacts:
paths:
- "public"
environment:
name: Develop
url: "$CI_JOB_URL/artifacts/file/public/index.html"
rules:
# Same rules as the building of lympho-dev
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_EVENT_TYPE == 'merge_train'
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
changes:
- src/$PROJECT/**/*
- .gitlab-ci.yml