forked from appsemble/appsemble
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
1186 lines (1119 loc) · 44.8 KB
/
.gitlab-ci.yml
File metadata and controls
1186 lines (1119 loc) · 44.8 KB
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
default:
image: node:20.18-bookworm-slim@sha256:ffc11dbf16dd0abcbb7b837410601b4d5592db2d03741e13a4a5336ab74d7ccb
stages:
- cleanup
- build
- test
- end 2 end
- publish
- deploy
- provision
- performance
- backup
variables:
BACKUPS_LOCATION: hetzner-s3:appsemble/backups
PROD_BACKUP_NAME: appsemble_prod_backup
workflow:
rules:
# By default, run jobs for every merge request.
- if: $CI_MERGE_REQUEST_ID
# By default, run jobs for every commit on main.
- if: $CI_COMMIT_BRANCH == 'main'
# By default, run jobs for every commit on staging.
- if: $CI_COMMIT_BRANCH == 'staging'
# By default, run jobs for every tag
- if: $CI_COMMIT_TAG
###################################################################################################
# Job Templates #
###################################################################################################
# A preset for running Docker in Docker.
.docker:
interruptible: true
services:
- docker:dind@sha256:1e9d444274b295261e49f96635f3d56a615cb3ae2021204160f8ac3cdf8f3b58
image: docker@sha256:1e9d444274b295261e49f96635f3d56a615cb3ae2021204160f8ac3cdf8f3b58
dependencies: []
before_script:
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
# A preconfigured environment for using npm.
.npm:
interruptible: true
dependencies: [npm_ci]
needs:
- job: npm_ci
artifacts: true
# A template for creating a minor or patch release
.release:
extends: .npm
stage: publish
rules:
- if: $CI_COMMIT_BRANCH == 'main'
when: manual
allow_failure: true
script:
- apt-get update
- apt-get install --yes git gnupg
- gpg --import "$GPG_PRIVATE_KEY"
- |
if [ -n "$IDENTIFIER" ]; then
npm run scripts -- release "$INCREMENT" --identifier "$IDENTIFIER"
else
npm run scripts -- release "$INCREMENT"
fi
- npm install
- VERSION="$(npm --silent run appsemble -- --version)"
- |
MESSAGE="$VERSION
$(npm --silent run scripts get-release-notes)"
- git config user.email bot@appsemble.com
- git config user.name Appsemble
- git add .
- git commit --message "$MESSAGE" --cleanup whitespace --gpg-sign
- git tag "$VERSION" --message "$MESSAGE" --cleanup whitespace --sign
- git push "https://appsemble-bot:$GITLAB_ACCESS_TOKEN@gitlab.com/appsemble/appsemble" HEAD:main
- |
if [ $? -eq 0 ]; then
echo "Code push successful. Pushing tags..."
git push "https://appsemble-bot:$GITLAB_ACCESS_TOKEN@gitlab.com/appsemble/appsemble" --tags
else
echo "Push to main branch failed. Tags will not be pushed."
fi
###################################################################################################
# Build Stage #
###################################################################################################
npm_ci:
stage: build
cache:
key:
files:
- package-lock.json
paths:
- node_modules/
- '**/node_modules'
- /root/.npm/
artifacts:
paths:
- node_modules/
- '**/node_modules'
expire_in: 1 day
script:
- npm ci
# Build the Docker image.
build docker image:
extends: .docker
stage: build
cache:
key: '$CI_COMMIT_REF_NAME'
paths:
- /root/.npm/
script:
# https://docs.gitlab.com/ee/ci/docker/docker_layer_caching.html
# We're pulling latest if no previous builds exist because we want the greatest possibility of cache hits for build layers.
- CACHE_IMAGE="$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
# We wouldn't like anything funny to happen to us because of cache
- if [ "$CI_COMMIT_REF_NAME" == "main" ] || [ "$CI_COMMIT_REF_NAME" == "staging" ]; then USE_CACHE="0"; else USE_CACHE="1"; fi
- if ! docker pull "$CACHE_IMAGE"; then CACHE_IMAGE="$CI_REGISTRY_IMAGE:latest"; docker pull "$CACHE_IMAGE" || true; fi
- docker build
-t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
--cache-from "$CACHE_IMAGE"
--build-arg "BUILDKIT_INLINE_CACHE=$USE_CACHE"
--build-arg "version=$CI_COMMIT_REF_NAME"
--build-arg "date=$CI_JOB_STARTED_AT" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
# Build the npm packages that should be published.
pack:
extends: .npm
stage: build
script:
- mkdir build/
- npm --pack-destination build --workspace @appsemble/types pack
- npm --pack-destination build --workspace @appsemble/sdk pack
- npm --pack-destination build --workspace @appsemble/lang-sdk pack
- npm --pack-destination build --workspace @appsemble/preact pack
- npm --pack-destination build --workspace @appsemble/utils pack
- npm --pack-destination build --workspace @appsemble/node-utils pack
- npm --pack-destination build --workspace @appsemble/webpack-config pack
- npm --pack-destination build --workspace @appsemble/cli pack
- npm --pack-destination build --workspace @appsemble/tsconfig pack
- npm --pack-destination build --workspace @appsemble/e2e pack
- npm --pack-destination build --workspace appsemble pack
- npm --pack-destination build --workspace create-appsemble pack
- npm run scripts -- validate-packaged-exports build/*
- find build -mindepth 1 -maxdepth 1 -type d -exec rm -r {} +
artifacts:
name: npm packages
expose_as: packages
paths:
- build/
# Package the Helm chart
helm package:
image: dtzar/helm-kubectl:3@sha256:569fbcea3ad1bdb26c953dc76e24591e9ac06abaf577e9f9167a0517e7669425
stage: build
needs: []
script:
- cp LICENSE.md config/charts/appsemble/
- config/bin/helm-package.sh --dependency-update --destination public config/charts/appsemble/
artifacts:
name: Helm chart
expose_as: Helm chart
paths:
- public/
###################################################################################################
# Test Stage #
###################################################################################################
# Spell check using cspell
cspell:
extends: .npm
stage: test
script:
- npx -- cspell
# Lint JavaScript code using ESLint.
eslint:
extends: .npm
stage: test
script:
- npx -- eslint --format gitlab .
artifacts:
reports:
codequality: gl-codequality.json
# Lint Helm charts.
helm lint:
image: dtzar/helm-kubectl:3@sha256:569fbcea3ad1bdb26c953dc76e24591e9ac06abaf577e9f9167a0517e7669425
stage: test
needs: []
script:
- helm lint config/charts/*
# Lint shell scripts
shellcheck:
image: koalaman/shellcheck-alpine@sha256:71e5a217c94204e164da3a89cc83ac0212dc06549f37af61b298273036bbab6f
stage: test
needs: []
script:
- printf "Evaluating:\n$(find . -name '*.sh')"
- find . -name '*.sh' | xargs shellcheck
# Verify app messages are in sync with the app definition.
i18n:
extends: .npm
stage: test
script:
- npm run appsemble -- app extract-messages --verify nl apps/*
# Check formatting using prettier.
prettier:
extends: .npm
stage: test
script:
- npx -- prettier .
# Lint Markdown using remark.
remark lint:
extends: .npm
stage: test
script:
- npx -- remark --frail --no-stdout .
# Lint CSS using stylelint.
stylelint:
extends: .npm
stage: test
script:
- npx -- stylelint .
# Run unittests using NodeJS.
test node:
extends: .npm
services:
- postgres:15@sha256:b8e11f8a8b383e19589a086a78b10f9ca69a39d6c9dcdd9342a8697544e8b3a0
- name: minio/minio:latest@sha256:a1ea29fa28355559ef137d71fc570e508a214ec84ff8083e39bc5428980b015e
alias: minio
command: ['server', '/data']
variables:
MINIO_ROOT_USER: admin
MINIO_ROOT_PASSWORD: password
variables:
POSTGRES_DB: testAppsemble
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
DATABASE_URL: 'postgres://admin:password@postgres:5432/testAppsemble'
S3_HOST: 'minio'
S3_PORT: 9000
stage: test
script:
- npm test -- --no-file-parallelism --coverage --shard=$CI_NODE_INDEX/$CI_NODE_TOTAL
parallel: 9
artifacts:
paths:
- coverage
reports:
junit: junit.xml
coverage_report:
coverage_format: cobertura
path: coverage/cobertura-coverage.xml
# Check type validity for our TypeScript files.
tsc:
extends: .npm
stage: test
script:
- npx --workspaces tsc
# Check type validity for our TypeScript files.
validate:
extends: .npm
stage: test
script:
- npm run scripts -- validate
# Check migrations are in sync with Sequelize models
check migrations:
extends: .npm
stage: test
interruptible: true
services:
- postgres:15@sha256:b8e11f8a8b383e19589a086a78b10f9ca69a39d6c9dcdd9342a8697544e8b3a0
variables:
FORCE_COLOR: '1' # Required for Chalk.js
POSTGRES_DB: testAppsemble
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
DATABASE_URL: 'postgres://admin:password@postgres:5432/testAppsemble'
script:
- npm run appsemble -- check-migrations
# Check down migrations
check down migrations:
extends: .npm
stage: test
interruptible: true
services:
- postgres:15@sha256:b8e11f8a8b383e19589a086a78b10f9ca69a39d6c9dcdd9342a8697544e8b3a0
variables:
FORCE_COLOR: '1' # Required for Chalk.js
POSTGRES_DB: testAppsemble
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
DATABASE_URL: 'postgres://admin:password@postgres:5432/testAppsemble'
script:
- npm run appsemble -- check-down-migrations
# Fuzz test migrations for anomalous up and down migration failures
fuzz migrations:
extends: .npm
stage: test
interruptible: true
services:
- postgres:15@sha256:b8e11f8a8b383e19589a086a78b10f9ca69a39d6c9dcdd9342a8697544e8b3a0
variables:
POSTGRES_DB: testAppsemble
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
DATABASE_URL: 'postgres://admin:password@postgres:5432/testAppsemble'
script:
- npm run appsemble -- fuzz-migrations
include:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Jobs/Container-Scanning.gitlab-ci.yml
# https://docs.gitlab.com/ee/user/application_security/container_scanning
# Uses https://github.com/aquasecurity/trivy
# The 'latest' template is used to enable merge-request scanning
# The generated report is used for https://gitlab.com/appsemble/security-policy-management/-/blob/main/.gitlab/security-policies/policy.yml
- template: Jobs/Container-Scanning.latest.gitlab-ci.yml
container_scanning:
needs:
- build docker image
variables:
GIT_STRATEGY: fetch
CS_DISABLE_LANGUAGE_VULNERABILITY_SCAN: false
CS_IMAGE: '$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG'
validate-snippets:
stage: test
interruptible: true
needs:
- build docker image
rules:
- if: $CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_SOURCE_PROJECT_PATH == 'appsemble/appsemble'
- if: $CI_COMMIT_TAG
variables:
FF_NETWORK_PER_BUILD: 'true'
DATABASE_HOST: database
DATABASE_PORT: 5432
DATABASE_NAME: appsemble
DATABASE_USER: admin
DATABASE_PASSWORD: password
services:
- name: postgres:15@sha256:b8e11f8a8b383e19589a086a78b10f9ca69a39d6c9dcdd9342a8697544e8b3a0
alias: database
variables:
POSTGRES_DB: appsemble
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
- name: minio/minio:latest@sha256:a1ea29fa28355559ef137d71fc570e508a214ec84ff8083e39bc5428980b015e
alias: minio
entrypoint: ['sh', '-c', 'minio server /data']
variables:
MINIO_ROOT_USER: admin
MINIO_ROOT_PASSWORD: password
- name: '$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG'
alias: appsemble
variables:
SECRET: secret
AES_SECRET: secret
HOST: 'http://appsemble:9999'
REMOTE: 'https://appsemble.app'
DATABASE_HOST: database
DATABASE_PORT: 5432
DATABASE_NAME: appsemble
DATABASE_USER: admin
DATABASE_PASSWORD: password
S3_HOST: minio
S3_SECURE: false
S3_ACCESS_KEY: admin
S3_SECRET_KEY: password
migrateTo: next
script:
- npm ci
- npm run scripts seed-account --
--name $BOT_ACCOUNT_NAME
--email $BOT_ACCOUNT_EMAIL
--password $BOT_ACCOUNT_PASSWORD
--timezone Europe/Amsterdam
--clientCredentials $APPSEMBLE_CLIENT_CREDENTIALS
- npm run appsemble -- config set remote 'http://appsemble:9999'
- npm run appsemble -- organization create appsemble
--description "The open source low-code app building platform"
--email support@appsemble.com
--icon packages/server/assets/appsemble.png
--name Appsemble
--website https://appsemble.com
- npm run appsemble -- block publish 'blocks/*'
- npm run scripts -- validate-docs --organization appsemble --remote 'http://appsemble:9999' -vv
###################################################################################################
# End 2 End Stage #
###################################################################################################
e2e:
stage: end 2 end
image: mcr.microsoft.com/playwright:v1.51.1-jammy@sha256:79da45705a7c3f147c435ac6d0beeddf2e132f53263cb27bed90beafbb2e552b
interruptible: true
needs:
- build docker image
rules:
- if: $CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_SOURCE_PROJECT_PATH == 'appsemble/appsemble'
- if: $CI_COMMIT_TAG
variables:
FF_NETWORK_PER_BUILD: 'true'
DATABASE_HOST: database
DATABASE_PORT: 5432
DATABASE_NAME: appsemble
DATABASE_USER: admin
DATABASE_PASSWORD: password
E2E_HOST: 'http://appsemble:9999'
services:
- name: postgres:15@sha256:b8e11f8a8b383e19589a086a78b10f9ca69a39d6c9dcdd9342a8697544e8b3a0
alias: database
variables:
POSTGRES_DB: appsemble
POSTGRES_USER: admin
POSTGRES_PASSWORD: password
- name: minio/minio:latest@sha256:a1ea29fa28355559ef137d71fc570e508a214ec84ff8083e39bc5428980b015e
alias: minio
entrypoint: ['sh', '-c', 'minio server /data']
variables:
MINIO_ROOT_USER: admin
MINIO_ROOT_PASSWORD: password
- name: '$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG'
alias: appsemble
variables:
SECRET: secret
AES_SECRET: secret
HOST: 'http://appsemble:9999'
REMOTE: 'https://appsemble.app'
DATABASE_HOST: database
DATABASE_PORT: 5432
DATABASE_NAME: appsemble
DATABASE_USER: admin
DATABASE_PASSWORD: password
S3_HOST: minio
S3_SECURE: false
S3_ACCESS_KEY: admin
S3_SECRET_KEY: password
migrateTo: next
E2E: true
before_script:
- apt-get update && apt-get install -y curl dnsutils
- |
echo "Aliasing app domains to appsemble..."
APPSEMBLE_IP=$(getent hosts appsemble | awk '{ print $1 }')
for APP_NAME in ./apps/*/; do
APP_NAME=$(basename "$APP_NAME")
CUSTOM_ALIAS="${APP_NAME}.appsemble.appsemble"
echo "$APPSEMBLE_IP $CUSTOM_ALIAS" >> /etc/hosts
echo "Added alias: $CUSTOM_ALIAS -> $APPSEMBLE_IP"
done
script:
- npm ci
- npm run scripts seed-account --
--name $BOT_ACCOUNT_NAME
--email $BOT_ACCOUNT_EMAIL
--password $BOT_ACCOUNT_PASSWORD
--timezone Europe/Amsterdam
--clientCredentials $APPSEMBLE_CLIENT_CREDENTIALS
- npm run appsemble -- config set context e2e
- npm run appsemble -- config set remote 'http://appsemble:9999'
- npm run appsemble -- organization create appsemble
--description "The open source low-code app building platform"
--email support@appsemble.com
--icon packages/server/assets/appsemble.png
--name Appsemble
--website https://appsemble.com
- npm run appsemble -- block publish 'blocks/*'
- npm run appsemble -- app publish 'apps/empty' --modify-context
- npm run appsemble -- app publish 'apps/holidays' --modify-context
- npm run appsemble -- app publish 'apps/notes' --modify-context
- npm run appsemble -- app publish 'apps/person' --modify-context
- npm run appsemble -- app publish 'apps/survey' --modify-context
- npm run appsemble -- app publish 'apps/unlittered' --modify-context
- npm --workspace @appsemble/types run prepack
- npm --workspace @appsemble/lang-sdk run prepack
- npm --workspace @appsemble/e2e run e2e -- --max-failures 6
artifacts:
expose_as: Playwright videos
when: always
paths:
- packages/e2e/test-results/
reports:
junit: packages/e2e/results.xml
# Apps under SLA are supported through Appsemble core changes
e2e apps obligatory:
allow_failure: false
stage: end 2 end
needs:
- build docker image
rules:
- if: $CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_SOURCE_PROJECT_PATH == 'appsemble/appsemble'
- if: $CI_COMMIT_TAG
inherit:
variables: false
variables:
APPSEMBLE_IMAGE: '$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG'
parallel:
matrix:
- PROJECT:
- 'appsemble/apps/sittard-geleen'
- 'appsemble/apps/restaurants'
- 'appsemble/apps/minjus'
- 'appsemble/apps/sounding-bodies'
trigger:
project: $PROJECT
strategy: depend
branch: main
# Allow failure as we don't support these anymore
e2e apps manual:
when: manual
allow_failure: true
stage: end 2 end
needs:
- build docker image
rules:
- if: $CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_SOURCE_PROJECT_PATH == 'appsemble/appsemble'
- if: $CI_COMMIT_TAG
inherit:
variables: false
variables:
APPSEMBLE_IMAGE: '$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG'
parallel:
matrix:
- PROJECT:
- 'appsemble/apps/template'
- 'appsemble/apps/eindhoven'
- 'appsemble/apps/amersfoort'
- 'appsemble/apps/tbvwonen'
trigger:
project: $PROJECT
strategy: depend
branch: main
###################################################################################################
# Publish Stage #
###################################################################################################
twitter:
extends: .npm
stage: publish
# This is new and mainly used to update nice-to-have metadata.
# Allow failure to prevent blocking of important jobs.
allow_failure: true
rules:
- if: $CI_COMMIT_TAG
script:
- npm run scripts -- twitter
# Update metadata on Docker Hub
docker metadata:
extends: .npm
stage: publish
# This is new and mainly used to update nice-to-have metadata.
# Allow failure to prevent blocking of important jobs.
allow_failure: true
rules:
- if: $CI_COMMIT_TAG
script:
- npm run scripts -- docker-metadata
# Create a GitHub release
github release:
extends: .npm
stage: publish
# This is new and mainly used to update nice-to-have metadata.
# Allow failure to prevent blocking of important jobs.
allow_failure: true
rules:
- if: $CI_COMMIT_TAG
script:
- npm run scripts -- github-release
# Create a GitLab release
gitlab release:
extends: .npm
stage: publish
# This is new and mainly used to update nice-to-have metadata.
# Allow failure to prevent blocking of important jobs.
allow_failure: true
rules:
- if: $CI_COMMIT_TAG
script:
- npm run scripts -- gitlab-release
publish docker:
extends: .docker
stage: publish
needs:
- build docker image
variables:
GIT_STRATEGY: none
rules:
- if: $CI_COMMIT_TAG
script:
- echo $DOCKER_HUB_PASSWORD | docker login -u $DOCKER_HUB_USERNAME --password-stdin
- docker pull "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
- docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" "$CI_REGISTRY_IMAGE:latest"
- docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
- docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" "appsemble/appsemble:latest"
- docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" "appsemble/appsemble:$CI_COMMIT_TAG"
- docker push "$CI_REGISTRY_IMAGE:latest"
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG"
- docker push "appsemble/appsemble:latest"
- docker push "appsemble/appsemble:$CI_COMMIT_TAG"
# Publish the Helm chart to https://charts.appsemble.com
publish helm:
image: dtzar/helm-kubectl:3@sha256:569fbcea3ad1bdb26c953dc76e24591e9ac06abaf577e9f9167a0517e7669425
needs:
- helm package
stage: publish
variables:
GIT_STRATEGY: none
rules:
- if: $CI_COMMIT_TAG
script:
- apk add git gnupg
- gpg --import "$GPG_PRIVATE_KEY"
- git init
- git remote add origin "https://appsemble-bot:$GITLAB_ACCESS_TOKEN@gitlab.com/appsemble/charts.git"
- git fetch --depth 1
- git checkout --track origin/main
- git config commit.gpgSign true
- git config user.email bot@appsemble.com
- git config user.name Appsemble
- git add public
- git commit --message "Add Appsemble Helm chart $CI_COMMIT_TAG"
- git push origin main
- helm repo add appsemble https://charts.appsemble.com
- | # Wait until the chart has been published downstream
while ! helm show all 'appsemble/appsemble' --version "$CI_COMMIT_TAG" 2> /dev/null; do
sleep 3
echo retrying in 3 seconds…
helm repo update > /dev/null
done
# Publish npm packages to npmjs.org.
publish npm:
stage: publish
needs:
- job: pack
artifacts: true
variables:
GIT_STRATEGY: none
rules:
- if: $CI_COMMIT_TAG
id_tokens:
SIGSTORE_ID_TOKEN:
aud: sigstore
script:
- npm config set //registry.npmjs.org/:_authToken "$NPM_TOKEN"
- |
if echo "$CI_RUNNED_TAGS" | grep -q "self-hosted"; then
PROVENANCE_FLAG=""
echo "Detected self-hosted tag, skipping provenance"
else
PROVENANCE_FLAG="--provenance"
echo "No self-hosted tag detected, enabling provenance"
fi
echo "Using provenance flag: '$PROVENANCE_FLAG'"
find ./build -name "*.tgz" -print0 | xargs -0 -I{} sh -c 'npm publish "{}" --access public '"$PROVENANCE_FLAG"''
# Perform various post release actions.
sentry release:
needs: []
image:
name: getsentry/sentry-cli:2@sha256:2a60d341709d8ae040b842556c66f98443cc6d59101cab751f9811f3a1df9362
entrypoint: [/bin/sh, -c]
stage: publish
rules:
- if: $CI_COMMIT_TAG
script:
- sentry-cli releases new --finalize "$CI_COMMIT_TAG"
- sentry-cli releases set-commits --auto "$CI_COMMIT_TAG"
# Create a test pre-release
release test:
extends: .release
variables:
INCREMENT: prerelease
IDENTIFIER: test
# Create a patch release
release patch:
extends: .release
variables:
INCREMENT: patch
# Create a minor release
release minor:
extends: .release
variables:
INCREMENT: minor
###################################################################################################
# Deploy Stage #
###################################################################################################
# Update lockfile and fix formatting where possible
update dependencies:
stage: deploy
variables:
GIT_STRATEGY: none
rules:
- if: $CI_PIPELINE_SOURCE == 'schedule' && $UPDATE_PROJECT_DEPS == 'true'
cache:
policy: push
key:
files:
- package-lock.json
paths:
- node_modules
- '**/node_modules'
script:
- apt update
- apt install --yes git gnupg
- gpg --import "$GPG_PRIVATE_KEY"
- git init
- git remote add origin "https://appsemble-bot:$GITLAB_ACCESS_TOKEN@gitlab.com/appsemble/appsemble.git"
- git fetch --depth 1
- git checkout -B update-lockfile origin/main
- git config commit.gpgSign true
- git config user.email bot@appsemble.com
- git config user.name Appsemble
- rm package-lock.json
- npm install --ignore-scripts
- npx -- eslint --fix . || true
- npx -- remark . -o || true
- npx -- stylelint --fix . || true
- npx -- prettier --write . || true
- git commit --all --message 'Update package-lock.json'
- git push --force origin update-lockfile
-o merge_request.create
-o merge_request.label=Chore
-o merge_request.merge_when_pipeline_succeeds
-o merge_request.remove_source_branch
# Deploy the Docker image for a branch to a review environment.
review:
image: dtzar/helm-kubectl:3.16.0@sha256:3d0876a8a4159fddfb381fcccf23c774bcfcd4b4ffdbb80c1a5c10c1eb23de54
stage: deploy
needs:
- build docker image
- job: helm package
artifacts: true
rules:
- if: $CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_SOURCE_PROJECT_PATH == 'appsemble/appsemble'
environment:
name: review/$CI_MERGE_REQUEST_IID
url: https://$CI_MERGE_REQUEST_IID.appsemble.review
on_stop: stop review
auto_stop_in: 1 day
variables:
GIT_STRATEGY: none
script:
- kubectl config use-context "$CI_PROJECT_PATH:development"
- kubectl config set-context --current --namespace review
# This is the only way to make sure the review environment can be overwritten
- helm delete "review-$CI_MERGE_REQUEST_IID" || true
- kubectl delete pvc --selector "app.kubernetes.io/instance=review-$CI_MERGE_REQUEST_IID" || true
- kubectl delete namespace "companion-containers-review-$CI_MERGE_REQUEST_IID" || true
- kubectl delete secret review-$CI_MERGE_REQUEST_IID-mailpit-tls || true
- apk add --no-cache openssl
- openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mailpit.key -out mailpit.crt -subj "/CN=review-${CI_MERGE_REQUEST_IID}-mailpit-smtp" -addext "subjectAltName=DNS:review-${CI_MERGE_REQUEST_IID}-mailpit-smtp"
- kubectl create secret tls review-$CI_MERGE_REQUEST_IID-mailpit-tls --cert=mailpit.crt --key=mailpit.key --dry-run=client -o yaml | kubectl apply -f -
- rm mailpit.key mailpit.crt
# default bitnami postgresql PVC size is 8Gi, but that much should not be needed for a review environment
- helm install "review-$CI_MERGE_REQUEST_IID" ./public/appsemble-*.tgz
--debug
--atomic
--set "fullnameOverride=review-$CI_MERGE_REQUEST_IID"
--set "gitlab.app=$CI_PROJECT_PATH_SLUG"
--set "gitlab.env=$CI_ENVIRONMENT_SLUG"
--set "image.pullPolicy=Always"
--set "image.repository=$CI_REGISTRY_IMAGE"
--set "image.tag=$CI_COMMIT_REF_SLUG"
--set "ingress.clusterIssuer=acme-issuer-dev"
--set "ingress.enabled=true"
--set "ingress.host=${CI_ENVIRONMENT_URL/https:\/\//}"
--set "ingress.tls.secretName=review-$CI_MERGE_REQUEST_IID-tls"
--set "ingress.tls.wildcardSecretName=review-$CI_MERGE_REQUEST_IID-tls-wildcard"
--set "migrateTo=next"
--set "global.postgresql.auth.existingSecret=postgresql-secret"
--set "postgresql.primary.persistence.size=1Gi"
--set "provision.organization.id=appsemble"
--set "provision.user.organizationRole=Maintainer"
--set "provision.user.clientCredentials=$APPSEMBLE_CLIENT_CREDENTIALS"
--set "provision.user.email=$BOT_ACCOUNT_EMAIL"
--set "provision.user.name=$BOT_ACCOUNT_NAME"
--set "provision.user.password=$BOT_ACCOUNT_PASSWORD"
--set "provision.user.timezone=Europe/Amsterdam"
--set "postgresql.fullnameOverride=review-$CI_MERGE_REQUEST_IID-postgresql"
--set "proxy=true"
--set "remote=https://appsemble.app"
--set "sentry.allowedDomains={*.appsemble.review}"
--set "sentry.environment=review-$CI_MERGE_REQUEST_IID"
--set "sentry.secret=sentry"
--set "mailpit.mailpit.smtp.tls.secretName=review-$CI_MERGE_REQUEST_IID-mailpit-tls"
--set "minio.persistence.size=1Gi"
--set "minio.fullnameOverride=review-$CI_MERGE_REQUEST_IID-minio"
--set "minio.ingress.hostname=console.minio.${CI_ENVIRONMENT_URL/https:\/\//}"
--set "minio.ingress.annotations.cert-manager\\.io/cluster-issuer=acme-issuer-dev"
--set "minio.apiIngress.hostname=api.minio.${CI_ENVIRONMENT_URL/https:\/\//}"
--set "minio.apiIngress.annotations.cert-manager\\.io/cluster-issuer=acme-issuer-dev"
--set "minio.apiIngress.annotations.nginx\\.ingress\\.kubernetes\\.io/proxy-body-size=256m"
# Stop a review environment.
stop review:
image: dtzar/helm-kubectl:3@sha256:569fbcea3ad1bdb26c953dc76e24591e9ac06abaf577e9f9167a0517e7669425
dependencies: []
stage: deploy
rules:
- if: $CI_MERGE_REQUEST_ID && $CI_MERGE_REQUEST_SOURCE_PROJECT_PATH == 'appsemble/appsemble'
when: manual
allow_failure: true
environment:
name: review/$CI_MERGE_REQUEST_IID
action: stop
variables:
GIT_STRATEGY: none
script:
- kubectl config use-context "$CI_PROJECT_PATH:development"
- kubectl config set-context --current --namespace review
- helm delete "review-$CI_MERGE_REQUEST_IID"
- kubectl delete pvc --selector "app.kubernetes.io/instance=review-$CI_MERGE_REQUEST_IID"
- kubectl delete namespace "companion-containers-review-$CI_MERGE_REQUEST_IID" || true
- kubectl get secrets --no-headers -o custom-columns=:metadata.name | grep "^review-$CI_MERGE_REQUEST_IID" | xargs -I{} kubectl delete secret {} || true
# Deploy the Docker image for main to the staging environment.
staging:
image: dtzar/helm-kubectl:3@sha256:569fbcea3ad1bdb26c953dc76e24591e9ac06abaf577e9f9167a0517e7669425
stage: deploy
needs:
- build docker image
- job: helm package
artifacts: true
rules:
- if: $CI_COMMIT_BRANCH == 'staging'
environment:
name: staging
url: https://staging.appsemble.review
variables:
GIT_STRATEGY: none
script:
- kubectl config use-context "$CI_PROJECT_PATH:development"
- kubectl config set-context --current --namespace staging
# This is the only way to make sure staging can be overwritten
- helm delete staging || true
- kubectl delete pvc --selector "app.kubernetes.io/instance=staging" || true
- kubectl delete namespace "companion-containers-staging" || true
- kubectl delete secret staging-mailpit-tls || true
- apk add --no-cache openssl
- openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mailpit.key -out mailpit.crt -subj "/CN=staging-appsemble-mailpit-smtp" -addext "subjectAltName=DNS:staging-appsemble-mailpit-smtp"
- kubectl create secret tls staging-mailpit-tls --cert=mailpit.crt --key=mailpit.key --dry-run=client -o yaml | kubectl apply -f -
- rm mailpit.key mailpit.crt
- helm install staging ./public/appsemble-*.tgz
--atomic
--timeout 15m0s
--set "gitlab.app=$CI_PROJECT_PATH_SLUG"
--set "gitlab.env=$CI_ENVIRONMENT_SLUG"
--set "global.postgresql.auth.existingSecret=postgresql-secret"
--set "image.pullPolicy=Always"
--set "image.repository=$CI_REGISTRY_IMAGE"
--set "image.tag=staging"
--set "ingress.clusterIssuer=acme-issuer-dev"
--set "ingress.enabled=true"
--set "ingress.host=staging.appsemble.review"
--set "ingress.tls.secretName=staging-tls"
--set "ingress.tls.wildcardSecretName=staging-tls-wildcard"
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/proxy-body-size=1G"
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/force-ssl-redirect=\"true\""
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/ssl-redirect=\"true\""
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/hsts=\"true\""
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/hsts-include-subdomains=\"true\""
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/hsts-max-age=\"31536000\""
--set "migrateTo=next"
--set "oauthSecret=oauth2"
--set "postgresql.fullnameOverride=staging-postgresql"
--set "provision.organization.id=appsemble"
--set "provision.user.organizationRole=Maintainer"
--set "provision.user.clientCredentials=$APPSEMBLE_CLIENT_CREDENTIALS"
--set "provision.user.email=$BOT_ACCOUNT_EMAIL"
--set "provision.user.name=$BOT_ACCOUNT_NAME"
--set "provision.user.password=$BOT_ACCOUNT_PASSWORD"
--set "provision.user.timezone=Europe/Amsterdam"
--set "importData.remoteStorage.url=$S3_REMOTE_STORAGE_URL"
--set "importData.remoteStorage.existingAccessKeySecret=s3-access-key-secret"
--set "importData.remoteStorage.region=$S3_REGION"
--set "importData.remoteStorage.location=$BACKUPS_LOCATION"
--set "importData.remoteStorage.filename=$PROD_BACKUP_NAME"
--set "migrateDefinitions.save=true"
--set "proxy=true"
--set "remote=https://appsemble.app"
--set "sentry.allowedDomains={*.appsemble.review}"
--set "sentry.environment=staging"
--set "sentry.secret=sentry"
--set "quotas.appEmail.enabled=true"
--set "quotas.appEmail.dailyLimit=10"
--set "quotas.appEmail.alertOrganizationOwner=true"
--set "mailpit.mailpit.smtp.tls.secretName=staging-mailpit-tls"
--set "mailpit.fullnameOverride=staging-appsemble-mailpit"
--set "minio.fullnameOverride=staging-minio"
--set "minio.ingress.hostname=console.minio.staging.appsemble.review"
--set "minio.ingress.annotations.cert-manager\\.io/cluster-issuer=acme-issuer-dev"
--set "minio.apiIngress.hostname=api.minio.staging.appsemble.review"
--set "minio.apiIngress.annotations.cert-manager\\.io/cluster-issuer=acme-issuer-dev"
--set "minio.apiIngress.annotations.nginx\\.ingress\\.kubernetes\\.io/proxy-body-size=256m"
production:
image: dtzar/helm-kubectl:3@sha256:569fbcea3ad1bdb26c953dc76e24591e9ac06abaf577e9f9167a0517e7669425
stage: deploy
needs:
- publish docker
- publish helm
rules:
- if: $CI_COMMIT_TAG
environment:
name: production
url: https://appsemble.app
variables:
GIT_STRATEGY: none
script:
- kubectl config use-context "$CI_PROJECT_PATH:production"
- kubectl config set-context --current --namespace appsemble
- helm repo add appsemble https://charts.appsemble.com
# Prevent a finished job without chart actually serving.
- |
retries=0
found=0
while [ $retries -lt 100 ] && [ $found -ne 1 ]; do
helm repo update
if helm search repo appsemble/appsemble --version "$CI_COMMIT_TAG" --fail-on-no-result; then
echo "Chart found!"
found=1
else
echo "Chart version $CI_COMMIT_TAG not found, retrying in 5 seconds..."
sleep 5
retries=$((retries + 1))
fi
done
if [ $found -ne 1 ]; then
echo "Maximum number of attempts reached. Chart not found."
exit 1
fi
- kubectl delete secret appsemble-mailpit-tls || true
- apk add --no-cache openssl
- openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mailpit.key -out mailpit.crt -subj "/CN=appsemble-mailpit-smtp" -addext "subjectAltName=DNS:appsemble-mailpit-smtp"
- kubectl create secret tls appsemble-mailpit-tls --cert=mailpit.crt --key=mailpit.key --dry-run=client -o yaml | kubectl apply -f -
- rm mailpit.key mailpit.crt
- kubectl rollout restart deployment appsemble-mailpit || true
- helm upgrade appsemble appsemble/appsemble
--debug
--timeout 30m
--version "$CI_COMMIT_TAG"
--set "gitlab.app=$CI_PROJECT_PATH_SLUG"
--set "gitlab.env=$CI_ENVIRONMENT_SLUG"
--set "global.postgresql.auth.existingSecret=$POSTGRESQL_SECRET"
--set "global.postgresql.auth.database=$POSTGRESQL_DATABASE"
--set "global.postgresql.auth.username=$POSTGRESQL_USERNAME"
--set "global.postgresql.service.ports.postgresql=$POSTGRESQL_PORT"
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/proxy-body-size=1G"
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/force-ssl-redirect=\"true\""
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/ssl-redirect=\"true\""
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/hsts=\"true\""
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/hsts-include-subdomains=\"true\""
--set "ingress.annotations.nginx\.ingress\.kubernetes\.io/hsts-max-age=\"31536000\""
--set "ingress.clusterIssuer=acme-issuer-prod"
--set "ingress.enabled=true"
--set "ingress.host=appsemble.app"
--set "ingress.tls.secretName=appsemble-tls"