forked from waldur/waldur-homeport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
395 lines (375 loc) · 12.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
include:
- project: "waldur/waldur-pipelines"
file: "/templates/stages.yml"
- project: "waldur/waldur-pipelines"
file: "/templates/release/publish.yml"
- project: "waldur/waldur-pipelines"
file: "/templates/validate/docker-compose-trigger.yml"
- project: "waldur/waldur-pipelines"
file: "/templates/test/lint-docker-image.yaml"
- project: "waldur/waldur-pipelines"
file: "/templates/test/lint-dockerfile.yaml"
- project: "waldur/waldur-pipelines"
file: "/templates/test/lint-md-files.yml"
- project: "waldur/waldur-pipelines"
file: "/templates/deploy/dev-env-update.yml"
variables:
COMPONENT_VERSION: "latest"
image: registry.hpc.ut.ee/mirror/library/node:lts-alpine
cache:
key: "$CI_COMMIT_REF_NAME"
policy: pull
paths:
- .yarn
- node_modules/
before_script:
- apk add git || echo "Non-Alpine image, skipping"
- yarn config set cache-folder .yarn
- yarn install --frozen-lockfile
Run linters:
stage: test
interruptible: true
rules:
- if: '$SKIP_TESTS == "true" || $SKIP_TESTS == "yes"'
when: never
- if: '$CI_COMMIT_BRANCH == "develop"'
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- src/**/*.css
- src/**/*.scss
- src/**/*.ts
- src/**/*.tsx
- package.json
- yarn.lock
- tsconfig.json
- typings.d.ts
- vite.config.ts
- .eslintrc.cjs
- .eslintignore
script:
- yarn oxlint
- yarn format:check
- yarn tsc -b
- yarn lint:check
- yarn style:check
- yarn deps:unused
- yarn deps:circular
Run code duplication detection:
stage: test
interruptible: true
rules:
- if: '$SKIP_TESTS == "true" || $SKIP_TESTS == "yes"'
when: never
- if: '$CI_COMMIT_BRANCH == "develop"'
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- src/**/*.css
- src/**/*.scss
- src/**/*.ts
- src/**/*.tsx
- .gitlab-ci.yml
script:
- npm install -g jscpd
- npx jscpd src/ --exitCode 1 -r consoleFull --pattern "**/*.scss"
- npx jscpd src/ --exitCode 1 -r consoleFull --pattern "**/*.tsx" -k 250
Run unit tests:
stage: test
interruptible: true
rules:
- if: '$SKIP_TESTS == "true" || $SKIP_TESTS == "yes"'
when: never
- if: '$CI_COMMIT_BRANCH == "develop"'
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- src/**/*.css
- src/**/*.scss
- src/**/*.ts
- src/**/*.tsx
- package.json
- yarn.lock
- tsconfig.json
- typings.d.ts
- vite.config.ts
- test/*
allow_failure: true
script:
- yarn vitest --run --reporter junit --outputFile junit.xml
coverage: /All\sfiles.*?\s+(\d+.\d+)/
artifacts:
when: always
reports:
junit: junit.xml
coverage_report:
coverage_format: cobertura
path: coverage/cobertura-coverage.xml
Run E2E tests:
image:
name: registry.hpc.ut.ee/mirror/cypress/included:13.15.0
entrypoint: [""]
stage: test
interruptible: true
rules:
- if: '$SKIP_TESTS == "true" || $SKIP_TESTS == "yes"'
when: never
- if: '$CI_COMMIT_BRANCH == "develop"'
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
changes:
- src/**/*.css
- src/**/*.scss
- src/**/*.ts
- src/**/*.tsx
- package.json
- yarn.lock
- tsconfig.json
- typings.d.ts
- vite.config.ts
- cypress/**/*
- cypress.config.js
allow_failure: true
script:
- NO_COLOR=1 yarn ci:test
artifacts:
expire_in: 1 week
when: always
paths:
- cypress/screenshots
- cypress/videos
reports:
junit:
- cypress/results/output-*.xml
Build artifact:
stage: build
interruptible: true
rules:
- if: '$SKIP_TESTS == "true" || $SKIP_TESTS == "yes"'
when: never
- if: '$CI_COMMIT_BRANCH == "develop"'
script:
- yarn build
artifacts:
paths:
- dist/
expire_in: 1 week
Publish latest docker image:
script:
- AUTH=$(echo -n "${WALDUR_DOCKER_HUB_USER}:${WALDUR_DOCKER_HUB_PASSWORD}" | base64)
- |
cat << EOF > /kaniko/.docker/config.json
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "${AUTH}"
}
}
}
EOF
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--build-arg="DOCKER_REGISTRY=${DOCKER_REGISTRY}"
--build-arg="COMMIT_INFO=${CI_COMMIT_SHA}"
--build-arg="VERSION=latest"
--destination "opennode/${CI_PROJECT_NAME}:${CI_COMMIT_TAG}"
Publish docker image with specific version:
script:
- AUTH=$(echo -n "${WALDUR_DOCKER_HUB_USER}:${WALDUR_DOCKER_HUB_PASSWORD}" | base64)
- |
cat << EOF > /kaniko/.docker/config.json
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "${AUTH}"
}
}
}
EOF
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--build-arg="DOCKER_REGISTRY=${DOCKER_REGISTRY}"
--build-arg="COMMIT_INFO=${CI_COMMIT_TAG}"
--build-arg="VERSION=$CI_COMMIT_TAG"
--destination "opennode/${CI_PROJECT_NAME}:${CI_COMMIT_TAG}"
Lint docker image:
extends: .Lint docker image template
variables:
IMAGE: opennode/waldur-homeport:latest
DOCKERFILE: Dockerfile
before_script: []
Lint dockerfile:
extends: .Lint dockerfile template
variables:
DOCKERFILE: Dockerfile
HADOLINT_CONFIG: |
ignored:
- DL3018 # "versions for `apk add`" warning
before_script: []
Upload translatable strings:
stage: build
interruptible: true
rules:
- if: '$SKIP_I18N_UPLOAD == "true" || $SKIP_I18N_UPLOAD == "yes"'
when: never
- if: '$CI_COMMIT_BRANCH == "develop"'
image:
name: registry.hpc.ut.ee/mirror/localazy/cli:latest
script:
- sed 's/{\([^}]*\)\}/{__\1__}/g' template.json > template-for-localazy.json
- localazy upload source -w $LOCALAZY_WRITE_KEY -r $LOCALAZY_READ_KEY
before_script: []
Download translation:
stage: test
interruptible: true
rules:
- if: '$CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE == "schedule"'
image:
name: registry.hpc.ut.ee/mirror/localazy/cli:latest
script:
- apt update && apt install -y git jq
- git config --global user.name "$GITLAB_USER_NAME"
- git config --global user.email "$GITLAB_USER_EMAIL"
- git remote set-url origin "https://gitlab-ci-token:${GITLAB_TOKEN}@$CI_SERVER_HOST/$CI_PROJECT_PATH.git"
- git fetch origin develop
- git branch -D new-translations || echo "No translation branch" # cleanup
- localazy download -w $LOCALAZY_WRITE_KEY -r $LOCALAZY_READ_KEY
- find locales -type f -name '*.json' -exec sed -i 's/{__\([^}]*\)__\}/{\1}/g' {} \;
- |
for file in locales/*.json; do
echo $file
if [[ $file == "locales/en.json" ]]; then
continue
fi
jq 'to_entries | map({(.key): .value.message}) | add' "$file" > temp.json && mv temp.json "$file"
done
- rm -f temp.json
- git status
- git add locales/*
- git commit locales -m "Updates translations" || exit 0
- git status
- echo "Committing updated translations"
- git branch new-translations
- git push --set-upstream origin new-translations:develop
before_script: []
Update UI developer docs:
stage: build
interruptible: true
rules:
- if: '$CI_COMMIT_BRANCH == "develop"'
image:
name: registry.hpc.ut.ee/mirror/alpine/git:latest
entrypoint: [""]
script:
- cd /tmp/
- git clone "https://homeport-token:$DOCS_TOKEN@$CI_SERVER_HOST/waldur/waldur-docs.git"
- git config --global user.name "$GITLAB_USER_NAME"
- git config --global user.email "$GITLAB_USER_EMAIL"
- cd waldur-docs
- cp -rv $CI_PROJECT_DIR/docs/* docs/developer-guide/ui
- git add docs/developer-guide/ui
- git commit -m "Update UI developer docs" || exit 0
- git branch new-ui-guide
- git push --set-upstream origin new-ui-guide:master
before_script: []
Build test docker image:
stage: test
interruptible: true
image:
name: "gcr.io/kaniko-project/executor:debug"
entrypoint: [""]
rules:
- if: '$SKIP_TESTS == "true" || $SKIP_TESTS == "yes"'
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
before_script:
- echo "[+] Build and publish docker image for merge request ${CI_MERGE_REQUEST_ID}"
- mkdir build-info
- echo $CI_COMMIT_SHA > build-info/COMMIT_SHA
script:
- echo $CI_REGISTRY_IMAGE:$CI_MERGE_REQUEST_ID
- AUTH=$(echo -n "${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}" | base64)
- |
cat << EOF > /kaniko/.docker/config.json
{
"auths": {
"https://${CI_REGISTRY}": {
"auth": "${AUTH}"
}
}
}
EOF
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--registry-map docker.io=registry.hpc.ut.ee/mirror
--registry-map index.docker.io=registry.hpc.ut.ee/mirror
--build-arg="DOCKER_REGISTRY=${DOCKER_REGISTRY}"
--build-arg="ASSET_PATH=/${CI_MERGE_REQUEST_ID}/"
--destination "${CI_REGISTRY_IMAGE}:${CI_MERGE_REQUEST_ID}"
Test k8s deployment:
stage: validate
image:
name: "registry.hpc.ut.ee/mirror/bitnami/kubectl:1.29.4-debian-12-r2"
entrypoint: ['']
interruptible: false
environment:
name: test-${CI_MERGE_REQUEST_ID}
action: start
on_stop: Cleanup test k8s deployment
url: https://homeport-testing.waldur.com/${CI_MERGE_REQUEST_ID}/
rules:
- if: '$SKIP_TESTS == "true" || $SKIP_TESTS == "yes"'
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
before_script:
- export KUBECONFIG=${K8S_CONFIG_WALDUR_HELM_TEST}
- apt update && apt install gettext -y
script:
- kubectl config current-context
- envsubst < k8s-test/deployment-tpl.yaml > k8s-test/deployment.yaml
- envsubst < k8s-test/service-tpl.yaml > k8s-test/service.yaml
- envsubst < k8s-test/ingress-tpl.yaml > k8s-test/ingress.yaml
- kubectl delete secret waldur-homeport-test-${CI_MERGE_REQUEST_ID} || true
- kubectl create secret docker-registry waldur-homeport-test-${CI_MERGE_REQUEST_ID} --docker-server=${CI_REGISTRY} --docker-username=${CI_REGISTRY_USER} --docker-password=${CI_REGISTRY_PASSWORD}
- kubectl apply -f k8s-test/deployment.yaml --wait
- kubectl apply -f k8s-test/service.yaml
- kubectl apply -f k8s-test/ingress.yaml
- kubectl rollout restart deployment waldur-homeport-test-${CI_MERGE_REQUEST_ID}
# Wait for rollout completion
- kubectl rollout status deployment waldur-homeport-test-${CI_MERGE_REQUEST_ID} --timeout 120s
# Wait a bit more to avoid race conditions
- sleep 5
- kubectl get pods -l app=waldur-homeport-test-${CI_MERGE_REQUEST_ID} --field-selector=status.phase=Running
- POD_NAME=$(kubectl get pod -l app=waldur-homeport-test-${CI_MERGE_REQUEST_ID} --sort-by=.metadata.creationTimestamp -o name | tail -n1)
- echo $POD_NAME
# Wait until the pod is ready to ensure the image is pulled
- kubectl wait --timeout=180s --for=condition=Ready=true $POD_NAME
- kubectl get pods -l app=waldur-homeport-test-${CI_MERGE_REQUEST_ID}
allow_failure: true
Cleanup test k8s deployment:
stage: deploy
image:
name: "registry.hpc.ut.ee/mirror/bitnami/kubectl:1.29.4-debian-12-r2"
entrypoint: ['']
interruptible: false
rules:
- if: '$SKIP_TESTS == "true" || $SKIP_TESTS == "yes"'
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: manual
environment:
name: test-${CI_MERGE_REQUEST_ID}
action: stop
before_script:
- export KUBECONFIG=${K8S_CONFIG_WALDUR_HELM_TEST}
script:
- kubectl delete secret waldur-homeport-test-${CI_MERGE_REQUEST_ID} || true
- kubectl delete deployment waldur-homeport-test-${CI_MERGE_REQUEST_ID} || true
- kubectl delete service waldur-homeport-test-${CI_MERGE_REQUEST_ID} || true
- kubectl delete ingress waldur-homeport-test-${CI_MERGE_REQUEST_ID} || true
Cleanup previous k8s test deployment:
extends: Cleanup test k8s deployment
stage: .pre
rules:
- if: '$SKIP_TESTS == "true" || $SKIP_TESTS == "yes"'
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'