-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path.gitlab-ci.yml
500 lines (456 loc) · 16.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
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
image: node:current-buster
# Run a branch pipeline when a merge request is not open for the branch; otherwise run a merge request pipeline
# https://docs.gitlab.com/ee/ci/yaml/workflow.html#switch-between-branch-pipelines-and-merge-request-pipelines
workflow:
rules:
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
stages:
- build
- dockerize
- test
- mkdocs
- deploy
- postdeploy
cache:
key: ${CI_JOB_NAME}
paths:
- node_modules/
- home/.elm
- home/.npm
- elm-stuff/
build_standalone_container:
stage: dockerize
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [ "" ]
before_script:
- 'sed -i -e "s/instanceConfigMgtRepoUrl:.*/instanceConfigMgtRepoUrl: \"https:\/\/gitlab.com\/${CI_PROJECT_NAMESPACE}\/${CI_PROJECT_NAME}\.git\",/g" environment-configs/docker-config.js'
- 'sed -i -e "s/\"instanceConfigMgtRepoCheckout\":.*/instanceConfigMgtRepoCheckout: \"${CI_COMMIT_SHA}\",/g" environment-configs/docker-config.js'
- 'sed -i -e "s/\"releaseVersion\":.*/\"releaseVersion\":\"${CI_COMMIT_SHA}\",/g" environment-configs/docker-config.js'
- 'sed -i -e "s/\"environmentName\":.*/\"environmentName\":\"ci-docker\"/g" environment-configs/docker-config.js'
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD | base64)\"}}}" > /kaniko/.docker/config.json
- |
TAGLIST="$CI_COMMIT_SHORT_SHA $CI_COMMIT_REF_SLUG"
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then TAGLIST="$TAGLIST latest"; fi
if [[ -n "$TAGLIST" ]]; then
for TAG in $TAGLIST; do
FORMATTEDTAGLIST="${FORMATTEDTAGLIST} --destination $CI_REGISTRY_IMAGE:$TAG ";
done;
fi
DOCKER_FILE="$CI_PROJECT_DIR/docker/standalone.Dockerfile"
/kaniko/executor --context $CI_PROJECT_DIR --dockerfile $DOCKER_FILE $FORMATTEDTAGLIST
.build_with_kaniko:
#Hidden job to use as an "extends" template
stage: dockerize
needs:
- elm_make
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [ "" ]
before_script:
- 'sed -i -e "s/\"instanceConfigMgtRepoUrl\":.*/\"instanceConfigMgtRepoUrl\": \"https:\/\/gitlab.com\/${CI_PROJECT_NAMESPACE}\/${CI_PROJECT_NAME}\.git\",/g" public/config.js'
- 'sed -i -e "s/\"instanceConfigMgtRepoCheckout\":.*/\"instanceConfigMgtRepoCheckout\": \"${CI_COMMIT_SHA}\",/g" public/config.js'
- 'sed -i -e "s/\"releaseVersion\":.*/\"releaseVersion\":\"${CI_COMMIT_SHA}\",/g" public/config.js'
- 'sed -i -e "s/\"environmentName\":.*/\"environmentName\":\"ci-kaniko\"/g" public/config.js'
- cp public/elm-web.js .
- cp public/ports.js .
- cp public/cloud_configs.js .
- cp public/config.js .
script:
- BROWSER_LOWER="$(echo $BROWSER | tr '[:upper:]' '[:lower:]')"
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"auth\":\"$(echo -n $CI_REGISTRY_USER:$CI_REGISTRY_PASSWORD | base64)\"}}}" > /kaniko/.docker/config.json
- |
TAGLIST="$CI_COMMIT_SHORT_SHA $CI_COMMIT_REF_SLUG"
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then TAGLIST="$TAGLIST latest"; fi
if [[ -n "$TAGLIST" ]]; then
for TAG in $TAGLIST; do
FORMATTEDTAGLIST="${FORMATTEDTAGLIST} --destination $CI_REGISTRY_IMAGE:e2e-${BROWSER_LOWER}-$TAG ";
done;
fi
DOCKER_FILE="$CI_PROJECT_DIR/integration-tests/docker/Selenium${BROWSER}AndExosphere/Dockerfile"
/kaniko/executor --context $CI_PROJECT_DIR --dockerfile $DOCKER_FILE $FORMATTEDTAGLIST
except:
- master
- dev
build_with_kaniko_e2e_firefox:
extends: .build_with_kaniko
variables:
BROWSER: "Firefox"
build_with_kaniko_e2e_chrome:
extends: .build_with_kaniko
variables:
BROWSER: "Chrome"
elm_make:
stage: build
before_script:
- 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
# https://gitlab.com/gitlab-org/gitlab-runner/-/issues/327#note_225643576
- if [ -d home/.elm ]; then echo "Restoring ~/.elm"; rsync -a home/.elm ~/; fi
- if [ -d home/.npm ]; then echo "Restoring ~/.npm"; rsync -a home/.npm ~/; fi
- npm install
script:
- mkdir -p public
- npm run build:prod
- cp elm-web.js public/elm-web.js
- cp index.html public/index.html
- cp ports.js public/ports.js
- cp cloud_configs.js public/cloud_configs.js
- cp config.js public/config.js
- cp exosphere.webmanifest public
- cp -R assets public
- cp -R fonts public
- cp service-worker.js public
- md5sum public/index.html public/elm-web.js public/ports.js public/config.js
after_script:
- mkdir -p home && rsync -a ~/.elm home
- mkdir -p home && rsync -a ~/.npm home
artifacts:
paths:
- public
minify:
stage: build
needs:
- elm_make
before_script:
- 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
- if [ -d home/.elm ]; then echo "Restoring ~/.elm"; rsync -a home/.elm ~/; fi
- if [ -d home/.npm ]; then echo "Restoring ~/.npm"; rsync -a home/.npm ~/; fi
- npm install
script:
- cp --force public/elm-web.js elm-web.js
- npm run minify
- cp --force elm-web.js public/elm-web.js
after_script:
- mkdir -p home && rsync -a ~/.elm home
- mkdir -p home && rsync -a ~/.npm home
artifacts:
paths:
- public
only:
- master
- dev
build_design_system:
stage: test
needs:
- elm_make
before_script:
- 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
- if [ -d home/.elm ]; then echo "Restoring ~/.elm"; rsync -a home/.elm ~/; fi
- if [ -d home/.npm ]; then echo "Restoring ~/.npm"; rsync -a home/.npm ~/; fi
- npm install
script:
- npx elm make --optimize src/DesignSystem/Explorer.elm --output=explorer.js
after_script:
- mkdir -p home && rsync -a ~/.elm home
- mkdir -p home && rsync -a ~/.npm home
static_analysis:
stage: test
needs:
- elm_make
before_script:
- 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
- if [ -d home/.elm ]; then echo "Restoring ~/.elm"; rsync -a home/.elm ~/; fi
- if [ -d home/.npm ]; then echo "Restoring ~/.npm"; rsync -a home/.npm ~/; fi
- npm install
- npm install --no-save elm-analyse
script:
- npx elm-analyse
- npx elm-format --validate src tests review/src review/tests
- npx elm-review
- npm run js:format
- npm run js:typecheck
after_script:
- mkdir -p home && rsync -a ~/.elm home
- mkdir -p home && rsync -a ~/.npm home
elm_test:
stage: test
needs:
- elm_make
before_script:
- 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
- if [ -d home/.elm ]; then echo "Restoring ~/.elm"; rsync -a home/.elm ~/; fi
- if [ -d home/.npm ]; then echo "Restoring ~/.npm"; rsync -a home/.npm ~/; fi
- npm install
script:
- npx elm-test-rs
- npx elm-test-rs --project review
- npx elm-test-rs --report junit > elm-test-report.xml
after_script:
- mkdir -p home && rsync -a ~/.elm home
- mkdir -p home && rsync -a ~/.npm home
artifacts:
when: always
reports:
junit: elm-test-report.xml
deploy_prod:
stage: deploy
resource_group: deploy_prod
dependencies:
- elm_make
- minify
before_script:
# See https://docs.gitlab.com/ee/ci/ssh_keys/
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$DOGFOOD_SSH_PRIV_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
# https://docs.gitlab.com/ee/ci/ssh_keys/#verifying-the-ssh-host-keys
- echo "$DOGFOOD_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
script:
- 'cp environment-configs/try.exosphere.app-config.js public/config.js'
- 'sed -i -e "s/\"instanceConfigMgtRepoCheckout\":.*/\"instanceConfigMgtRepoCheckout\": \"${CI_COMMIT_SHA}\",/g" public/config.js'
- 'sed -i -e "s/\"releaseVersion\":.*/\"releaseVersion\":\"${CI_COMMIT_SHA}\",/g" public/config.js'
- 'sed -i -e ''s/<base href="\/" \/>/<base href="\/exosphere\/" \/>/g'' public/index.html'
- 'rsync -av --delete --filter=''protect public/banners.json'' public [email protected]:'
environment:
name: prod
url: https://try.exosphere.app/exosphere
only:
- master
deploy_jetstream2:
stage: deploy
resource_group: deploy_jetstream2
dependencies:
- elm_make
- minify
before_script:
# See https://docs.gitlab.com/ee/ci/ssh_keys/README.html
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$DOGFOOD_SSH_PRIV_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
# https://docs.gitlab.com/ee/ci/ssh_keys/#verifying-the-ssh-host-keys
- echo "$DOGFOOD_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
script:
- 'cp environment-configs/jetstream2.exosphere.app-config.js public/config.js'
- 'sed -i -e "s/\"instanceConfigMgtRepoCheckout\":.*/\"instanceConfigMgtRepoCheckout\": \"${CI_COMMIT_SHA}\",/g" public/config.js'
- 'sed -i -e "s/\"releaseVersion\":.*/\"releaseVersion\":\"${CI_COMMIT_SHA}\",/g" public/config.js'
- 'sed -i -e ''s/<base href="\/" \/>/<base href="\/exosphere\/" \/>/g'' public/index.html'
- 'rsync -av --delete --filter=''protect public/banners.json'' public [email protected]:jetstream2-deploy/'
environment:
name: jetstream2
url: https://jetstream2.exosphere.app/exosphere
only:
- master
deploy_rescloud:
stage: deploy
resource_group: deploy_rescloud
dependencies:
- elm_make
- minify
before_script:
# See https://docs.gitlab.com/ee/ci/ssh_keys/README.html
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$DOGFOOD_SSH_PRIV_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
# https://docs.gitlab.com/ee/ci/ssh_keys/#verifying-the-ssh-host-keys
- echo "$DOGFOOD_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
script:
- 'cp environment-configs/rescloud.iu.edu-config.js public/config.js'
- 'sed -i -e "s/\"instanceConfigMgtRepoCheckout\":.*/\"instanceConfigMgtRepoCheckout\": \"${CI_COMMIT_SHA}\",/g" public/config.js'
- 'sed -i -e "s/\"releaseVersion\":.*/\"releaseVersion\":\"${CI_COMMIT_SHA}\",/g" public/config.js'
- 'sed -i -e ''s/<base href="\/" \/>/<base href="\/exosphere\/" \/>/g'' public/index.html'
- 'rsync -av --delete --filter=''protect public/banners.json'' public [email protected]:rescloud-deploy/'
environment:
name: rescloud
url: https://rescloud.iu.edu/exosphere
only:
- master
deploy_dev:
stage: deploy
resource_group: deploy_dev
needs:
- elm_make
- minify
before_script:
# See https://docs.gitlab.com/ee/ci/ssh_keys/README.html
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$DOGFOOD_SSH_PRIV_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
# https://docs.gitlab.com/ee/ci/ssh_keys/#verifying-the-ssh-host-keys
- echo "$DOGFOOD_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
script:
- 'cp environment-configs/try-dev.exosphere.app-config.js public/config.js'
- 'sed -i -e "s/\"instanceConfigMgtRepoCheckout\":.*/\"instanceConfigMgtRepoCheckout\": \"${CI_COMMIT_SHA}\",/g" public/config.js'
- 'sed -i -e "s/\"releaseVersion\":.*/\"releaseVersion\":\"${CI_COMMIT_SHA}\",/g" public/config.js'
- 'sed -i -e ''s/<base href="\/" \/>/<base href="\/exosphere\/" \/>/g'' public/index.html'
- 'rsync -av --delete --filter=''protect public/banners.json'' public [email protected]:dev-deploy/'
environment:
name: dev
url: https://try-dev.exosphere.app/exosphere
only:
- dev
.e2e:
#Hidden job to use as an "extends" template
image: python:3.11
allow_failure: true
retry: 1
services:
- name: "$SELENIUM_CONTAINER_IMAGE"
alias: e2e.exosphere.service
before_script:
- if [[ -z "$OS_USERNAME" || -z "$OS_PASSWORD" ]]; then echo "Must provide OS_USERNAME and OS_PASSWORD in environment" 1>&2; exit 1; fi
- echo -e "section_start:`date +%s`:pip_install[collapsed=true]\r\e[0KInstall Python dependencies"
- pip install -r integration-tests/requirements.txt
- echo -e "section_end:`date +%s`:pip_install\r\e[0K"
- mkdir -p integration-tests/screenshots integration-tests/logs
# For visual debugging of browser via VNC, uncomment lines below to enable cloudflared tunnel:
# - echo -e "section_start:`date +%s`:install_cloudflared[collapsed=true]\r\e[0KInstall cloudflared"
# - wget -O ~/cloudflared.deb https://bin.equinox.io/c/VdrWdbjqyF/cloudflared-stable-linux-amd64.deb
# - dpkg -i ~/cloudflared.deb
# - echo -e "section_end:`date +%s`:install_cloudflared\r\e[0K"
# - echo -e "section_start:`date +%s`:cloudflared_tunnel_vnc[collapsed=true]\r\e[0KEstablish a Cloudflare tunnel to VNC"
# - ./integration-tests/docker/run-cloudflared-tunnel.sh
# - echo -e "section_end:`date +%s`:cloudflared_tunnel_vnc\r\e[0K"
# - echo cloudflared should be running in the background. Sleep for 60 seconds so you can grab the VNC tunnel details.
# - sleep 60
script:
- cd integration-tests
- echo -e "section_start:`date +%s`:behave_run[collapsed=false]\r\e[0KRun behave"
- behave --junit --no-skipped -D UNIQUE_TAG="e2e-$BROWSER_LOWER-$CI_COMMIT_REF_SLUG-$ENV_NAME" -D EXOSPHERE_BASE_URL=$EXOSPHERE_BASE_URL -D BROWSER=$BROWSER_LOWER -D REMOTE_WEBDRIVER=yes -D COMMAND_EXECUTOR=http://e2e.exosphere.service:4444/wd/hub features/exosphere.feature
- echo -e "section_end:`date +%s`:behave_run\r\e[0K"
artifacts:
when: always
reports:
junit: integration-tests/reports/TESTS-exosphere.xml
paths:
- integration-tests/screenshots
- integration-tests/logs
.mr_e2e:
extends: .e2e
stage: test
variables:
CI_DISPOSABLE_ENVIRONMENT: "true"
EXOSPHERE_BASE_URL: "http://app.exosphere.localhost:8000"
ENV_NAME: "mr"
except:
- master
- dev
mr_e2e_firefox:
extends: .mr_e2e
variables:
BROWSER_LOWER: "firefox"
SELENIUM_CONTAINER_IMAGE: "$CI_REGISTRY_IMAGE:e2e-firefox-$CI_COMMIT_SHORT_SHA"
needs:
- build_with_kaniko_e2e_firefox
mr_e2e_chrome:
extends: .mr_e2e
variables:
BROWSER_LOWER: "chrome"
SELENIUM_CONTAINER_IMAGE: "$CI_REGISTRY_IMAGE:e2e-chrome-$CI_COMMIT_SHORT_SHA"
needs:
- build_with_kaniko_e2e_chrome
.e2e_chrome:
extends: .e2e
variables:
BROWSER_LOWER: "chrome"
SELENIUM_CONTAINER_IMAGE: "selenium/standalone-chrome:4"
.e2e_firefox:
extends: .e2e
variables:
BROWSER_LOWER: "firefox"
SELENIUM_CONTAINER_IMAGE: "selenium/standalone-firefox:4"
.dev_post_deploy:
stage: postdeploy
variables:
EXOSPHERE_BASE_URL: "https://try-dev.exosphere.app/exosphere"
ENV_NAME: "dev"
needs:
- deploy_dev
only:
- dev
.prod_post_deploy:
stage: postdeploy
variables:
EXOSPHERE_BASE_URL: "https://try.exosphere.app/exosphere"
ENV_NAME: "prod"
needs:
- deploy_prod
only:
- master
.jetstream2_post_deploy:
stage: postdeploy
variables:
EXOSPHERE_BASE_URL: "https://jetstream2.exosphere.app/exosphere/loginpicker"
ENV_NAME: "j7m2"
needs:
- deploy_jetstream2
only:
- master
dev_post_deploy_e2e_chrome:
extends:
- .e2e_chrome
- .dev_post_deploy
dev_post_deploy_e2e_firefox:
extends:
- .e2e_firefox
- .dev_post_deploy
prod_post_deploy_e2e_chrome:
extends:
- .e2e_chrome
- .prod_post_deploy
prod_post_deploy_e2e_firefox:
extends:
- .e2e_firefox
- .prod_post_deploy
jetstream2_post_deploy_e2e_chrome:
extends:
- .e2e_chrome
- .jetstream2_post_deploy
jetstream2_post_deploy_e2e_firefox:
extends:
- .e2e_firefox
- .jetstream2_post_deploy
mkdocs_test:
stage: mkdocs
# Run as soon as possible because it doesn't depend on any other jobs
needs: []
image: python:3.11
before_script:
- cd mkdocs
- pip install -r requirements.txt
script:
- mkdocs build --strict --verbose --site-dir test
artifacts:
paths:
- mkdocs/test
pages:
stage: mkdocs
needs:
- mkdocs_test
image: python:3.11
before_script:
- cd mkdocs
- pip install -r requirements.txt
script:
- mkdocs build --strict --verbose
- mv site ../public
artifacts:
paths:
- public
only:
- master
include:
- template: Dependency-Scanning.gitlab-ci.yml