forked from heliocloud-data/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
362 lines (345 loc) · 13.9 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
default:
image: python:3.9
services:
- docker:20.10.23-dind
variables:
# When using dind service, you must instruct Docker to talk with
# the daemon started inside of the service. The daemon is available
# with a network connection instead of the default
# /var/run/docker.sock socket.
DOCKER_HOST: tcp://docker:2376
#
# The 'docker' hostname is the alias of the service container as described at
# https://docs.gitlab.com/ee/ci/services/#accessing-the-services.
# If you're using GitLab Runner 12.7 or earlier with the Kubernetes executor and Kubernetes 1.6 or earlier,
# the variable must be set to tcp://localhost:2376 because of how the
# Kubernetes executor connects services to the job container
# DOCKER_HOST: tcp://localhost:2376
#
# Specify to Docker where to create the certificates. Docker
# creates them automatically on boot, and creates
# `/certs/client` to share between the service and job
# container, thanks to volume mount from config.toml
DOCKER_TLS_CERTDIR: "/certs"
# These are usually specified by the entrypoint, however the
# Kubernetes executor doesn't run entrypoints
# https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4125
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
stages:
- test
- integration
- staging
- deploy
# At the momemnt, there are a subset of unit tests that require nodejs
# to be installed.
unit-test:
stage: test
before_script:
- mkdir -p public/badges
script:
- export PYTHONPATH=.
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
- bash .gitlab-ci/scripts/install-deps.sh
- curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh && bash get_helm.sh -v v3.9.4 && rm -rf get_helm.sh
- curl https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.1.1/kustomize_v5.1.1_linux_amd64.tar.gz --silent --location --remote-name && tar zxvf kustomize_v5.1.1_linux_amd64.tar.gz && mv kustomize /usr/local/bin/ && rm -rf kustomize_v5.1.1_linux_amd64.tar.gz
- pytest -c pytest-unit.ini --junit-xml=TEST-HelioCloud-platform.xml --junit-prefix=HelioCloud-platform
artifacts:
when: always
paths:
- TEST-HelioCloud-platform.xml
reports:
junit: TEST-HelioCloud-platform.xml
# See
# * https://docs.gitlab.com/ee/ci/testing/test_coverage_visualization.html
coverage:
stage: test
script:
- export PYTHONPATH=.
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
- bash .gitlab-ci/scripts/install-deps.sh
- curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh && bash get_helm.sh -v v3.9.4 && rm -rf get_helm.sh
- curl https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.1.1/kustomize_v5.1.1_linux_amd64.tar.gz --silent --location --remote-name && tar zxvf kustomize_v5.1.1_linux_amd64.tar.gz && mv kustomize /usr/local/bin/ && rm -rf kustomize_v5.1.1_linux_amd64.tar.gz
- coverage run -m pytest -c pytest-unit.ini
- coverage report
- coverage xml
- coverage html
coverage: '/(?i)TOTAL.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
when: always
paths:
- coverage.xml
- htmlcov
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
# For static-analysis, we're going to run the analysis once for badge generation
# and once for generating the codeclimate report, which is required integration
# with the gitlab pull request.
#
# This configuration only runs pylint on the main source files of the project,
# it excludes the unit and integration test folders as well as the cdk output
# build folder.
#
# See:
# * https://pypi.org/project/pylint-gitlab/
static-analysis:
stage: test
variables:
PYLINT_TEXT_OUTPUT_FILE: 'pylint.txt'
PYLINT_SCORE_OUTPUT_FILE: public/pylint.score
PYLINT_BADGE_OUTPUT_FILE: 'public/pylint.svg'
CODE_CLIMATE_OUTPUT_FILE: 'codeclimate.json'
before_script:
- mkdir -p public
script:
- export PYTHONPATH=.
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
- pylint --exit-zero --output-format=text $(find -type f -name "*.py" ! -path "**/.venv/**" | grep -v '/test/' | grep -v '/cdk.out/') | tee ${PYLINT_TEXT_OUTPUT_FILE}
- sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ${PYLINT_TEXT_OUTPUT_FILE} > ${PYLINT_SCORE_OUTPUT_FILE}
- anybadge --value=$(cat ${PYLINT_SCORE_OUTPUT_FILE}) --file=${PYLINT_BADGE_OUTPUT_FILE} pylint
- pylint --exit-zero --load-plugins=pylint_gitlab --output-format=gitlab-codeclimate $(find -type f -name "*.py" ! -path "**/.venv/**" | grep -v '/test/' | grep -v '/cdk.out/') > ${CODE_CLIMATE_OUTPUT_FILE}
artifacts:
when: always
paths:
- ${CODE_CLIMATE_OUTPUT_FILE}
- ${PYLINT_TEXT_OUTPUT_FILE}
- ${PYLINT_SCORE_OUTPUT_FILE}
- ${PYLINT_BADGE_OUTPUT_FILE}
reports:
codequality: ${CODE_CLIMATE_OUTPUT_FILE}
black:
stage: test
script:
- export PYTHONPATH=.
- python -m pip install -r requirements-dev.txt
- black --check .
# The integration stage will deploy parts of the heliocloud system and test
# it using the "black-box" interface of the system component under test. In
# the current configuration, the environment is retained between runs.
#
# These jobs presume valid AWS variables are set, specifically:
# * AWS_ACCESS_KEY_ID
# * AWS_SECRET_ACCESS_KEY
# * AWS_DEFAULT_REGION
#
# All jobs executing at this stage will create per-branch environments in
# GitLab by using the CI_COMMIT_REF_SLUG environment variable.
#
# Per-commit environments are also possible using the CI_COMMIT_SHORT_SHA
# environment variable.
#
# See:
# https://docs.gitlab.com/ee/ci/environments/
# https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
integration-cdk-deploy:
stage: integration
tags:
- dind # set to run on specific runer
environment:
name: testing/$CI_COMMIT_REF_SLUG
url: https://portal-${CI_COMMIT_REF_SLUG}.aplscicloud.org
on_stop: integration-cdk-destroy-on_stop_hook
auto_stop_in: 8 hours
script:
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
- bash .gitlab-ci/scripts/install-deps.sh
- npm install -g npm
- npm install -g aws-cdk
- cdk --version
# Dependencies for Portal
- curl -sSL https://get.docker.com/ | sh
- apt-get update && apt-get install -y gettext
- envsubst < instance/gitlab-integration.yaml > instance/gitlab-integration-${CI_COMMIT_REF_SLUG}.yaml
# Modify the cdk.json file to run in coverage mode.
- cdk --app "coverage run app.py" deploy --all -c instance=gitlab-integration-${CI_COMMIT_REF_SLUG} --require-approval never -v
artifacts:
when: always
paths:
- instance/gitlab-integration-${CI_COMMIT_REF_SLUG}.yaml
integration-test:
stage: integration
environment:
name: testing/$CI_COMMIT_REF_SLUG
action: verify
script:
- export PYTHONPATH=.:test/integration
- export HC_INSTANCE=gitlab-integration-${CI_COMMIT_REF_SLUG}
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
- apt-get update && apt-get install -y gettext
- envsubst < instance/gitlab-integration.yaml > instance/${HC_INSTANCE}.yaml
- pytest -c pytest-integration.ini --junit-xml=IT-HelioCloud-platform.xml --junit-prefix=IT-HelioCloud-platform
artifacts:
when: always
paths:
- IT-HelioCloud-platform.xml
reports:
junit: IT-HelioCloud-platform.xml
dependencies:
- integration-cdk-deploy
needs: ['integration-cdk-deploy']
integration-cdk-destroy:
stage: integration
environment:
name: testing/$CI_COMMIT_REF_SLUG
action: stop
script:
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
- bash .gitlab-ci/scripts/install-deps.sh
- npm install -g npm
- npm install -g aws-cdk
- cdk --version
- apt-get update && apt-get install -y gettext
# Modify the cdk.json file to run in coverage mode.
- cdk --app "coverage run app.py" destroy --all -c instance=gitlab-integration-${CI_COMMIT_REF_SLUG} --force -v
dependencies:
- integration-cdk-deploy
- integration-test
needs: ['integration-cdk-deploy', 'integration-test']
rules:
- if: $CI_COMMIT_BRANCH == "develop" || $CI_COMMIT_BRANCH == "main"
integration-cdk-destroy-on_stop_hook:
stage: integration
when: manual
environment:
name: testing/$CI_COMMIT_REF_SLUG
action: stop
script:
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
- bash .gitlab-ci/scripts/install-deps.sh
- npm install -g npm
- npm install -g aws-cdk
- cdk --version
- apt-get update && apt-get install -y gettext
# Modify the cdk.json file to run in coverage mode.
- cdk --app "coverage run app.py" destroy --all -c instance=gitlab-integration-${CI_COMMIT_REF_SLUG} --force -v
dependencies:
- integration-cdk-deploy
- integration-test
needs: ['integration-cdk-deploy', 'integration-test']
staging-cdk-deploy:
stage: staging
tags:
- dind # set to run on specific runer
environment:
name: staging
url: https://portal-dev.aplscicloud.org
on_stop: staging-cdk-destroy-on_stop_hook
script:
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
# Dependencies for CDK
- bash .gitlab-ci/scripts/install-deps.sh
- npm install -g npm
- npm install -g aws-cdk
- cdk --version
# Dependencies for Portal
- curl -sSL https://get.docker.com/ | sh
# Dependencies for Daskhub
- curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "session-manager-plugin.deb"
- dpkg -i session-manager-plugin.deb
- apt-get update && apt-get install -y gettext
- envsubst < instance/staging.yaml > instance/staging-${CI_COMMIT_REF_SLUG}.yaml
# For an incremental deployment, we must deploy each stack, but not Daskhub. That one
# has must be done via eksctl/kubect.
- cdk deploy staging-${CI_COMMIT_REF_SLUG}/Base -c instance=staging-${CI_COMMIT_REF_SLUG} --require-approval never -v
- cdk deploy staging-${CI_COMMIT_REF_SLUG}/Identity -c instance=staging-${CI_COMMIT_REF_SLUG} --require-approval never -v
- cdk deploy staging-${CI_COMMIT_REF_SLUG}/Auth -c instance=staging-${CI_COMMIT_REF_SLUG} --require-approval never -v
- cdk deploy staging-${CI_COMMIT_REF_SLUG}/Portal -c instance=staging-${CI_COMMIT_REF_SLUG} --require-approval never -v
- cdk deploy staging-${CI_COMMIT_REF_SLUG}/Registry -c instance=staging-${CI_COMMIT_REF_SLUG} --require-approval never -v
artifacts:
when: always
paths:
- instance/staging-${CI_COMMIT_REF_SLUG}.yaml
rules:
- if: $CI_COMMIT_BRANCH == "develop"
staging-test:
stage: staging
environment:
name: staging
action: verify
script:
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
- 'wget --header="JOB-TOKEN: $CI_JOB_TOKEN" ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/google-chrome/118.0.5993.88/google-chrome-stable_current_amd64.deb'
- apt-get update && apt install -f ./google-chrome-stable_current_amd64.deb -y
- apt-get update && apt-get install -y gettext
- export HC_INSTANCE=staging-${CI_COMMIT_REF_SLUG}
- envsubst < instance/staging.yaml > instance/${HC_INSTANCE}.yaml
- behave --junit
artifacts:
when: always
paths:
- reports/*.xml
- temp/feature-tests/*
reports:
junit: reports/*.xml
dependencies:
- staging-cdk-deploy
needs: ['staging-cdk-deploy']
rules:
- if: $CI_COMMIT_BRANCH == "develop"
staging-cdk-destroy-on_stop_hook:
stage: staging
when: manual
environment:
name: staging
action: stop
script:
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
- bash .gitlab-ci/scripts/install-deps.sh
- npm install -g npm
- npm install -g aws-cdk
- cdk --version
- apt-get update && apt-get install -y gettext
- cdk destroy --all -c instance=staging-${CI_COMMIT_REF_SLUG} --force -v
dependencies:
- staging-cdk-deploy
needs: ['staging-cdk-deploy']
rules:
- if: $CI_COMMIT_BRANCH == "develop"
production-jhuapl-cdk-deploy:
stage: deploy
tags:
- dind # set to run on specific runer
when: manual
environment:
name: production/jhuapl
url: https://portal.aplscicloud.org
script:
- python -m pip install -r requirements.txt
- python -m pip install -r requirements-dev.txt
# Dependencies for CDK
- bash .gitlab-ci/scripts/install-deps.sh
- npm install -g npm
- npm install -g aws-cdk
- cdk --version
# Dependencies for Portal
- curl -sSL https://get.docker.com/ | sh
# Dependencies for Daskhub
- curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "session-manager-plugin.deb"
- dpkg -i session-manager-plugin.deb
- apt-get update && apt-get install -y gettext
- envsubst < instance/production.yaml > instance/production-jhuapl.yaml
# For an incremental deployment, we must deploy each stack, but not Daskhub. That one
# has must be done via eksctl/kubect.
- cdk deploy production-jhuapl/Base -c instance=production-jhuapl --require-approval never -v
- cdk deploy production-jhuapl/Identity -c instance=production-jhuapl --require-approval never -v
- cdk deploy production-jhuapl/Auth -c instance=production-jhuapl --require-approval never -v
- cdk deploy production-jhuapl/Portal -c instance=production-jhuapl --require-approval never -v
- cdk deploy production-jhuapl/Registry -c instance=production-jhuapl --require-approval never -v
artifacts:
when: always
paths:
- instance/production-jhuapl.yaml
rules:
- if: $CI_COMMIT_BRANCH == "develop"