forked from magda-io/magda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
1046 lines (998 loc) · 38.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
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
variables:
CI: "true"
DOCKER_DRIVER: overlay2
# Make sure sbt cache are captured completely
COURSIER_CACHE: $CI_PROJECT_DIR/sbt-cache/coursier
SBT_OPTS: >
-Dsbt.global.base=$CI_PROJECT_DIR/sbt-cache/sbtboot
-Dsbt.boot.directory=$CI_PROJECT_DIR/sbt-cache/boot
-Dsbt.ivy.home=$CI_PROJECT_DIR/sbt-cache/ivy
# If you changed dependencies (especially for scala), you might want to prevent your branch from using old cache by increase the version blew
# gitlab actually use the same technique when you click the `Clear Cache Button`
CACHE_VERSION: ts-15-scala-7
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
BUILDER_IMG_TAG: "$CI_COMMIT_REF_SLUG"
stages:
- builders
- sbt-prebuild
- prebuild
- buildtest
- dockerize
- preview
- deploy-dev
- pre-release
- release
- deploy-staging
- deploy-prod
yarn-install:
stage: builders
image: data61/magda-builder-docker:node14
retry: 1
needs: []
cache:
key: $CI_JOB_NAME-$CACHE_VERSION
paths:
- .yarn
script:
- yarn install --no-progress --child-concurrency 1 --cache-folder .yarn
artifacts:
paths:
- "node_modules"
- "*/node_modules"
- "packages/*/node_modules"
- "yarn.lock"
expire_in: 7 days
build-builder-image:
stage: builders
image: data61/magda-builder-docker:node14
retry: 1
needs: []
before_script:
- ./gitlab-ci-buildx-setup.sh
services:
- docker:dind
script: |
# Build all three builder images and push to gitlab registry
cd magda-builder-nodejs && docker buildx build --push -t $CI_REGISTRY/magda-data/magda/magda-builder-nodejs:$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64 -f Dockerfile .
cd ..
cd magda-builder-docker && docker buildx build --push -t $CI_REGISTRY/magda-data/magda/magda-builder-docker:$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64 -f Dockerfile .
cd ..
cd magda-builder-scala && docker buildx build --push -t $CI_REGISTRY/magda-data/magda/magda-builder-scala:$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64 -f Dockerfile .
cd ..
# Make sure sbt depenencies, plugins are in place, cached (only for this job) and pass to following stage as artifacts
sbt-prebuild:
stage: sbt-prebuild
needs:
- build-builder-image
image: registry.gitlab.com/magda-data/magda/magda-builder-scala:$BUILDER_IMG_TAG
cache:
key: $CI_JOB_NAME-$CACHE_VERSION
paths:
- "$CI_PROJECT_DIR/sbt-cache"
script:
- |
if [ ! -d "$CI_PROJECT_DIR/sbt-cache" ]; then
cp -R /sbt-cache "$CI_PROJECT_DIR/sbt-cache"
mkdir -p "$CI_PROJECT_DIR/sbt-cache/coursier"
cp -R "$CI_PROJECT_DIR/dep-jars/." "$CI_PROJECT_DIR/sbt-cache/coursier/https/"
fi
- sbt update
artifacts:
paths:
- "sbt-cache"
- "target"
- "project/target"
- "project/project/target"
- "*/target"
- "*/project/target"
- "*/project/project/target"
expire_in: 7 days
check-scala-formatting:
stage: prebuild
image: registry.gitlab.com/magda-data/magda/magda-builder-scala:$BUILDER_IMG_TAG
needs:
- build-builder-image
script:
- sbt scalafmtCheckAll
registry-typescript-api:
stage: prebuild
image: registry.gitlab.com/magda-data/magda/magda-builder-scala:$BUILDER_IMG_TAG
needs:
- yarn-install
- sbt-prebuild
script:
- lerna run generate --scope=@magda/typescript-common --stream
artifacts:
paths:
- "magda-typescript-common/src/generated"
expire_in: 7 days
buildtest:search-with-index-cache:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-scala:$BUILDER_IMG_TAG
retry: 2
timeout: 18 minutes
needs:
- sbt-prebuild
before_script:
- |
if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then
export DOCKER_HOST='tcp://localhost:2375'
fi
- docker info
- docker-compose --version
cache:
key: $CI_JOB_NAME-$CACHE_VERSION
paths:
- "$CI_PROJECT_DIR/pip-cache"
services:
- docker:dind
variables:
# allow openssl 1.02 until we upgrade builder to use node12/alpine3.9
CRYPTOGRAPHY_ALLOW_OPENSSL_102: 1
PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
# 2.5gb heap
# unload classes we don't need
# aim for < 1000ms gc pauses (largely ignored)
# use the next-gen collector that every blog on the internet says not to use because we know better than them
# use < 25% of time for GC
# put the ivy cache in the workspace where gitlab can cache it
SBT_OPTS: >
-Xms2500M -Xmx2500M
-XX:+CMSClassUnloadingEnabled
-XX:MaxGCPauseMillis=1000
-XX:+UseG1GC
-XX:GCTimeRatio=3
-Dsbt.global.base=$CI_PROJECT_DIR/sbt-cache/sbtboot
-Dsbt.boot.directory=$CI_PROJECT_DIR/sbt-cache/boot
-Dsbt.ivy.home=$CI_PROJECT_DIR/sbt-cache/ivy
tags:
- heavy
script:
- cd magda-elastic-search
- docker-compose up -d
- cd ..
- sbt -DelasticSearch.serverUrl=elasticsearch://docker:9200 "intTest/testOnly au.csiro.data61.magda.api.*Spec"
- cd magda-elastic-search
- docker-compose down
artifacts:
paths:
- "target"
- "project/target"
- "project/project/target"
- "*/target"
- "*/project/target"
- "*/project/project/target"
expire_in: 7 days
buildtest:search-no-index-cache:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-scala:$BUILDER_IMG_TAG
retry: 2
timeout: 18 minutes
needs:
- sbt-prebuild
before_script:
- |
if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then
export DOCKER_HOST='tcp://localhost:2375'
fi
- docker info
- docker-compose --version
cache:
key: $CI_JOB_NAME-$CACHE_VERSION
paths:
- "$CI_PROJECT_DIR/pip-cache"
services:
- postgres:13.3
- docker:dind
variables:
# allow openssl 1.02 until we upgrade builder to use node12/alpine3.9
CRYPTOGRAPHY_ALLOW_OPENSSL_102: 1
POSTGRES_URL: "jdbc:postgresql://postgres/postgres"
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: "password"
PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
# 2.5gb heap
# unload classes we don't need
# aim for < 1000ms gc pauses (largely ignored)
# use the next-gen collector that every blog on the internet says not to use because we know better than them
# use < 25% of time for GC
# put the ivy cache in the workspace where gitlab can cache it
SBT_OPTS: >
-Xms2500M -Xmx2500M
-XX:+CMSClassUnloadingEnabled
-XX:MaxGCPauseMillis=1000
-XX:+UseG1GC
-XX:GCTimeRatio=3
-Dsbt.global.base=$CI_PROJECT_DIR/sbt-cache/sbtboot
-Dsbt.boot.directory=$CI_PROJECT_DIR/sbt-cache/boot
-Dsbt.ivy.home=$CI_PROJECT_DIR/sbt-cache/ivy
tags:
- heavy
script:
- cd magda-elastic-search
- docker-compose up -d
- cd ..
- sbt -DelasticSearch.serverUrl=elasticsearch://docker:9200 "intTest/testOnly au.csiro.data61.magda.crawler.*Spec au.csiro.data61.magda.indexer.*Spec au.csiro.data61.magda.spatial.*Spec"
- cd magda-elastic-search
- docker-compose down
artifacts:
paths:
- "target"
- "project/target"
- "project/project/target"
- "*/target"
- "*/project/target"
- "*/project/project/target"
expire_in: 7 days
buildtest:ui:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-nodejs:$BUILDER_IMG_TAG
retry: 1
needs:
- yarn-install
- build-builder-image
cache:
paths: []
variables:
REACT_APP_SHA1: "$CI_COMMIT_SHA"
script:
- yarn run eslint
- cd magda-typescript-common && yarn build
- cd ..
- yarn run in-submodules -- -f categories.ui=true -- run build --include-filtered-dependencies
- yarn run in-submodules -- -f categories.ui=true -- run test
artifacts:
paths:
- "*/build"
- "*/dist"
expire_in: 7 days
buildtest:registry:
stage: buildtest
retry: 2
image: registry.gitlab.com/magda-data/magda/magda-builder-scala:$BUILDER_IMG_TAG
needs:
- sbt-prebuild
timeout: 30 minutes
services:
- postgres:13.3
variables:
POSTGRES_URL: "jdbc:postgresql://postgres/postgres"
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: "password"
script:
- sbt "registryApi/testOnly au.csiro.data61.magda.registry.*"
artifacts:
paths:
- "target"
- "project/target"
- "project/project/target"
- "*/target"
- "*/project/target"
- "*/project/project/target"
expire_in: 7 days
buildtest:scala-others:
stage: buildtest
retry: 2
image: registry.gitlab.com/magda-data/magda/magda-builder-scala:$BUILDER_IMG_TAG
needs:
- sbt-prebuild
timeout: 30 minutes
script:
- sbt "common/test"
- sbt "indexer/test"
artifacts:
paths:
- "target"
- "project/target"
- "project/project/target"
- "*/target"
- "*/project/target"
- "*/project/project/target"
expire_in: 7 days
buildtest:typescript-apis-stateless:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-nodejs:$BUILDER_IMG_TAG
retry: 1
needs:
- yarn-install
- build-builder-image
- registry-typescript-api
script:
- cd magda-typescript-common && yarn build && yarn test
- cd ..
- cd magda-minion-framework && yarn build && yarn test
- cd ..
- yarn run in-submodules -- -f language=typescript -f categories.api=true -f categories.stateless=true -- run build --include-filtered-dependencies
- yarn run in-submodules -- -f language=typescript -f categories.api=true -f categories.stateless=true -- run test --include-filtered-dependencies
- yarn run in-submodules -- -f categories.npmPackage=true -f categories.useCommonLib=true -- run build
- yarn run in-submodules -- -f categories.npmPackage=true -f categories.useMinionLib=true -- run build
- yarn run in-submodules -- -f language=typescript -f categories.dockerizedTool=true -- run build --include-filtered-dependencies
- yarn run in-submodules -- -f language=typescript -f categories.dockerizedTool=true -- run test --include-filtered-dependencies
artifacts:
paths:
- "*/dist"
- "packages/*/dist"
- "packages/*/bin"
expire_in: 30 days
buildtest:typescript-apis-with-pg:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 1
needs:
- yarn-install
- build-builder-image
- registry-typescript-api
before_script:
- |
if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then
export DOCKER_HOST='tcp://localhost:2375'
fi
- docker info
- docker-compose --version
cache:
key: $CI_JOB_NAME-$CACHE_VERSION
paths:
- "$CI_PROJECT_DIR/pip-cache"
services:
- postgres:13.3
- docker:dind
variables:
# allow openssl 1.02 until we upgrade builder to use node12/alpine3.9
CRYPTOGRAPHY_ALLOW_OPENSSL_102: 1
PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
POSTGRES_HOST: postgres
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: "password"
PGUSER: postgres
PGPASSWORD: password
OPA_URL: "http://docker:8181/"
script:
- cd magda-opa
- yarn dev -d
- cd ..
- cd magda-typescript-common && yarn build && yarn test
- cd ..
- cd magda-minion-framework && yarn build && yarn test
- cd ..
- yarn run in-submodules -- -f language=typescript -f categories.api=true -f categories.uses-pg=true -- run build --include-filtered-dependencies
- yarn run in-submodules -- -f language=typescript -f categories.api=true -f categories.uses-pg=true -- run test --include-filtered-dependencies
- yarn run in-submodules -- -f categories.npmPackage=true -f categories.useAuthApi=true -- run build
- cd magda-opa
- yarn dev-stop
artifacts:
paths:
- "*/dist"
- "packages/*/dist"
- "packages/*/bin"
expire_in: 7 days
buildtest:typescript-apis-with-es:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 2
needs:
- yarn-install
- build-builder-image
before_script:
- |
if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then
export DOCKER_HOST='tcp://localhost:2375'
fi
- docker info
- docker-compose --version
cache:
key: $CI_JOB_NAME
paths:
- "$CI_PROJECT_DIR/pip-cache"
services:
- docker:dind
variables:
# allow openssl 1.02 until we upgrade builder to use node12/alpine3.9
CRYPTOGRAPHY_ALLOW_OPENSSL_102: 1
PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
TEST_ES_URL: "http://docker:9200"
script:
- cd magda-elastic-search
- docker-compose up -d
- cd ..
- yarn run in-submodules -- -f language=typescript -f categories.api=true -f categories.uses-es=true -- run build --include-filtered-dependencies
# Wait for es to come up
- until $(curl --output /dev/null --silent --head --fail http://docker:9200); do printf '.' sleep 5; done
- curl http://docker:9200
- yarn run in-submodules -- -f language=typescript -f categories.api=true -f categories.uses-es=true -- run test --include-filtered-dependencies
- cd magda-elastic-search
- docker-compose down
artifacts:
paths:
- "*/dist"
expire_in: 30 days
buildtest:storage-api:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 1
needs:
- yarn-install
- build-builder-image
- registry-typescript-api
before_script:
- |
if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then
export DOCKER_HOST='tcp://localhost:2375'
fi
- docker info
- docker-compose --version
cache:
key: $CI_JOB_NAME-$CACHE_VERSION
paths:
- "$CI_PROJECT_DIR/pip-cache"
services:
- docker:dind
variables:
# allow openssl 1.02 until we upgrade builder to use node12/alpine3.9
CRYPTOGRAPHY_ALLOW_OPENSSL_102: 1
PIP_CACHE_DIR: "$CI_PROJECT_DIR/pip-cache"
MINIO_HOST: "docker"
MINIO_PORT: "9000"
script:
- cd magda-storage-api
- docker-compose up -d
- yarn run build
- yarn run test
- docker-compose down
artifacts:
paths:
- "*/dist"
expire_in: 7 days
buildtest:integration-tests:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-scala:$BUILDER_IMG_TAG
retry: 1
needs:
- yarn-install
- build-builder-image
- registry-typescript-api
- sbt-prebuild
- dockerize:dockerExtensions
before_script:
- |
if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then
export DOCKER_HOST='tcp://localhost:2375'
fi
- docker info
- docker-compose --version
# we can remove socat installation in future once the change is merged into master as it's installed in base image
- apk add socat
cache:
key: $CI_JOB_NAME-$CACHE_VERSION
paths:
- "$CI_PROJECT_DIR/pip-cache"
services:
- docker:dind
variables:
POSTGRES_URL: "jdbc:postgresql://localhost/postgres"
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: "password"
tags:
- heavy
script:
- cd magda-authorization-api && yarn build
- cd ..
- cd magda-storage-api && yarn build
- cd ..
- cd magda-migrator-registry-aspects && yarn build
- cd ..
- cd magda-int-test-ts
- yarn test
artifacts:
paths:
- "target"
- "project/target"
- "project/project/target"
- "*/target"
- "*/project/target"
- "*/project/project/target"
expire_in: 7 days
buildtest:opa-policies:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 1
needs:
- yarn-install
- build-builder-image
cache:
paths: []
services:
- docker:dind
script:
- cd magda-opa
- yarn test
buildtest:helm-charts:
stage: buildtest
image: dtzar/helm-kubectl:3.9.0
needs:
- yarn-install
cache:
paths: []
script:
- apk add nodejs npm yarn
- helm repo add magda-io https://charts.magda.io
- yarn update-all-charts
- echo "helm lint magda chart using magda-dev.yml"
- helm lint -f deploy/helm/magda-dev.yml deploy/helm/local-deployment
- echo "helm lint magda chart using minikube-dev.yml"
- helm lint -f deploy/helm/minikube-dev.yml deploy/helm/local-deployment
- echo "helm lint magda chart using preview.yml"
- helm lint -f deploy/helm/preview.yml deploy/helm/local-deployment
- echo "helm lint magda chart using preview-multi-tenant.yml"
- helm lint -f deploy/helm/preview-multi-tenant.yml deploy/helm/local-deployment
artifacts:
paths:
- "deploy/helm/magda/charts"
- "deploy/helm/magda-core/charts"
- "deploy/helm/local-deployment/charts"
- "deploy/helm/local-auth-test-deployment/charts"
expire_in: 7 days
buildtest:helm-docs-check:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
needs:
- build-builder-image
cache:
paths: []
services:
- docker:dind
script:
- code=0
- docker run --rm -v "$(pwd):/helm-docs" -u $(id -u) jnorwood/helm-docs:v1.5.0 || code=$?;
if [ "$code" != "0" ]; then
echo "Failed to run helm-docs!";
exit 1;
fi;
- cd deploy
- code=0
- git ls-files -m | grep -i readme.md || code=$?;
if [ "$code" == "0" ]; then
echo -e "Some of helm chart docs are required to be updated using the [helm-docs](https://github.com/norwoodj/helm-docs) tool. \n
Please run helm-docs (v1.5.0) at project root, review & commit docs changes and push a new commit.";
exit 1;
else
echo -e "helm docs check passed. helm docs update is not required.";
fi;
dockerize:scala:
stage: dockerize
image: registry.gitlab.com/magda-data/magda/magda-builder-scala:$BUILDER_IMG_TAG
retry: 2
needs:
- registry-typescript-api
- sbt-prebuild
- buildtest:registry
- buildtest:search-no-index-cache
- buildtest:search-with-index-cache
services:
- docker:dind
script:
- ./gitlab-ci-buildx-setup.sh
# output stage docker image content without build it
- sbt docker:stage
- cd $CI_PROJECT_DIR/magda-search-api/target/docker/stage && docker buildx build --push -t $CI_REGISTRY/magda-data/magda/magda-search-api:$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64 -f Dockerfile .
- cd $CI_PROJECT_DIR/magda-registry-api/target/docker/stage && docker buildx build --push -t $CI_REGISTRY/magda-data/magda/magda-registry-api:$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64 -f Dockerfile .
- cd $CI_PROJECT_DIR/magda-indexer/target/docker/stage && docker buildx build --push -t $CI_REGISTRY/magda-data/magda/magda-indexer:$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64 -f Dockerfile .
dockerize:ui:
stage: dockerize
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 2
cache:
paths: []
services:
- docker:dind
needs:
- yarn-install
- registry-typescript-api
- buildtest:ui
script:
- ./gitlab-ci-buildx-setup.sh
- cd $CI_PROJECT_DIR/magda-apidocs-server && yarn docker-build-prod --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64
- cd $CI_PROJECT_DIR/magda-web-server && yarn docker-build-prod --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64
dockerize:ui-scss-compiler:
timeout: 120 minutes
stage: dockerize
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 2
cache:
paths: []
services:
- docker:dind
needs:
- yarn-install
- registry-typescript-api
- buildtest:ui
script:
- ./gitlab-ci-buildx-setup.sh
- cd magda-scss-compiler
- yarn docker-build-prod --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64
dockerize:typescript:
stage: dockerize
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 2
cache:
paths: []
services:
- docker:dind
needs:
- yarn-install
- registry-typescript-api
- buildtest:typescript-apis-stateless
- buildtest:typescript-apis-with-pg
- buildtest:typescript-apis-with-es
- buildtest:storage-api
script:
- ./gitlab-ci-buildx-setup.sh
- yarn run in-submodules -- -f categories.api=true -f language=typescript -- run docker-build-prod --include-filtered-dependencies -- -- --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64
- yarn run in-submodules -- -f categories.dockerizedTool=true -f language=typescript -- run docker-build-prod --include-filtered-dependencies -- -- --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64
dockerize:migrators:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 2
needs:
- yarn-install
- build-builder-image
cache:
paths: []
services:
- docker:dind
script:
- ./gitlab-ci-buildx-setup.sh
- yarn run in-submodules -- -f categories.migrator=true -- run docker-build-prod --include-filtered-dependencies -- -- --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64
dockerize:opa:
stage: buildtest
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 1
needs:
- yarn-install
- build-builder-image
- buildtest:opa-policies
cache:
paths: []
before_script:
- ./gitlab-ci-buildx-setup.sh
services:
- docker:dind
script:
- cd magda-opa
- yarn docker-build-prod --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64
dockerize:dockerExtensions:
stage: prebuild
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 2
needs:
- yarn-install
- build-builder-image
cache:
paths: []
services:
- docker:dind
script:
- ./gitlab-ci-buildx-setup.sh
# disable multi-arch docker image build for postgreSQL for now
#- yarn run in-submodules -- -f categories.dockerExtension=true -- run docker-build-prod --include-filtered-dependencies -- -- --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64
- cd $CI_PROJECT_DIR/magda-elastic-search && yarn docker-build-prod --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG --platform linux/arm64,linux/amd64
- cd $CI_PROJECT_DIR/magda-postgres && yarn docker-build-prod --repository=$CI_REGISTRY/magda-data/magda --version=$CI_COMMIT_REF_SLUG
(Full) Run As Preview: &runAsPreview
stage: preview
when: manual
only:
- branches
except:
- main
dependencies:
- buildtest:helm-charts
cache:
paths: []
image:
name: dtzar/helm-kubectl:3.9.0
retry: 1
environment:
name: preview/$CI_COMMIT_REF_NAME
url: https://$CI_COMMIT_REF_SLUG.dev.magda.io
on_stop: Stop Preview
before_script:
# Add PWGEN for generating passwords
- apk add --update pwgen
# Env vars
- MINIO_HOST="${MINIO_HOST:-localhost}"
- MINIO_PORT="${MINIO_PORT:-9000}"
# Kube Config
- echo "$KUBECTL_CONFIG" > kubectlconfig.yaml
- export KUBECONFIG=kubectlconfig.yaml
# Create kube namespace
- kubectl get namespace $CI_COMMIT_REF_SLUG || kubectl create namespace $CI_COMMIT_REF_SLUG
# Create kube secrets
- kubectl create secret docker-registry regcred --namespace $CI_COMMIT_REF_SLUG --docker-server=registry.gitlab.com --docker-username=magdabot --docker-password=$GITLAB_DOCKER_PASSWORD [email protected] --dry-run=client -o json | kubectl apply --namespace $CI_COMMIT_REF_SLUG -f -
- kubectl create secret generic oauth-secrets --from-literal=facebook-client-secret=$FACEBOOK_CLIENT_SECRET --from-literal=google-client-secret=$GOOGLE_CLIENT_SECRET --from-literal arcgis-client-secret=$ARCGIS_CLIENT_SECRET --from-literal aaf-client-secret=$AAF_SECRET --namespace $CI_COMMIT_REF_SLUG --dry-run=client -o json | kubectl apply --namespace $CI_COMMIT_REF_SLUG -f -
- kubectl create secret generic vanguard-secrets --from-literal certificate="$VANGUARD_CERT" --namespace $CI_COMMIT_REF_SLUG --dry-run=client -o json | kubectl apply --namespace $CI_COMMIT_REF_SLUG -f -
- kubectl create secret generic smtp-secret --from-literal=username=$SMTP_USERNAME --from-literal=password=$SMTP_PASSWORD --namespace $CI_COMMIT_REF_SLUG --dry-run=client -o json | kubectl apply --namespace $CI_COMMIT_REF_SLUG -f -
- echo "$DB_SERVICE_ACCOUNT_PRIVATE_KEY" > backup-storage-account.json
- kubectl create secret generic backup-storage-account --from-file backup-storage-account.json --from-literal=GOOGLE_APPLICATION_CREDENTIALS=/etc/wal-g.d/env/backup-storage-account.json --namespace $CI_COMMIT_REF_SLUG --dry-run=client -o json | kubectl apply --namespace $CI_COMMIT_REF_SLUG -f -
script:
# Copy db secrets from master deployment (where backup is created) so that there won't be password issues after db recovery
- CLIENT_DB_PASSWORD=$(kubectl --namespace=default get secret combined-db-password --template={{.data.password}} | base64 -d)
- SUPER_DB_PASSWORD=$(kubectl --namespace=default get secret db-main-account-secret --template='{{index .data "postgresql-password"}}' | base64 -d)
- kubectl create secret generic combined-db-password --from-literal=password=$CLIENT_DB_PASSWORD --dry-run=client -o json | kubectl apply --namespace $CI_COMMIT_REF_SLUG -f -
- kubectl create secret generic db-main-account-secret --from-literal=postgresql-password=$SUPER_DB_PASSWORD --dry-run=client -o json | kubectl apply --namespace $CI_COMMIT_REF_SLUG -f -
- helm upgrade $CI_COMMIT_REF_SLUG deploy/helm/local-deployment --install --recreate-pods --namespace $CI_COMMIT_REF_SLUG -f deploy/helm/preview.yml --set magda.magda-core.authorization-db.migratorBackoffLimit=10,magda.magda-core.registry-db.migratorBackoffLimit=10,global.image.tag=$CI_COMMIT_REF_SLUG,magda.magda-core.combined-db.magda-postgres.postgresql.image.tag=$CI_COMMIT_REF_SLUG,magda.magda-core.ingress.hostname=$CI_COMMIT_REF_SLUG.dev.magda.io,global.externalUrl=https://$CI_COMMIT_REF_SLUG.dev.magda.io,global.namespace=$CI_COMMIT_REF_SLUG --timeout 3600m --wait
- echo "Successfully deployed to https://${CI_COMMIT_REF_SLUG}.dev.magda.io"
(UI) Run As Preview:
<<: *runAsPreview
script:
- helm upgrade $CI_COMMIT_REF_SLUG deploy/helm/local-deployment --install --recreate-pods --namespace $CI_COMMIT_REF_SLUG -f deploy/helm/preview.yml --set global.openfaas.enabled=false,global.image.tag=$CI_COMMIT_REF_SLUG,magda.magda-core.ingress.hostname=$CI_COMMIT_REF_SLUG.dev.magda.io,magda.magda-core.ingress.targetService=web,tags.all=false,tags.web-server=true,tags.correspondence-api=false,magda.magda-core.web-server.registryApiBaseUrlInternal=https://dev.magda.io/api/v0/registry,magda.magda-core.web-server.baseUrl=https://dev.magda.io,global.externalUrl=https://$CI_COMMIT_REF_SLUG.dev.magda.io,magda.magda-core.web-server.useLocalStyleSheet=true --timeout 3600m --wait
- echo "Successfully deployed to https://${CI_COMMIT_REF_SLUG}.dev.magda.io"
(UI - Auto) Run As Preview:
<<: *runAsPreview
when: always
only:
variables:
- $CI_COMMIT_MESSAGE =~ /#deploy-ui-preview/
script:
- helm upgrade $CI_COMMIT_REF_SLUG deploy/helm/local-deployment --install --recreate-pods --namespace $CI_COMMIT_REF_SLUG -f deploy/helm/preview.yml --set global.openfaas.enabled=false,global.image.tag=$CI_COMMIT_REF_SLUG,magda.magda-core.ingress.hostname=$CI_COMMIT_REF_SLUG.dev.magda.io,magda.magda-core.ingress.targetService=web,tags.all=false,tags.web-server=true,tags.correspondence-api=false,magda.magda-core.web-server.baseUrl=https://dev.magda.io,global.externalUrl=https://$CI_COMMIT_REF_SLUG.dev.magda.io,magda.magda-core.web-server.useLocalStyleSheet=true --timeout 3600m --wait
- echo "Successfully deployed to https://${CI_COMMIT_REF_SLUG}.dev.magda.io"
(No Data) Run As Preview:
<<: *runAsPreview
script:
- helm upgrade $CI_COMMIT_REF_SLUG deploy/helm/local-deployment --install --recreate-pods --namespace $CI_COMMIT_REF_SLUG -f deploy/helm/preview.yml --set global.image.tag=$CI_COMMIT_REF_SLUG,magda.magda-core.combined-db.magda-postgres.postgresql.image.tag=$CI_COMMIT_REF_SLUG,magda.magda-core.ingress.hostname=$CI_COMMIT_REF_SLUG.dev.magda.io,magda.magda-core.combined-db.magda-postgres.backupRestore.recoveryMode.enabled=false,magda.magda-core.elasticsearch.useGcsSnapshots=false,global.externalUrl=https://$CI_COMMIT_REF_SLUG.dev.magda.io,global.namespace=$CI_COMMIT_REF_SLUG --timeout 3600m --wait
- echo "Successfully deployed to https://${CI_COMMIT_REF_SLUG}.dev.magda.io"
(No Data) Run As Multi-tenant Preview:
<<: *runAsPreview
script:
- helm upgrade $CI_COMMIT_REF_SLUG deploy/helm/local-deployment --install --recreate-pods --namespace $CI_COMMIT_REF_SLUG -f deploy/helm/preview-multi-tenant.yml --set global.image.tag=$CI_COMMIT_REF_SLUG,magda.magda-core.combined-db.magda-postgres.postgresql.image.tag=$CI_COMMIT_REF_SLUG,magda.magda-core.ingress.hostname=$CI_COMMIT_REF_SLUG.dev.magda.io,magda.magda-core.combined-db.magda-postgres.backupRestore.recoveryMode.enabled=false,magda.magda-core.elasticsearch.useGcsSnapshots=false,global.externalUrl=https://$CI_COMMIT_REF_SLUG.dev.magda.io,global.magdaAdminPortalName=$CI_COMMIT_REF_SLUG.dev.magda.io,global.namespace=$CI_COMMIT_REF_SLUG --timeout 3600m --wait
- echo "Successfully deployed to https://${CI_COMMIT_REF_SLUG}.dev.magda.io"
Stop Preview: &stopPreview
stage: preview
when: manual
only:
- branches
except:
- main
dependencies: []
cache:
paths: []
image:
name: dtzar/helm-kubectl:3.9.0
retry: 1
before_script: []
environment:
name: preview/$CI_COMMIT_REF_NAME
action: stop
script:
- echo "$KUBECTL_CONFIG" > kubectlconfig.yaml
- export KUBECONFIG=kubectlconfig.yaml
- helm --namespace $CI_COMMIT_REF_SLUG del $CI_COMMIT_REF_SLUG
- kubectl delete namespace $CI_COMMIT_REF_SLUG
Deploy Main Branch To Dev:
stage: deploy-dev
only:
- main
cache: {}
needs:
- buildtest:helm-charts
- dockerize:scala
- dockerize:ui
- dockerize:ui-scss-compiler
- dockerize:typescript
- dockerize:migrators
- dockerize:dockerExtensions
- buildtest:integration-tests
image:
name: dtzar/helm-kubectl:3.9.0
retry: 1
before_script: []
environment:
name: dev
url: https://dev.magda.io
script:
- echo "$KUBECTL_CONFIG" > kubectlconfig.yaml
- export KUBECONFIG=kubectlconfig.yaml
- kubectl create secret docker-registry regcred --namespace default --docker-server=registry.gitlab.com --docker-username=magdabot --docker-password=$GITLAB_DOCKER_PASSWORD [email protected] --dry-run=client -o json | kubectl apply --namespace default -f -
- helm upgrade magda deploy/helm/local-deployment --install --recreate-pods -f deploy/helm/magda-dev.yml --timeout 3600m --wait
pre-release:check-release-version:
stage: pre-release
rules:
# Strict Semvar validation. match any version string. Should release version tag
- if: $CI_COMMIT_TAG =~ /^v((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/
variables:
SKIP_CHECK: "false"
# Regex matches non-pre-release version only e.g. v1.0.2; Should release `latest` tag
- if: $CI_COMMIT_TAG =~ /^v([0-9]+)\.([0-9]+)\.([0-9]+)$/
variables:
SKIP_CHECK: "false"
- if: $CI_COMMIT_BRANCH == "main"
variables:
SKIP_CHECK: "true"
- if: $CI_COMMIT_BRANCH == "next"
variables:
SKIP_CHECK: "true"
needs:
- yarn-install
cache: {}
image: registry.gitlab.com/magda-data/magda/magda-builder-nodejs:$BUILDER_IMG_TAG
script: |
if [ "$SKIP_CHECK" == "true" ]; then
echo "Release version is skipped."
else
yarn check-release-version
fi
Release-to-Docker-Hub-Github-Container:
stage: release
services:
- docker:dind
rules:
# Strict Semvar validation. match any version string. Should release version tag
- if: $CI_COMMIT_TAG =~ /^v((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/
variables:
RELEASE_VERSION_TAG: "true"
# Regex matches non-pre-release version only e.g. v1.0.2; Should release `latest` tag
- if: $CI_COMMIT_TAG =~ /^v([0-9]+)\.([0-9]+)\.([0-9]+)$/
variables:
RELEASE_LATEST_TAG: "true"
- if: $CI_COMMIT_BRANCH == "main"
variables:
RELEASE_MAIN_TAG: "true"
- if: $CI_COMMIT_BRANCH == "next"
variables:
RELEASE_NEXT_TAG: "true"
needs:
- pre-release:check-release-version
- yarn-install
- buildtest:helm-charts
- buildtest:helm-docs-check
- dockerize:scala
- dockerize:ui
- dockerize:ui-scss-compiler
- dockerize:typescript
- dockerize:migrators
- dockerize:dockerExtensions
- buildtest:integration-tests
cache: {}
image: registry.gitlab.com/magda-data/magda/magda-builder-docker:$BUILDER_IMG_TAG
retry: 1
script:
- echo "$CI_JOB_TOKEN" | docker login $CI_REGISTRY -u gitlab-ci-token --password-stdin
- echo "$DOCKER_HUB_PASSWORD" | docker login -u magdabot --password-stdin
- echo "$GITHUB_ACCESS_TOKEN" | docker login ghcr.io -u magdabot --password-stdin
- |
if [ "$RELEASE_VERSION_TAG" == "true" ]; then
yarn run retag-and-push -- -- -- --fromPrefix=registry.gitlab.com/magda-data/magda/ --fromVersion=$CI_COMMIT_REF_SLUG --toPrefix=data61/ --copyFromRegistry=true
yarn run retag-and-push -- -- -- --fromPrefix=registry.gitlab.com/magda-data/magda/ --fromVersion=$CI_COMMIT_REF_SLUG --toPrefix=ghcr.io/magda-io/ --copyFromRegistry=true
fi
- |
if [ "$RELEASE_LATEST_TAG" == "true" ]; then
yarn run retag-and-push -- -- -- --fromPrefix=registry.gitlab.com/magda-data/magda/ --fromVersion=$CI_COMMIT_REF_SLUG --toPrefix=data61/ --toVersion=latest --copyFromRegistry=true
yarn run retag-and-push -- -- -- --fromPrefix=registry.gitlab.com/magda-data/magda/ --fromVersion=$CI_COMMIT_REF_SLUG --toPrefix=ghcr.io/magda-io/ --toVersion=latest --copyFromRegistry=true
fi
- |
if [ "$RELEASE_MAIN_TAG" == "true" ]; then
yarn run retag-and-push -- -- -- --fromPrefix=registry.gitlab.com/magda-data/magda/ --fromVersion=$CI_COMMIT_REF_SLUG --toPrefix=data61/ --toVersion=main --copyFromRegistry=true
yarn run retag-and-push -- -- -- --fromPrefix=registry.gitlab.com/magda-data/magda/ --fromVersion=$CI_COMMIT_REF_SLUG --toPrefix=ghcr.io/magda-io/ --toVersion=main --copyFromRegistry=true
fi
- |
if [ "$RELEASE_NEXT_TAG" == "true" ]; then
yarn run retag-and-push -- -- -- --fromPrefix=registry.gitlab.com/magda-data/magda/ --fromVersion=$CI_COMMIT_REF_SLUG --toPrefix=data61/ --toVersion=next --copyFromRegistry=true
yarn run retag-and-push -- -- -- --fromPrefix=registry.gitlab.com/magda-data/magda/ --fromVersion=$CI_COMMIT_REF_SLUG --toPrefix=ghcr.io/magda-io/ --toVersion=next --copyFromRegistry=true
fi
Publish NPM Packages:
stage: release
only:
# Strict Semvar validation
- /^v((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/
except:
- branches
- triggers
needs:
- pre-release:check-release-version
- yarn-install
- buildtest:helm-charts
- buildtest:helm-docs-check
- buildtest:typescript-apis-stateless
- buildtest:typescript-apis-with-pg
- dockerize:scala
- dockerize:ui
- dockerize:ui-scss-compiler
- dockerize:typescript
- dockerize:migrators
- dockerize:dockerExtensions
- buildtest:integration-tests
image:
name: registry.gitlab.com/magda-data/magda/magda-builder-nodejs:$BUILDER_IMG_TAG
cache: {}
script:
# Setup NPM token & scoped registry
- npm config set @magda:registry https://registry.npmjs.org/
- npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
- yarn run in-submodules -f categories.npmPackage=true run release
Publish Helm Chart:
stage: release
rules:
# Strict Semvar validation. match any version string. Should release version tag
- if: $CI_COMMIT_TAG =~ /^v((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/
needs:
- pre-release:check-release-version
- yarn-install
- buildtest:helm-charts
- buildtest:helm-docs-check
- dockerize:scala
- dockerize:ui
- dockerize:ui-scss-compiler
- dockerize:typescript
- dockerize:migrators
- dockerize:dockerExtensions
- buildtest:integration-tests
image:
name: dtzar/helm-kubectl:3.9.2
retry: 1
script: |
# release helm charts to github container registry
echo "$GITHUB_ACCESS_TOKEN" | helm registry login -u magdabot ghcr.io/magda-io --password-stdin
cd deploy/helm
# release magda-core helm chart
helm package magda-core
PKG_NAME=`ls *.tgz`
helm push ${PKG_NAME} oci://ghcr.io/magda-io/charts
unlink ${PKG_NAME}
# release magda helm chart
helm package magda
PKG_NAME=`ls *.tgz`
helm push ${PKG_NAME} oci://ghcr.io/magda-io/charts
unlink ${PKG_NAME}
# release magda-common helm chart
helm package magda-common
PKG_NAME=`ls *.tgz`
helm push ${PKG_NAME} oci://ghcr.io/magda-io/charts