-
Notifications
You must be signed in to change notification settings - Fork 4
/
.gitlab-ci.yml
916 lines (854 loc) · 25.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
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
stages:
- prepare
- test
- build:frontend
- build:docker
- test:containers
- deploy
variables:
K8_NAMESPACE: covid-19-vis
STAGING_BRANCH: main
URL_SUFFIX: coronavis.dbvis.de
###########################################
# DEFINE BRANCH TRIGGER RULES
###########################################
#--------------------
# Deployment
#--------------------
.rules-backend: &rules-backend
rules:
# do not run pipelines for merge requests (gets rid of "detatched pipelines")
- if: $CI_MERGE_REQUEST_ID
when: never
# if this is set, run this job all the time
- if: $RUN_ALWAYS == "yes"
when: on_success
# run if files changed
# and if it should run on a feature branch or it should run on main
# - changes:
# # - Backend/**/*
# # - k8/Backend/**/*
# # - .gitlab-ci.yml
- if: $RUN_ON_FB == "yes" && $CI_COMMIT_BRANCH != $STAGING_BRANCH && $CI_COMMIT_TAG == null
when: on_success
# - changes:
# - Backend/**/*
# - k8/Backend/**/*
# - .gitlab-ci.yml
- if: $RUN_ON_MAIN == "yes" && $CI_COMMIT_BRANCH == $STAGING_BRANCH
when: on_success
# run if tagged
- if: $RUN_ON_TAG == "yes" && $CI_COMMIT_TAG =~ /^v.*/
when: on_success
# default is on_success, so explicitly set job not to run if none of the above rules matched
- when: never
.rules-frontend: &rules-frontend
rules:
# do not run pipelines for merge requests (gets rid of "detatched pipelines")
- if: $CI_MERGE_REQUEST_ID
when: never
# if this is set, run this job all the time
- if: $RUN_ALWAYS == "yes"
when: on_success
# run if files changed
# and if it should run on a feature branch or it should run on main
# - changes:
# - Frontend/**/*
# - k8/Frontend/**/*
# - .gitlab-ci.yml
- if: $RUN_ON_FB == "yes" && $CI_COMMIT_BRANCH != $STAGING_BRANCH && $CI_COMMIT_TAG == null
when: on_success
# - changes:
# - Frontend/**/*
# - k8/Frontend/**/*
# - .gitlab-ci.yml
- if: $RUN_ON_MAIN == "yes" && $CI_COMMIT_BRANCH == $STAGING_BRANCH
when: on_success
# run if tagged
- if: $RUN_ON_TAG == "yes" && $CI_COMMIT_TAG =~ /^v.*/
when: on_success
# default is on_success, so explicitly set job not to run if none of the above rules matched
- when: never
.rules-crawler: &rules-crawler
rules:
# do not run pipelines for merge requests (gets rid of "detatched pipelines")
- if: $CI_MERGE_REQUEST_ID
when: never
# if this is set, run this job all the time
- if: $RUN_ALWAYS == "yes"
when: on_success
# run if files changed
# and if it should run on a feature branch or it should run on main
# - changes:
# - Crawler/**/*
# - k8/Crawler/**/*
# - k8/crawler-new/**/*
# - .gitlab-ci.yml
- if: $RUN_ON_FB == "yes" && $CI_COMMIT_BRANCH != $STAGING_BRANCH && $CI_COMMIT_TAG == null
when: on_success
# - changes:
# - Crawler/**/*
# - k8/Crawler/**/*
# - k8/crawler-new/**/*
# - .gitlab-ci.yml
- if: $RUN_ON_MAIN == "yes" && $CI_COMMIT_BRANCH == $STAGING_BRANCH
when: on_success
# run if tagged
- if: $RUN_ON_TAG == "yes" && $CI_COMMIT_TAG =~ /^v.*/
when: on_success
# default is on_success, so explicitly set job not to run if none of the above rules matched
- when: never
.rules-tiles: &rules-tiles
rules:
# do not run pipelines for merge requests (gets rid of "detatched pipelines")
- if: $CI_MERGE_REQUEST_ID
when: never
# if this is set, run this job all the time
- if: $RUN_ALWAYS == "yes"
when: on_success
# run if files changed
# and if it should run on a feature branch or it should run on main
- if: $RUN_ON_FB == "yes" && $CI_COMMIT_BRANCH != $STAGING_BRANCH && $CI_COMMIT_TAG == null
changes:
- "Tiles/**/*"
- "k8/tiles-new/**/*"
- .gitlab-ci.yml
when: manual
- if: $RUN_ON_MAIN == "yes" && $CI_COMMIT_BRANCH == $STAGING_BRANCH
changes:
- "Tiles/**/*"
- "k8/tiles-new/**/*"
- .gitlab-ci.yml
when: manual
# run if tagged
- if: $RUN_ON_TAG == "yes" && $CI_COMMIT_TAG =~ /^v.*/
changes:
- "Tiles/**/*"
- "k8/tiles-new/**/*"
- .gitlab-ci.yml
when: manual
# default is on_success, so explicitly set job not to run if none of the above rules matched
- when: never
#--------------------
# Environment Cleanup
#--------------------
.rules-backend-cleanup: &rules-backend-cleanup
rules:
# do not run pipelines for merge requests (gets rid of "detatched pipelines")
- if: $CI_MERGE_REQUEST_ID
when: never
# if this is set, run this job all the time
- if: $RUN_ALWAYS == "yes"
when: manual
# run if files changed
# and if it should run on a feature branch or it should run on main
# - changes:
# - Backend/**/*
# - k8/Backend/**/*
# - .gitlab-ci.yml
- if: $RUN_ON_FB == "yes" && $CI_COMMIT_BRANCH != $STAGING_BRANCH && $CI_COMMIT_TAG == null
when: manual
allow_failure: true
# - changes:
# - Backend/**/*
# - k8/Backend/**/*
# - .gitlab-ci.yml
- if: $RUN_ON_MAIN == "yes" && $CI_COMMIT_BRANCH == $STAGING_BRANCH
when: manual
allow_failure: true
# default is on_success, so explicitly set job not to run if none of the above rules matched
- when: never
.rules-frontend-cleanup: &rules-frontend-cleanup
rules:
# do not run pipelines for merge requests (gets rid of "detatched pipelines")
- if: $CI_MERGE_REQUEST_ID
when: never
# if this is set, run this job all the time
- if: $RUN_ALWAYS == "yes"
when: manual
# run if files changed
# and if it should run on a feature branch or it should run on main
# - changes:
# - Frontend/**/*
# - k8/Frontend/**/*
# - .gitlab-ci.yml
- if: $RUN_ON_FB == "yes" && $CI_COMMIT_BRANCH != $STAGING_BRANCH && $CI_COMMIT_TAG == null
when: manual
allow_failure: true
# - changes:
# - Frontend/**/*
# - k8/Frontend/**/*
# - .gitlab-ci.yml
- if: $RUN_ON_MAIN == "yes" && $CI_COMMIT_BRANCH == $STAGING_BRANCH
when: manual
allow_failure: true
# default is on_success, so explicitly set job not to run if none of the above rules matched
- when: never
###########################################
# SETUP ENVIRONMENT VARIALBES
###########################################
export-environment:
image: debian:stretch-slim
stage: prepare
script:
- echo $CI_COMMIT_BRANCH
- echo $CI_COMMIT_REF_NAME
# set the version either as a tag (v0.0.1) or as a commit sha (74bac331)
- if [[ ${CI_COMMIT_TAG} =~ ^v[0-9]+.[0-9]+.[0-9]+ ]]; then VERSION=${CI_COMMIT_TAG}; else VERSION=${CI_COMMIT_SHORT_SHA}; fi
# the current URL suffix
#- URL_SUFFIX="covis.dbvis.de" # defined in the variables section
# this shortens the slug to 30 characters and removes all trailing dashes
- SHORTENED_CI_COMMIT_REF_SLUG=$(echo ${CI_COMMIT_REF_SLUG} | tr / - | cut -c -30 | sed -E 's#-+$##')
- URL_PREFIX=""
- FRONTEND_URL_TILES_PREFIX=""
- URL_PROTOCOL="https"
- ENV_TYPE="review"
- REPLICA_COUNT="2"
- CPU_REQ="200m"
- CPU_LIMIT="4000m"
- MEM_REQ="3Gi"
- MEM_LIMIT="10Gi"
# multiple things happen here:
# URL_PREFIX:
# if tag => ""
# if main => "staging."
# if fb => "${CI_COMMIT_REF_SLUG}."
# Furthermore, the FRONTEND_URL_TILES_PREFIX is set because the tile server will not be deployed on a per fb-basis
# FRONTEND_URL_TILES_PREFIX:
# if tag => ""
# if main => "staging."
# if fb => "staging."
# Determine what ENV_TYPE it is (production, staging or review)
- if [[ "${CI_COMMIT_TAG}" =~ ^v[0-9]+.[0-9]+.[0-9]+ ]]; then ENV_TYPE="production"; fi
- if [ "${CI_COMMIT_BRANCH}" == "${STAGING_BRANCH}" ]; then ENV_TYPE="staging"; fi
# Determine URL, ReplicaCount, and ReleaseName based on ENV_TYPE
- if [ "${ENV_TYPE}" == "staging" ]; then FRONTEND_URL_TILES_PREFIX="staging."; URL_PREFIX="staging."; REPLICA_COUNT="1"; RELEASE_NAME_RAW="${ENV_TYPE}/$CI_PROJECT_NAME/${CI_COMMIT_REF_SLUG}"; CPU_REQ="50m"; CPU_LIMIT="4000m"; MEM_REQ="1Gi"; MEM_LIMIT="4Gi"; fi
- if [ "${ENV_TYPE}" == "review" ]; then FRONTEND_URL_TILES_PREFIX="staging."; URL_PREFIX="${SHORTENED_CI_COMMIT_REF_SLUG}."; REPLICA_COUNT="1"; RELEASE_NAME_RAW="${ENV_TYPE}/$CI_PROJECT_NAME/${CI_COMMIT_REF_SLUG}"; CPU_REQ="50m"; CPU_LIMIT="4000m"; MEM_REQ="500Mi"; MEM_LIMIT="4Gi"; fi
# Build the frontend url: prefix.suffix
- URL_FRONTEND="${URL_PREFIX}${URL_SUFFIX}"
# Build the backend url: prefix.api.suffix
- URL_BACKEND="${URL_PREFIX}api.${URL_SUFFIX}"
# Build the tiles url: prefix.tiles.suffix
- URL_TILES="${URL_PREFIX}tiles.${URL_SUFFIX}"
# This variable is used in the build job to set the api url in the environment.prod.ts
- FRONTEND_URL_BACKEND="${URL_PREFIX}api.${URL_SUFFIX}"
# This variable is used in the build job to set the tiles server url in the environment.prod.ts
- FRONTEND_URL_TILES="${FRONTEND_URL_TILES_PREFIX}tiles.${URL_SUFFIX}"
# all the stuff into the var.env
- echo "ENV_TYPE=${ENV_TYPE}" >> var.env
- echo "VERSION=${VERSION}" >> var.env
- echo "URL_PROTOCOL=${URL_PROTOCOL}" >> var.env
- echo "URL_FRONTEND=${URL_FRONTEND}" >> var.env
- echo "URL_BACKEND=${URL_BACKEND}" >> var.env
- echo "URL_TILES=${URL_TILES}" >> var.env
- echo "FRONTEND_URL_BACKEND=${FRONTEND_URL_BACKEND}" >> var.env
- echo "FRONTEND_URL_TILES=${FRONTEND_URL_TILES}" >> var.env
- echo "REPLICA_COUNT=${REPLICA_COUNT}" >> var.env
- echo "CPU_REQ=${CPU_REQ}" >> var.env
- echo "CPU_LIMIT=${CPU_LIMIT}" >> var.env
- echo "MEM_REQ=${MEM_REQ}" >> var.env
- echo "MEM_LIMIT=${MEM_LIMIT}" >> var.env
# DEBUG
- cat var.env
artifacts:
paths:
- var.env
expire_in: 3000 days
retry: 2
tags:
- no-cache
set up sentry release:
stage: prepare
image:
name: getsentry/sentry-cli:2.39.1
entrypoint: [""]
variables:
RUN_ALWAYS: "no"
RUN_ON_FB: "yes"
RUN_ON_MAIN: "yes"
RUN_ON_TAG: "yes"
script:
- export SENTRY_AUTH_TOKEN=${SENTRY_AUTH}
- export SENTRY_ORG=lingvisio
- sentry-cli releases new -p server "$CI_COMMIT_SHA"
- sentry-cli releases set-commits "$CI_COMMIT_SHA" --auto --log-level=debug --ignore-missing --ignore-empty
- sentry-cli releases finalize "$CI_COMMIT_SHA"
- sentry-cli releases deploys "$CI_COMMIT_SHA" new -e ${CI_COMMIT_REF_NAME}
dependencies: []
tags:
- no-cache
<<: *rules-frontend
interruptible: true
allow_failure: true
retry: 2
frontend-install-dependencies:
stage: prepare
image: node:21
script:
- cd ./Frontend/gis
- yarn config set registry https://nexus.dbvis.de/repository/npmjs/
# if node_modules does not exist use yarn to create it
- test -d ./node_modules || yarn --frozen-lockfile --non-interactive --no-progress
artifacts:
expire_in: 1 day
paths:
- ./Frontend/gis/node_modules
cache:
key:
files:
- ./Frontend/gis/package.json
- ./Frontend/gis/yarn.lock
paths:
- ./Frontend/gis/node_modules
policy: pull-push
needs: []
retry: 2
tags:
- docker
syntax-check-crawler-scripts:
stage: test
image: python:3.13-slim
script:
- source var.env
- cd Crawler
- python -m compileall
dependencies:
- export-environment
needs:
- export-environment
retry: 2
tags:
- no-cache
frontend-lint:
stage: test
image: node:21
script:
- cd ./Frontend/gis
- yarn lint
dependencies:
- frontend-install-dependencies
needs:
- frontend-install-dependencies
retry: 2
tags:
- no-cache
# frontend-code-quality:
# stage: test
# image: docker:latest
# allow_failure: true
# services:
# - docker:dind
# variables:
# DOCKER_DRIVER: overlay2
# DOCKER_TLS_CERTDIR: ""
# CODE_QUALITY_IMAGE: "registry.gitlab.com/gitlab-org/ci-cd/codequality:0.85.10-gitlab.1"
# needs: []
# before_script:
# - source ./Frontend/code-quality-env.sh
# - export SOURCE_CODE=$PWD/Frontend/gis
# script:
# # - |
# # if ! docker info &>/dev/null; then
# # if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then
# # export DOCKER_HOST='tcp://localhost:2375'
# # fi
# # fi
# - docker pull --quiet "$CODE_QUALITY_IMAGE"
# - |
# docker run \
# $(propagate_env_vars \
# SOURCE_CODE \
# TIMEOUT_SECONDS \
# CODECLIMATE_DEBUG \
# CODECLIMATE_DEV \
# REPORT_STDOUT \
# ENGINE_MEMORY_LIMIT_BYTES \
# ) \
# --volume "$PWD":/code \
# --volume /var/run/docker.sock:/var/run/docker.sock \
# "$CODE_QUALITY_IMAGE" /code
# artifacts:
# reports:
# codequality: gl-code-quality-report.json
# expire_in: 4 weeks
# dependencies: []
# rules:
# - if: '$CODE_QUALITY_DISABLED'
# when: never
# - if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
# retry: 2
# tags:
# - docker-build
check-missing-translations:
stage: test
image: node:21
script:
- cd ./Frontend/gis
- yarn extract-i18n
- git status
- git diff
- |
if [ -z "$(git status --porcelain)" ]; then
# Working directory clean
exit 0
else
# Uncommitted changes
exit 1
fi
dependencies:
- frontend-install-dependencies
needs:
- frontend-install-dependencies
retry: 2
tags:
- no-cache
###########################################
# BUILD
###########################################
.build-frontend: &build-frontend
stage: build:frontend
image: node:21
script:
- source var.env
- cd ./Frontend
- export FRONTEND_URL_BACKEND=${URL_BACKEND}
- export FRONTEND_URL_TILES=${FRONTEND_URL_TILES}
- export URL_PROTOCOL
- export VERSION
- export ENV_TYPE
- export SENTRY_DSN
- sh -c ./replace-environment-urls.sh
- cd ./gis
- yarn ng version
- yarn build
artifacts:
expire_in: 1 day
paths:
- ./Frontend/gis/dist
cache:
key: coronavis-angular-cache
paths:
- ./Frontend/gis/.angular/
dependencies:
- export-environment
- frontend-install-dependencies
needs:
- export-environment
- frontend-install-dependencies
retry: 2
tags:
- docker
build-frontend:
extends: .build-frontend
###########################################
# DOCKERIZE
###########################################
.dockerize-template: &dockerize-template
stage: build:docker
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
# load the var.env variables from the export-environment job
- source ./var.env
# Login
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- cd ${FOLDER}
# generate imagename using a lowercased foldername == app
- IMGNAME=$(echo "${FOLDER}" | tr '[:upper:]' '[:lower:]')
- IMG="${CI_REGISTRY_IMAGE}/${IMGNAME}:${VERSION}"
- IMG2="${CI_REGISTRY_IMAGE}/${IMGNAME}:${CI_COMMIT_SHORT_SHA}"
- KANIKO_DIR="${CI_PROJECT_DIR}/kaniko"
- echo "KANKO DIR = ${KANIKO_DIR}"
# build and push :)
- /kaniko/executor --context . --dockerfile ./Dockerfile --registry-mirror registry-mirror.dbvis.de --build-arg VERSION=${VERSION} --destination $IMG --destination $IMG2 --cache=${KANIKO_CACHE} --force --use-new-run --kaniko-dir=${KANIKO_DIR}
tags:
- no-cache
retry: 2
dockerize-backend:
variables:
FOLDER: Backend
# we build and deploy always to keep backend and frontend in sync
RUN_ALWAYS: "yes"
RUN_ON_FB: "yes"
RUN_ON_MAIN: "yes"
RUN_ON_TAG: "yes"
KANIKO_CACHE: "true"
<<: *dockerize-template
<<: *rules-backend
needs:
- export-environment
dependencies:
- export-environment
dockerize-frontend:
variables:
FOLDER: Frontend
# we build and deploy always to keep backend and frontend in sync
RUN_ALWAYS: "yes"
RUN_ON_FB: "yes"
RUN_ON_MAIN: "yes"
RUN_ON_TAG: "yes"
KANIKO_CACHE: "true"
<<: *dockerize-template
<<: *rules-frontend
needs:
- build-frontend
- export-environment
dependencies:
- build-frontend
- export-environment
dockerize-crawler:
variables:
FOLDER: Crawler
RUN_ALWAYS: "yes"
# Yes? In case the build image fails this could help with MR?
RUN_ON_FB: "yes"
RUN_ON_MAIN: "yes"
RUN_ON_TAG: "yes"
KANIKO_CACHE: "true"
<<: *dockerize-template
<<: *rules-crawler
needs:
- export-environment
dependencies:
- export-environment
dockerize-tiles:
variables:
FOLDER: Tiles
RUN_ALWAYS: "no"
RUN_ON_FB: "no"
RUN_ON_MAIN: "yes"
RUN_ON_TAG: "yes"
GIT_SUBMODULE_STRATEGY: "recursive"
KANIKO_CACHE: "false"
<<: *dockerize-template
<<: *rules-tiles
tags:
- large-data
needs:
- export-environment
dependencies:
- export-environment
###########################################
# TEST CONTAINERS
###########################################
test-backend:
stage: test:containers
image:
name: $CI_REGISTRY_IMAGE/backend:$CI_COMMIT_SHORT_SHA
entrypoint: ['']
script:
- source var.env
- export $(grep -v '^#' var.env | xargs -d '\n')
- cd ${FOLDER}
- python -m unittest
<<: *rules-backend
variables:
ENVIRONMENT: testing
FOLDER: Backend
# we build and deploy always to keep backend and frontend in sync
RUN_ALWAYS: "yes"
RUN_ON_FB: "yes"
RUN_ON_MAIN: "yes"
RUN_ON_TAG: "yes"
needs:
- export-environment
- dockerize-backend
dependencies:
- export-environment
retry: 2
tags:
- no-cache
###########################################
# DEPLOY NEW CLUSTER
###########################################
.deploy-script-new: &deploy-template-new
stage: deploy
image:
name: alpine/helm:3.16.3
entrypoint: ["sh", "-c", "apk add bash sed && /bin/bash"]
script:
- echo $KUBECONFIG
- source var.env
# DEBUG
- cat var.env
# using the app name converted to uppercase to generate the url accessor, result: URL_BACKEND
- URL_ACCESSOR="URL_$(echo ${APP} | tr [:lower:] [:upper:])"
# DEBUG
- echo $URL_ACCESSOR
# this will retrieve the content of the actual URL_BACKEND variable
# works only with bash
# - URL=${!URL_ACCESSOR}
- URL=$(eval echo \$$URL_ACCESSOR)
# DEBUG
- echo ${URL}
# generates the chart name using the environment name, replace all / with -; result: review-backend-100-fancify-pipeline
- CHART_NAME=$(echo ${CI_ENVIRONMENT_NAME} | tr / - | cut -c -53 | sed -E 's#-+$##')
# DEBUG
- echo ${CHART_NAME}
# delete old var.env file to not run into limit issues
- rm var.env
- echo "ENV_TYPE=${ENV_TYPE}" >> var.env
- echo "URL_PROTOCOL=${URL_PROTOCOL}" >> var.env
- echo "VERSION=${VERSION}" >> var.env
# write the url into the var.env file for the dynamic env url generation
- echo "URL=${URL}" >> var.env
- cat var.env
# use chart name and the folder by uppercasing the first character of the app name; result: Backend
- helm upgrade --namespace=${K8_NAMESPACE} --dry-run --debug --install --set sha="${VERSION}" --set url=${URL} --set urlProtocol=${URL_PROTOCOL} --set environment=${ENV_TYPE} --set replicaCount=${REPLICA_COUNT} --set cpu.req=${CPU_REQ} --set cpu.limit=${CPU_LIMIT} --set mem.req=${MEM_REQ} --set mem.limit=${MEM_LIMIT} ${CHART_NAME} ./k8/${APP}-new
- helm upgrade --namespace=${K8_NAMESPACE} --install --set sha="${VERSION}" --set url=${URL} --set urlProtocol=${URL_PROTOCOL} --set environment=${ENV_TYPE} --set replicaCount=${REPLICA_COUNT} --set cpu.req=${CPU_REQ} --set cpu.limit=${CPU_LIMIT} --set mem.req=${MEM_REQ} --set mem.limit=${MEM_LIMIT} ${CHART_NAME} ./k8/${APP}-new
retry: 2
tags:
- no-cache
#--------------------
# BACKEND
#--------------------
.deploy-backend-new: &deploy-backend-new
<<: *deploy-template-new
<<: *rules-backend
before_script:
- export KUBECONFIG=$KUBECONFIG_NEW
variables:
APP: backend
RUN_ON_FB: "no"
RUN_ON_MAIN: "no"
RUN_ON_TAG: "no"
environment:
url: $URL_PROTOCOL://$URL
name: $ENV_TYPE/$APP/$CI_COMMIT_REF_SLUG
kubernetes:
namespace: $K8_NAMESPACE
artifacts:
reports:
dotenv: var.env
needs:
- test-backend
- dockerize-backend
- export-environment
dependencies:
- dockerize-backend
- export-environment
deploy-backend-fb-new:
extends: .deploy-backend-new
variables:
ENV_TYPE: review
RUN_ON_FB: "yes"
environment:
on_stop: remove-deployment-backend-review-new
deploy-backend-staging-new:
extends: .deploy-backend-new
before_script:
- export KUBECONFIG=$KUBECONFIG_STAGING
variables:
ENV_TYPE: staging
RUN_ON_MAIN: "yes"
K8_NAMESPACE: covid-19-vis-staging
deploy-backend-production-new:
extends: .deploy-backend-new
before_script:
- export KUBECONFIG=$KUBECONFIG_PRODUCTION
variables:
ENV_TYPE: production
RUN_ON_TAG: "yes"
K8_NAMESPACE: covid-19-vis-production
environment:
name: $ENV_TYPE/$APP
#--------------------
# FRONTEND
#--------------------
.deploy-frontend-new: &deploy-frontend-new
<<: *deploy-template-new
<<: *rules-frontend
before_script:
- export KUBECONFIG=$KUBECONFIG_NEW
variables:
APP: frontend
RUN_ON_FB: "no"
RUN_ON_MAIN: "no"
RUN_ON_TAG: "no"
environment:
url: $URL_PROTOCOL://$URL
name: $ENV_TYPE/$APP/$CI_COMMIT_REF_SLUG
kubernetes:
namespace: $K8_NAMESPACE
artifacts:
reports:
dotenv: var.env
needs:
- dockerize-frontend
- export-environment
dependencies:
- dockerize-frontend
- export-environment
deploy-frontend-fb-new:
extends: .deploy-frontend-new
environment:
on_stop: remove-deployment-frontend-review-new
variables:
ENV_TYPE: review
RUN_ON_FB: "yes"
deploy-frontend-staging-new:
extends: .deploy-frontend-new
before_script:
- export KUBECONFIG=$KUBECONFIG_STAGING
variables:
ENV_TYPE: staging
RUN_ON_MAIN: "yes"
K8_NAMESPACE: covid-19-vis-staging
deploy-frontend-production-new:
extends: .deploy-frontend-new
before_script:
- export KUBECONFIG=$KUBECONFIG_PRODUCTION
variables:
ENV_TYPE: production
RUN_ON_TAG: "yes"
K8_NAMESPACE: covid-19-vis-production
environment:
name: $ENV_TYPE/$APP
#--------------------
# CRAWLER
#--------------------
.deploy-crawler-new: &deploy-crawler-new
<<: *deploy-template-new
<<: *rules-crawler
before_script:
- export KUBECONFIG=$KUBECONFIG_NEW
variables:
APP: crawler
RUN_ON_FB: "no"
RUN_ON_MAIN: "no"
RUN_ON_TAG: "no"
environment:
# url: $URL_PROTOCOL://$URL
name: $ENV_TYPE/$APP/$CI_COMMIT_REF_SLUG
kubernetes:
namespace: $K8_NAMESPACE
artifacts:
reports:
dotenv: var.env
needs:
- dockerize-crawler
- export-environment
dependencies:
- dockerize-crawler
- export-environment
# deploy-crawler-fb:
# extends: .deploy-crawler-new
# variables:
# ENV_TYPE: review
# RUN_ON_FB: "yes"
# deploy-crawler-staging:
# extends: .deploy-crawler-new
# before_script:
# - export KUBECONFIG=$KUBECONFIG_STAGING
# variables:
# ENV_TYPE: staging
# RUN_ON_MAIN: "yes"
# K8_NAMESPACE: covid-19-vis-staging
deploy-crawler-production-new:
extends: .deploy-crawler-new
before_script:
- export KUBECONFIG=$KUBECONFIG_PRODUCTION
variables:
ENV_TYPE: production
RUN_ON_TAG: "yes"
K8_NAMESPACE: covid-19-vis-production
environment:
name: $ENV_TYPE/$APP
#--------------------
# TILES
#--------------------
.deploy-tiles-new: &deploy-tiles-new
<<: *deploy-template-new
<<: *rules-tiles
before_script:
- export KUBECONFIG=$KUBECONFIG_NEW
variables:
APP: tiles
RUN_ON_FB: "no"
RUN_ON_MAIN: "no"
RUN_ON_TAG: "no"
environment:
url: $URL_PROTOCOL://$URL
name: $ENV_TYPE/$APP/$CI_COMMIT_REF_SLUG
kubernetes:
namespace: $K8_NAMESPACE
artifacts:
reports:
dotenv: var.env
needs:
- dockerize-tiles
- export-environment
dependencies:
- dockerize-tiles
- export-environment
# deploy-tiles-fb:
# extends: .deploy-tiles-new
# variables:
# ENV_TYPE: review
# RUN_ON_FB: "yes"
deploy-tiles-staging-new:
extends: .deploy-tiles-new
before_script:
- export KUBECONFIG=$KUBECONFIG_STAGING
variables:
ENV_TYPE: staging
RUN_ON_MAIN: "yes"
K8_NAMESPACE: covid-19-vis-staging
deploy-tiles-production-new:
extends: .deploy-tiles-new
before_script:
- export KUBECONFIG=$KUBECONFIG_PRODUCTION
variables:
ENV_TYPE: production
RUN_ON_TAG: "yes"
K8_NAMESPACE: covid-19-vis-production
environment:
name: $ENV_TYPE/$APP
###########################################
# CLEANUP NEW ENV
###########################################
.remove-deployment-new:
stage: deploy
image:
name: alpine/helm:3.16.3
entrypoint: ["sh", "-c", "apk add bash && /bin/bash"]
variables:
GIT_STRATEGY: none
RUN_ON_FB: "no"
RUN_ON_MAIN: "no"
RUN_ON_TAG: "no"
script:
- export KUBECONFIG=$KUBECONFIG_NEW
- echo $KUBECONFIG
- CHART_NAME=$(echo "${ENV_TYPE}/${APP}/${CI_COMMIT_REF_SLUG}" | tr / - | cut -c -53 | sed -E 's#-+$##')
# DEBUG
- echo $CHART_NAME
- helm delete --namespace=${K8_NAMESPACE} --dry-run --debug ${CHART_NAME}
- helm delete --namespace=${K8_NAMESPACE} ${CHART_NAME}
dependencies: []
allow_failure: true
retry: 2
tags:
- no-cache
remove-deployment-backend-review-new:
extends: .remove-deployment-new
<<: *rules-backend-cleanup
variables:
APP: backend
ENV_TYPE: review
RUN_ON_FB: "yes"
environment:
name: $ENV_TYPE/$APP/$CI_COMMIT_REF_SLUG
action: stop
remove-deployment-frontend-review-new:
extends: .remove-deployment-new
<<: *rules-frontend-cleanup
variables:
APP: frontend
ENV_TYPE: review
RUN_ON_FB: "yes"
environment:
name: $ENV_TYPE/$APP/$CI_COMMIT_REF_SLUG
action: stop