forked from nomad-coe/nomad
-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
450 lines (423 loc) · 15.6 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
# default installed image for docker executor is: python:3.6
# using an image that can do git, docker, docker-compose
image: gitlab-registry.mpcdf.mpg.de/nomad-lab/nomad-fair/ci-runner:latest
# build directory inside
# https://gitlab.mpcdf.mpg.de/help/ci/runners/configure_runners.md#custom-build-directories
# https://docs.gitlab.com/ee/ci/yaml/workflow.html
# https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
# if: CI_COMMIT_BRANCH && CI_COMMIT_BEFORE_SHA == "0000000000000000000000000000000000000000"
# A branch pipeline, but it is the first commit for that branch
# if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
# For an existing workflow section to switch from branch pipelines to merge request pipelines when a merge request is created.
# if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
# A branch pipeline, but a merge request is open for that branch, do not run the branch pipeline.
# if: $CI_PIPELINE_SOURCE == "merge_request_event"
# A merge request pipeline, start the pipeline.
# if: $CI_COMMIT_BRANCH
# A branch pipeline, but there is no merge request open for the branch, run the branch pipeline.
default:
tags:
# Necessary to select the right CI runner
- cloud
variables:
DOCKER_TAG: ${CI_COMMIT_REF_SLUG}
DOCKER_HOST: tcp://docker-dind:2375
DOCKER_TLS_CERTDIR: ""
workflow:
rules:
- if: $CI_COMMIT_BRANCH && $CI_COMMIT_BEFORE_SHA == "0000000000000000000000000000000000000000"
when: never
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
when: never
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_COMMIT_BRANCH
- if: $CI_COMMIT_TAG
variables:
DOCKER_TAG: ${CI_COMMIT_REF_NAME}
- when: never
stages:
- build
- test
- deploy
- release
update changelog:
stage: build
script:
- curl -X POST "https://gitlab.mpcdf.mpg.de/api/v4/projects/$CI_PROJECT_ID/repository/changelog?version=${CI_COMMIT_TAG:1}&access_token=$CI_ACCESS_TOKEN&message=Add%20changelog%20for%20version%20$CI_COMMIT_TAG%20%5Bskip-ci%5D"
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/
build:
stage: build
variables:
GIT_SUBMODULE_STRATEGY: recursive
GIT_SUBMODULE_UPDATE_FLAGS: --jobs 4
DOCKER_BUILDKIT: 1
before_script:
- docker --version
- echo "${CI_REGISTRY_PASSWORD}" | docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password-stdin
- pip install --upgrade setuptools_scm
- export SETUPTOOLS_SCM_PRETEND_VERSION=$(python -m setuptools_scm)
- echo "SETUPTOOLS_SCM_PRETEND_VERSION=$SETUPTOOLS_SCM_PRETEND_VERSION"
script:
- docker build --build-arg SETUPTOOLS_SCM_PRETEND_VERSION -t ${CI_REGISTRY_IMAGE}:${DOCKER_TAG} .
- docker build --build-arg SETUPTOOLS_SCM_PRETEND_VERSION --target dev_node -t ${CI_REGISTRY_IMAGE}/dev_node:${DOCKER_TAG} .
- docker build --build-arg SETUPTOOLS_SCM_PRETEND_VERSION --target dev_python -t ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG} .
- docker push ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
- docker push ${CI_REGISTRY_IMAGE}/dev_node:${DOCKER_TAG}
- docker push ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
after_script:
- docker run --rm ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG} bash -c 'cat dist/`ls dist`' > nomad-lab.tar.gz
- docker run --rm ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG} cat tests/data/parsers/vasp/vasp.xml > vasp.xml
artifacts:
paths:
- nomad-lab.tar.gz
- vasp.xml
expire_in: 1 hour
rules:
- when: on_success
build helm chart:
stage: build
script:
- helm package -u ops/kubernetes/nomad -d ops/kubernetes
- 'curl --request POST --user gitlab-ci-token:$CI_JOB_TOKEN --form "chart=@ops/kubernetes/nomad-1.0.0.tgz" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/latest/charts"'
python linting:
stage: test
image: ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
variables:
GIT_STRATEGY: none
before_script:
- cd /app
script:
- ruff nomad tests
- ruff format nomad tests --check
- ruff nomad tests --output-format gitlab > $CI_PROJECT_DIR/gl-code-quality-report.json
- mypy nomad tests
rules:
- if: $CI_COMMIT_TAG
when: never
- when: on_success
artifacts:
name: "nomad_code_quality"
when: always
reports:
codequality: gl-code-quality-report.json
expire_in: never
gui linting:
stage: test
image: ${CI_REGISTRY_IMAGE}/dev_node:${DOCKER_TAG}
variables:
GIT_STRATEGY: none
before_script:
- cd /app/gui
script:
- yarn run lint
rules:
- if: $CI_COMMIT_TAG
when: never
- when: on_success
check python dependencies:
stage: test
image: python:3.9
variables:
GIT_SUBMODULE_STRATEGY: recursive
GIT_SUBMODULE_UPDATE_FLAGS: --jobs 4
before_script:
- pip install --upgrade pip-tools
script:
- scripts/check_python_dependencies.sh
rules:
- if: $CI_COMMIT_TAG
when: never
- when: manual
allow_failure: true
check gui artifacts:
stage: test
image: ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
variables:
GIT_STRATEGY: none
before_script:
- cd /app
script:
- scripts/check_gui_artifacts.sh
after_script:
- >
if [ $CI_JOB_STATUS == 'failed' ]; then
echo 'Make sure that the right GUI artifacts have been regenerated and committed by running'
echo './scripts/generate_gui_artifacts.sh'
fi
rules:
- if: $CI_COMMIT_TAG
when: never
- when: on_success
python tests:
stage: test
image: ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
services:
- name: rabbitmq:3.11.5
alias: rabbitmq
- name: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
alias: elastic
command:
- bash
- "-c"
- ES_JAVA_OPTS="-Xms512m -Xmx512m" docker-entrypoint.sh elasticsearch -Ediscovery.type=single-node -Expack.security.enabled=false
- name: mongo:5.0.6
alias: mongo
variables:
GIT_STRATEGY: none
RABBITMQ_ERLANG_COOKIE: SWQOKODSQALRPCLNMEQG
RABBITMQ_DEFAULT_USER: rabbitmq
RABBITMQ_DEFAULT_PASS: rabbitmq
RABBITMQ_DEFAULT_VHOST: /
NOMAD_RABBITMQ_HOST: rabbitmq
NOMAD_ELASTIC_HOST: elastic
NOMAD_MONGO_HOST: mongo
NOMAD_KEYCLOAK_PASSWORD: ${CI_KEYCLOAK_ADMIN_PASSWORD}
NOMAD_NORMALIZE_SPRINGER_DB_PATH: /nomad/fairdi/db/data/springer.msg
before_script:
- cd /app
- scripts/check_elastic.sh
script:
- python -m pytest --cov=nomad --cov-report term --cov-report xml:coverage.xml --cov-config=.coveragerc -sv tests
after_script:
- cd /app
- cp coverage.xml $CI_PROJECT_DIR
coverage: /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/
artifacts:
when: always
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
rules:
- if: $CI_COMMIT_TAG
when: never
- when: on_success
install tests:
stage: test
image: python:3.9
script:
- pip install --upgrade pip
- pip install nomad-lab.tar.gz
- python -c 'import nomad.cli'
- python -c 'from nomad.client import ArchiveQuery'
- python -m nomad.cli parse vasp.xml
- pip install git+https://github.com/nomad-coe/nomad-parser-example.git
- python -m exampleparser tests/data/examples/example.out
gui tests:
stage: test
image: ${CI_REGISTRY_IMAGE}/dev_node:${DOCKER_TAG}
variables:
GIT_STRATEGY: none
before_script:
- cd /app/gui
script:
- yarn test --ci --collectCoverage --reporters=default --reporters=jest-junit --silent
--testPathIgnorePatterns=src/components/entry/ArchiveEntryView.spec.js
--testPathIgnorePatterns=src/components/archive/FileBrowser.spec.js
--testPathIgnorePatterns=src/components/archive/MetainfoBrowser.spec.js
after_script:
- cd /app/gui
- cp junit.xml $CI_PROJECT_DIR
- cp coverage/cobertura-coverage.xml $CI_PROJECT_DIR
timeout: 1h 30m
coverage: /Lines\s*:\s*(\d+.?\d*)%/
artifacts:
when: always
reports:
junit:
- junit.xml
coverage_report:
coverage_format: cobertura
path: cobertura-coverage.xml
rules:
- if: $CI_COMMIT_TAG
when: never
- when: on_success
deploy prod:
stage: deploy
environment:
name: staging
deployment_tier: production
url: https://nomad-lab.eu/prod/v1
before_script:
- mkdir ~/.kube/
- echo ${CI_K8S_CLOUD_CONFIG} | base64 -d > ~/.kube/config
- echo "${CI_REGISTRY_PASSWORD}" | docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password-stdin
script:
- docker pull ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
- docker tag ${CI_REGISTRY_IMAGE}:${DOCKER_TAG} ${CI_REGISTRY_IMAGE}:prod
- docker push ${CI_REGISTRY_IMAGE}:prod
- helm dependency update ops/kubernetes/nomad
- helm upgrade nomad-prod ops/kubernetes/nomad
--install
--namespace nomad-prod
--values ops/kubernetes/values.yaml
--values ops/kubernetes/nomad-prod.yaml
--set nomad.image.tag=prod
--set roll=true
--timeout=15m
--wait
- docker pull ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
- docker run -t -e NOMAD_KEYCLOAK_REALM_NAME=fairdi_nomad_prod -e NOMAD_KEYCLOAK_SERVER_URL=https://nomad-lab.eu/fairdi/keycloak/auth/ ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
nomad client -n https://nomad-lab.eu/prod/v1/api -u test -w $CI_NOMAD_TEST_PASSWORD integrationtests --skip-publish --skip-doi
rules:
- when: manual
allow_failure: true
deploy prod staging:
stage: deploy
environment:
name: staging
deployment_tier: production
url: https://nomad-lab.eu/prod/v1/staging
before_script:
- mkdir ~/.kube/
- echo ${CI_K8S_CLOUD_CONFIG} | base64 -d > ~/.kube/config
- echo "${CI_REGISTRY_PASSWORD}" | docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password-stdin
script:
- docker pull ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
- docker tag ${CI_REGISTRY_IMAGE}:${DOCKER_TAG} ${CI_REGISTRY_IMAGE}:staging
- docker push ${CI_REGISTRY_IMAGE}:staging
- helm dependency update ops/kubernetes/nomad
- helm upgrade nomad-prod-staging ops/kubernetes/nomad
--install
--namespace nomad-prod-staging
--values ops/kubernetes/values.yaml
--values ops/kubernetes/nomad-prod-staging.yaml
--set nomad.image.tag=staging
--set roll=true
--timeout=15m
--wait
- docker pull ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
- docker run -t -e NOMAD_KEYCLOAK_REALM_NAME=fairdi_nomad_prod -e NOMAD_KEYCLOAK_SERVER_URL=https://nomad-lab.eu/fairdi/keycloak/auth/ ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
nomad client -n https://nomad-lab.eu/prod/v1/staging/api -u test -w $CI_NOMAD_TEST_PASSWORD integrationtests --skip-publish --skip-doi
rules:
- when: manual
allow_failure: true
deploy prod develop:
stage: deploy
environment:
name: develop
deployment_tier: production
url: https://nomad-lab.eu/prod/v1/develop
before_script:
- mkdir ~/.kube/
- echo ${CI_K8S_CLOUD_CONFIG} | base64 -d > ~/.kube/config
- echo "${CI_REGISTRY_PASSWORD}" | docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password-stdin
script:
- docker pull ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
- docker tag ${CI_REGISTRY_IMAGE}:${DOCKER_TAG} ${CI_REGISTRY_IMAGE}:develop
- docker push ${CI_REGISTRY_IMAGE}:develop
- helm dependency update ops/kubernetes/nomad
- helm upgrade nomad-prod-develop ops/kubernetes/nomad
--install
--namespace nomad-prod-develop
--values ops/kubernetes/values.yaml
--values ops/kubernetes/nomad-prod-develop.yaml
--set nomad.image.tag=develop
--set roll=true
--timeout=15m
--wait
- docker pull ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
- docker run -t -e NOMAD_KEYCLOAK_REALM_NAME=fairdi_nomad_prod -e NOMAD_KEYCLOAK_SERVER_URL=https://nomad-lab.eu/fairdi/keycloak/auth/ ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
nomad client -n https://nomad-lab.eu/prod/v1/develop/api -u test -w $CI_NOMAD_TEST_PASSWORD integrationtests --skip-publish --skip-doi
rules:
- if: $CI_COMMIT_BRANCH == "develop" && $NIGHTLY
- when: manual
allow_failure: true
deploy prod test:
stage: deploy
environment:
name: test
deployment_tier: production
url: https://nomad-lab.eu/prod/v1/test
before_script:
- mkdir ~/.kube/
- echo ${CI_K8S_CLOUD_CONFIG} | base64 -d > ~/.kube/config
- echo "${CI_REGISTRY_PASSWORD}" | docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password-stdin
script:
- docker pull ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
- docker tag ${CI_REGISTRY_IMAGE}:${DOCKER_TAG} ${CI_REGISTRY_IMAGE}:test
- docker push ${CI_REGISTRY_IMAGE}:test
- helm dependency update ops/kubernetes/nomad
- helm upgrade nomad-prod-test ops/kubernetes/nomad
--install
--namespace nomad-prod-test
--values ops/kubernetes/values.yaml
--values ops/kubernetes/nomad-prod-test.yaml
--set nomad.image.tag=test
--set roll=true
--timeout=15m
--wait
- docker pull ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
- docker run -t -e NOMAD_KEYCLOAK_REALM_NAME=fairdi_nomad_prod -e NOMAD_KEYCLOAK_SERVER_URL=https://nomad-lab.eu/fairdi/keycloak/auth/ ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
nomad client -n https://nomad-lab.eu/prod/v1/test/api -u test -w $CI_NOMAD_TEST_PASSWORD integrationtests --skip-publish --skip-doi
rules:
- when: manual
allow_failure: true
release latest image:
stage: release
variables:
GIT_STRATEGY: none
before_script:
- echo "${CI_REGISTRY_PASSWORD}" | docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password-stdin
- docker pull ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
script:
- docker tag ${CI_REGISTRY_IMAGE}:${DOCKER_TAG} ${CI_REGISTRY_IMAGE}:latest
- docker push ${CI_REGISTRY_IMAGE}:latest
rules:
- when: manual
allow_failure: true
release stable image:
stage: release
variables:
GIT_STRATEGY: none
before_script:
- echo "${CI_REGISTRY_PASSWORD}" | docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password-stdin
- docker pull ${CI_REGISTRY_IMAGE}:${DOCKER_TAG}
script:
- docker tag ${CI_REGISTRY_IMAGE}:${DOCKER_TAG} ${CI_REGISTRY_IMAGE}:stable
- docker push ${CI_REGISTRY_IMAGE}:stable
rules:
- if: $CI_COMMIT_TAG
when: manual
allow_failure: true
- when: never
python package:
stage: release
variables:
GIT_STRATEGY: none
before_script:
- echo "${CI_REGISTRY_PASSWORD}" | docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password-stdin
- docker pull ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
script:
- docker run --rm ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
twine upload -u gitlab-ci-token -p ${CI_JOB_TOKEN} --repository-url https://gitlab.mpcdf.mpg.de/api/v4/projects/${CI_PROJECT_ID}/packages/pypi dist/nomad-lab-*.tar.gz
rules:
- when: manual
allow_failure: true
pypi package:
stage: release
variables:
GIT_STRATEGY: none
before_script:
- echo "${CI_REGISTRY_PASSWORD}" | docker login ${CI_REGISTRY} --username ${CI_REGISTRY_USER} --password-stdin
- docker pull ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
script:
- docker run --rm ${CI_REGISTRY_IMAGE}/dev_python:${DOCKER_TAG}
twine upload -u $CI_TWINE_USER -p $CI_TWINE_PASSWORD dist/nomad-lab-*.tar.gz
rules:
- if: $CI_COMMIT_TAG
when: manual
allow_failure: true
- when: never
push to github:
stage: release
script:
- git checkout ${CI_COMMIT_REF_NAME}
- git push "https://${CI_GITHUB_ACCESS_TOKEN}@github.com/nomad-coe/nomad.git" ${CI_COMMIT_REF_NAME}
rules:
- if: $CI_COMMIT_BRANCH == "develop" || $CI_COMMIT_TAG