-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathconfig.yml
1153 lines (1096 loc) · 39.3 KB
/
config.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
# CircleCI v2 Config
version: 2.1
##
# orbs
#
# Orbs used in this pipeline
##
orbs:
anchore: anchore/anchore-engine@1.9.0
slack: circleci/slack@4.12.5 # Ref: https://github.com/mojaloop/ci-config/tree/master/slack-templates
pr-tools: mojaloop/pr-tools@0.1.10 # Ref: https://github.com/mojaloop/ci-config/
gh: circleci/github-cli@2.2.0
##
# defaults
#
# YAML defaults templates, in alphabetical order
##
defaults_docker_Dependencies: &defaults_docker_Dependencies |
apk --no-cache add bash
apk --no-cache add git
apk --no-cache add ca-certificates
apk --no-cache add curl
apk --no-cache add openssh-client
apk --no-cache add -t build-dependencies make gcc g++ python3 libtool autoconf automake jq
apk --no-cache add -t openssl ncurses coreutils libgcc linux-headers grep util-linux binutils findutils
apk --no-cache add curl
apk --no-cache add librdkafka-dev
npm install -g node-gyp
## Default 'default-machine' executor dependencies
defaults_machine_Dependencies: &defaults_machine_Dependencies |
## Add Package Repos
## Ref: https://docs.confluent.io/platform/current/installation/installing_cp/deb-ubuntu.html#get-the-software
wget -qO - https://packages.confluent.io/deb/7.4/archive.key | sudo apt-key add -
sudo add-apt-repository -y "deb https://packages.confluent.io/clients/deb $(lsb_release -cs) main"
## Install deps
sudo apt install -y librdkafka-dev
defaults_awsCliDependencies: &defaults_awsCliDependencies |
apk --no-cache add aws-cli
defaults_license_scanner: &defaults_license_scanner
name: Install and set up license-scanner
command: |
git clone https://github.com/mojaloop/license-scanner /tmp/license-scanner
cd /tmp/license-scanner && make build default-files set-up
defaults_npm_auth: &defaults_npm_auth
name: Update NPM registry auth token
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
defaults_npm_publish_release: &defaults_npm_publish_release
name: Publish NPM $RELEASE_TAG artifact
command: |
source $BASH_ENV
echo "Publishing tag $RELEASE_TAG"
npm publish --tag $RELEASE_TAG --access public
defaults_export_version_from_package: &defaults_export_version_from_package
name: Format the changelog into the github release body and get release tag
command: |
git diff --no-indent-heuristic master~1 HEAD CHANGELOG.md | sed -n '/^+[^+]/ s/^+//p' > /tmp/changes
echo 'export RELEASE_CHANGES=`cat /tmp/changes`' >> $BASH_ENV
echo 'export RELEASE_TAG=`cat package-lock.json | jq -r .version`' >> $BASH_ENV
defaults_configure_git: &defaults_configure_git
name: Configure git
command: |
git config user.email ${GIT_CI_EMAIL}
git config user.name ${GIT_CI_USER}
defaults_configure_nvmrc: &defaults_configure_nvmrc
name: Configure NVMRC
command: |
if [ -z "$NVMRC_VERSION" ]; then
echo "==> Configuring NVMRC_VERSION!"
export ENV_DOT_PROFILE=$HOME/.profile
touch $ENV_DOT_PROFILE
export NVMRC_VERSION=$(cat $CIRCLE_WORKING_DIRECTORY/.nvmrc)
echo "export NVMRC_VERSION=$NVMRC_VERSION" >> $ENV_DOT_PROFILE
fi
echo "NVMRC_VERSION=$NVMRC_VERSION"
defaults_configure_nvm: &defaults_configure_nvm
name: Configure NVM
command: |
cd $HOME
export ENV_DOT_PROFILE=$HOME/.profile
touch $ENV_DOT_PROFILE
echo "1. Export env variable"
export NVM_DIR="$HOME/.nvm"
if [ -z "$NVMRC_VERSION" ]; then
echo "==> Configuring NVMRC_VERSION!"
export NVMRC_VERSION=$(cat $CIRCLE_WORKING_DIRECTORY/.nvmrc)
echo "export NVMRC_VERSION=$NVMRC_VERSION" >> $ENV_DOT_PROFILE
fi
if [ -f "$NVM_DIR" ]; then
echo "==> $NVM_DIR exists. Skipping steps 2-4!"
else
echo "==> $NVM_DIR does not exists. Executing steps 2-4!"
echo "2. Installing NVM"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
echo "3. Executing $NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
fi
## Ref: https://github.com/nvm-sh/nvm/issues/1102#issuecomment-550572252
if [ ! -z "$NVM_ARCH_UNOFFICIAL_OVERRIDE" ]; then
echo "==> Handle NVM_ARCH_UNOFFICIAL_OVERRIDE=$NVM_ARCH_UNOFFICIAL_OVERRIDE!"
echo "nvm_get_arch() { nvm_echo \"${NVM_ARCH_UNOFFICIAL_OVERRIDE}\"; }" >> $ENV_DOT_PROFILE
echo "export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release" >> $ENV_DOT_PROFILE
source $ENV_DOT_PROFILE
fi
echo "4. Installing Node version: $NVMRC_VERSION"
nvm install $NVMRC_VERSION
nvm alias default $NVMRC_VERSION
nvm use $NVMRC_VERSION
cd $CIRCLE_WORKING_DIRECTORY
defaults_display_versions: &defaults_display_versions
name: Display Versions
command: |
echo "What is the active version of Nodejs?"
echo "node: $(node --version)"
echo "yarn: $(yarn --version)"
echo "npm: $(npm --version)"
echo "nvm: $(nvm --version)"
defaults_environment: &defaults_environment
## env var for nx to set main branch
MAIN_BRANCH_NAME: master
## Disable LIBRDKAFKA build since we install it via general dependencies
BUILD_LIBRDKAFKA: 0
##
# Executors
#
# CircleCI Executors
##
executors:
default-docker:
working_directory: &WORKING_DIR /home/circleci/project
shell: "/bin/sh -leo pipefail" ## Ref: https://circleci.com/docs/env-vars/#alpine-linux
environment:
BASH_ENV: /etc/profile ## Ref: https://circleci.com/docs/env-vars/#alpine-linux
NVM_ARCH_UNOFFICIAL_OVERRIDE: x64-musl ## Ref: https://github.com/nvm-sh/nvm/issues/1102#issuecomment-550572252
docker:
- image: node:lts-alpine # Ref: https://hub.docker.com/_/node?tab=tags&page=1&name=alpine
default-machine:
working_directory: *WORKING_DIR
shell: "/bin/bash -leo pipefail"
machine:
image: ubuntu-2204:2023.04.2 # Ref: https://circleci.com/developer/machine/image/ubuntu-2204
##
# Jobs
#
# A map of CircleCI jobs
##
jobs:
setup:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- run:
name: Update NPM install
command: npm ci
- save_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
paths:
- node_modules
test-dependencies:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Execute dependency tests
command: npm run dep:check
test-lint:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Execute lint tests
command: npm run lint
test-unit:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
# This is needed for legacy core tests. Remove this once 'tape' is fully deprecated.
name: Install tape, tapes and tap-xunit
command: npm install tape tapes tap-xunit
- run:
name: Create dir for test results
command: mkdir -p ./test/results
- run:
name: Execute unit tests
command: npm -s run test:xunit
- store_artifacts:
path: ./test/results
destination: test
- store_test_results:
path: ./test/results
test-coverage:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_docker_Dependencies
- run:
name: Install AWS CLI dependencies
command: *defaults_awsCliDependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Execute code coverage check
command: npm -s run test:coverage-check
- store_artifacts:
path: coverage
destination: test
- store_test_results:
path: coverage
test-integration:
executor: default-machine
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_machine_Dependencies
- checkout
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- attach_workspace:
at: /tmp
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- run:
name: Create dir for test results
command: mkdir -p ./test/results
- run:
name: Build and start the docker containers
command: |
## This is not needed as we are only doing narrow-integration tests.
# docker-compose build
## Lets pull only the Services needed for the Integration Test
docker-compose pull mysql kafka init-kafka
## Lets startup only the Services needed for the Integration Test
docker-compose up -d mysql kafka init-kafka
## Check straight away to see if any containers have exited
docker-compose ps
## wait for services to be up and running
npm run wait-4-docker
- run:
name: Install dependencies to check health services
command: |
sudo apt install curl
- run:
name: Rebuild any dependencies
command: |
npm rebuild
- run:
name: Run migration scripts
command: |
npm run migrate
- run:
name: Run the integration tests
command: |
## Run Service in background
## This is a temporary work-around until the following issue can be addressed: https://github.com/mojaloop/project/issues/3112
echo "Starting Service in the background"
npm start > ./test/results/cl-service.log &
## Store PID for cleanup
echo $! > /tmp/int-test-service.pid
PID=$(cat /tmp/int-test-service.pid)
echo "Service started with Process ID=$PID"
## Check Service Health
echo "Waiting for Service to be healthy"
bash .circleci/curl-retry-cl-health.sh
## Lets wait a few seconds to ensure that Kafka handlers are rebalanced
echo "Waiting ${WAIT_FOR_REBALANCE}s for Kafka Re-balancing..." && sleep $WAIT_FOR_REBALANCE
## Start integration tests
echo "Running Integration Tests"
npm run test:int:skipMigrate
## Kill service
echo "Stopping Service with Process ID=$PID"
kill $(cat /tmp/int-test-service.pid)
environment:
ENDPOINT_URL: http://localhost:4545/notification
UV_THREADPOOL_SIZE: 12
WAIT_FOR_REBALANCE: 20
TEST_INT_RETRY_COUNT: 20
TEST_INT_RETRY_DELAY: 2
TEST_INT_REBALANCE_DELAY: 20000
- run:
name: Cleanup Docker
command: |
## Shutdown Docker containers
docker compose down -v
- store_artifacts:
path: ./test/results
destination: test
- store_test_results:
path: ./test/results
test-functional:
executor: default-machine
environment:
<<: *defaults_environment
steps:
- checkout
- run:
<<: *defaults_configure_nvmrc
- attach_workspace:
at: /tmp
- run:
name: Load the pre-built docker local image from workspace
command: docker load -i /tmp/docker-image.tar
- run:
name: Download the mojaloop/ml-core-test-harness repo
command: |
git clone --depth 1 --branch v0.0.3 https://github.com/mojaloop/ml-core-test-harness.git /tmp/ml-core-test-harness
- run:
name: Execute TTK functional tests
command: |
cp ./docker/config-modifier/configs/central-ledger.js /tmp/ml-core-test-harness/docker/config-modifier/configs/central-ledger.js
cd /tmp/ml-core-test-harness
export CENTRAL_LEDGER_VERSION=local
docker-compose --project-name ttk-func --ansi never --profile all-services --profile ttk-provisioning --profile ttk-tests up -d
bash wait-for-container.sh ttk-func-ttk-tests-1
docker logs ttk-func-ttk-tests-1 > ./reports/ttk-tests-console.log
docker-compose -p ttk-func --ansi never down
cat ./reports/ttk-tests-console.log
- store_artifacts:
path: /tmp/ml-core-test-harness/reports
destination: test
vulnerability-check:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_docker_Dependencies
- checkout
- run:
<<: *defaults_configure_nvm
- run:
<<: *defaults_display_versions
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Create dir for test results
command: mkdir -p ./audit/results
- run:
name: Check for new npm vulnerabilities
command: npm run audit:check -- -o json > ./audit/results/auditResults.json
- store_artifacts:
path: ./audit/results
destination: audit
audit-licenses:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_docker_Dependencies
- run:
<<: *defaults_license_scanner
- checkout
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Run the license-scanner
command: cd /tmp/license-scanner && pathToRepo=$CIRCLE_WORKING_DIRECTORY make run
- store_artifacts:
path: /tmp/license-scanner/results
destination: licenses
build-local:
executor: default-machine
environment:
<<: *defaults_environment
steps:
- checkout
- run:
<<: *defaults_configure_nvmrc
- run:
name: Build Docker local image
command: |
source ~/.profile
export DOCKER_NODE_VERSION="$NVMRC_VERSION-alpine"
echo "export DOCKER_NODE_VERSION=$NVMRC_VERSION-alpine" >> $BASH_ENV
echo "Building Docker image: ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:local --build-arg NODE_VERSION=$DOCKER_NODE_VERSION"
docker build -t ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:local --build-arg NODE_VERSION=$DOCKER_NODE_VERSION .
- run:
name: Save docker image to workspace
command: docker save -o /tmp/docker-image.tar ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:local
- persist_to_workspace:
root: /tmp
paths:
- ./docker-image.tar
build:
executor: default-machine
environment:
<<: *defaults_environment
steps:
- attach_workspace:
at: /tmp
- run:
name: Load the pre-built docker local image from workspace
command: docker load -i /tmp/docker-image.tar
- run:
name: Re-tag the image
command: |
echo "Re-tagging Docker image: $CIRCLE_TAG"
docker tag ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:local ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
- run:
name: Save the new docker image to workspace
command: docker save -o /tmp/docker-image.tar ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
- persist_to_workspace:
root: /tmp
paths:
- ./docker-image.tar
license-scan:
executor: default-machine
environment:
<<: *defaults_environment
steps:
- attach_workspace:
at: /tmp
- run:
name: Load the pre-built docker image from workspace
command: docker load -i /tmp/docker-image.tar
- run:
<<: *defaults_license_scanner
- run:
name: Run the license-scanner
command: cd /tmp/license-scanner && mode=docker dockerImages=${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG make run
- store_artifacts:
path: /tmp/license-scanner/results
destination: licenses
image-scan:
executor: anchore/anchore_engine
environment:
<<: *defaults_environment
steps:
- setup_remote_docker
- checkout
- run:
name: Setup Slack config
command: |
echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
echo "export SLACK_RELEASE_TYPE='GitHub Release'" >> $BASH_ENV
echo "export SLACK_RELEASE_TAG='${RELEASE_TAG} on ${CIRCLE_BRANCH} branch'" >> $BASH_ENV
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
echo "export SLACK_CUSTOM_MSG='Anchore Image Scan failed for: \`${DOCKER_ORG}/${CIRCLE_PROJECT_REPONAME}:${CIRCLE_TAG}\`'" >> $BASH_ENV
- run:
name: Install docker dependencies for anchore
command: |
apk add --update py-pip docker python3-dev libffi-dev openssl-dev gcc libc-dev make jq npm
- run:
name: Install general dependencies
command: |
apk --no-cache add git
apk --no-cache add ca-certificates
apk --no-cache add curl
apk --no-cache add openssh-client
apk add --no-cache -t build-dependencies make gcc g++ python3 libtool autoconf automake
npm config set unsafe-perm true
npm install -g node-gyp
- run:
name: Install AWS CLI dependencies
command: *defaults_awsCliDependencies
- attach_workspace:
at: /tmp
- run:
name: Load the pre-built docker image from workspace
command: docker load -i /tmp/docker-image.tar
- run:
name: Download the mojaloop/ci-config repo
command: |
git clone https://github.com/mojaloop/ci-config /tmp/ci-config
# Generate the mojaloop anchore-policy
cd /tmp/ci-config/container-scanning && ./mojaloop-policy-generator.js /tmp/mojaloop-policy.json
- run:
name: Pull base image locally
command: |
docker pull node:16.15.0-alpine
# Analyze the base and derived image
# Note: It seems images are scanned in parallel, so preloading the base image result doesn't give us any real performance gain
- anchore/analyze_local_image:
# Force the older version, version 0.7.0 was just published, and is broken
anchore_version: v0.6.1
image_name: "docker.io/node:16.15.0-alpine ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG"
policy_failure: false
timeout: '500'
# Note: if the generated policy is invalid, this will fallback to the default policy, which we don't want!
policy_bundle_file_path: /tmp/mojaloop-policy.json
- run:
name: Upload Anchore reports to s3
command: |
aws s3 cp anchore-reports ${AWS_S3_DIR_ANCHORE_REPORTS}/${CIRCLE_PROJECT_REPONAME}/ --recursive
aws s3 rm ${AWS_S3_DIR_ANCHORE_REPORTS}/latest/ --recursive --exclude "*" --include "${CIRCLE_PROJECT_REPONAME}*"
aws s3 cp anchore-reports ${AWS_S3_DIR_ANCHORE_REPORTS}/latest/ --recursive
- run:
name: Evaluate failures
command: /tmp/ci-config/container-scanning/anchore-result-diff.js anchore-reports/node_16.15.0-alpine-policy.json anchore-reports/${CIRCLE_PROJECT_REPONAME}*-policy.json
- store_artifacts:
path: anchore-reports
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE
release:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_docker_Dependencies
- checkout
- restore_cache:
keys:
- dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
<<: *defaults_configure_git
- run:
name: Setup Slack config
command: |
echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
echo "export SLACK_RELEASE_TYPE='GitHub Release'" >> $BASH_ENV
echo "export SLACK_RELEASE_TAG='${RELEASE_TAG} on ${CIRCLE_BRANCH} branch'" >> $BASH_ENV
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
- run:
name: Generate changelog and bump package version
command: npm run release -- --no-verify
- run:
name: Push the release
command: git push --follow-tags origin ${CIRCLE_BRANCH}
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE
github-release:
executor: default-machine
shell: "/bin/bash -eo pipefail"
environment:
<<: *defaults_environment
steps:
- run:
name: Install git
command: |
sudo apt-get update && sudo apt-get install -y git
- gh/install
- checkout
- run:
<<: *defaults_configure_git
- run:
name: Fetch updated release branch
command: |
git fetch origin
git checkout origin/${CIRCLE_BRANCH}
- run:
<<: *defaults_export_version_from_package
- run:
name: Check the release changes
command: |
echo "Changes are: ${RELEASE_CHANGES}"
- run:
name: Setup Slack config
command: |
echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
echo "export SLACK_RELEASE_TYPE='Github Release'" >> $BASH_ENV
echo "export SLACK_RELEASE_TAG=v${RELEASE_TAG}" >> $BASH_ENV
echo "export SLACK_RELEASE_URL=https://github.com/mojaloop/${CIRCLE_PROJECT_REPONAME}/releases/tag/v${RELEASE_TAG}" >> $BASH_ENV
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
- run:
name: Create Release
command: |
gh release create "v${RELEASE_TAG}" --title "v${RELEASE_TAG} Release" --draft=false --notes "${RELEASE_CHANGES}" ./CHANGELOG.md
- slack/notify:
event: pass
template: SLACK_TEMP_RELEASE_SUCCESS
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE
publish-docker:
executor: default-machine
shell: "/bin/bash -eo pipefail"
environment:
<<: *defaults_environment
steps:
- checkout
- run:
name: Setup for LATEST release
command: |
echo "export RELEASE_TAG=$RELEASE_TAG_PROD" >> $BASH_ENV
echo "RELEASE_TAG=$RELEASE_TAG_PROD"
PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
- run:
name: Setup Slack config
command: |
echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
echo "export SLACK_RELEASE_TYPE='Docker Release'" >> $BASH_ENV
echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
- attach_workspace:
at: /tmp
- run:
name: Load the pre-built docker image from workspace
command: |
docker load -i /tmp/docker-image.tar
- run:
name: Login to Docker Hub
command: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run:
name: Re-tag pre built image
command: |
docker tag ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
- run:
name: Publish Docker image $CIRCLE_TAG & Latest tag to Docker Hub
command: |
echo "Publishing ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG"
docker push ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
echo "Publishing ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG"
docker push ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
- run:
name: Set Image Digest
command: |
IMAGE_DIGEST=$(docker inspect ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:v${CIRCLE_TAG:1} | jq '.[0].RepoDigests | .[]')
echo "IMAGE_DIGEST=${IMAGE_DIGEST}"
echo "export IMAGE_DIGEST=${IMAGE_DIGEST}" >> $BASH_ENV
- run:
name: Update Slack config
command: |
echo "export SLACK_RELEASE_URL='https://hub.docker.com/layers/${CIRCLE_PROJECT_REPONAME}/${DOCKER_ORG}/${CIRCLE_PROJECT_REPONAME}/v${CIRCLE_TAG:1}/images/${IMAGE_DIGEST}?context=explore'" | sed -r "s/${DOCKER_ORG}\/${CIRCLE_PROJECT_REPONAME}@sha256:/sha256-/g" >> $BASH_ENV
- slack/notify:
event: pass
template: SLACK_TEMP_RELEASE_SUCCESS
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE
publish-docker-snapshot:
executor: default-machine
shell: "/bin/bash -eo pipefail"
environment:
<<: *defaults_environment
steps:
- checkout
- run:
name: Setup for SNAPSHOT release
command: |
echo "export RELEASE_TAG=$RELEASE_TAG_SNAPSHOT" >> $BASH_ENV
echo "RELEASE_TAG=$RELEASE_TAG_SNAPSHOT"
PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
- run:
name: Setup Slack config
command: |
echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
echo "export SLACK_RELEASE_TYPE='Docker Release'" >> $BASH_ENV
echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
- attach_workspace:
at: /tmp
- run:
name: Load the pre-built docker image from workspace
command: |
docker load -i /tmp/docker-image.tar
- run:
name: Login to Docker Hub
command: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run:
name: Re-tag pre built image
command: |
docker tag ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
- run:
name: Publish Docker image $CIRCLE_TAG & Latest tag to Docker Hub
command: |
echo "Publishing ${DOCKER_ORG:-mojaloop}/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG"
docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$CIRCLE_TAG
echo "Publishing $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG"
docker push $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:$RELEASE_TAG
- run:
name: Set Image Digest
command: |
IMAGE_DIGEST=$(docker inspect $DOCKER_ORG/$CIRCLE_PROJECT_REPONAME:v${CIRCLE_TAG:1} | jq '.[0].RepoDigests | .[]')
echo "IMAGE_DIGEST=${IMAGE_DIGEST}"
echo "export IMAGE_DIGEST=${IMAGE_DIGEST}" >> $BASH_ENV
- run:
name: Update Slack config
command: |
echo "export SLACK_RELEASE_URL='https://hub.docker.com/layers/${CIRCLE_PROJECT_REPONAME}/${DOCKER_ORG}/${CIRCLE_PROJECT_REPONAME}/v${CIRCLE_TAG:1}/images/${IMAGE_DIGEST}?context=explore'" | sed -r "s/${DOCKER_ORG}\/${CIRCLE_PROJECT_REPONAME}@sha256:/sha256-/g" >> $BASH_ENV
- slack/notify:
event: pass
template: SLACK_TEMP_RELEASE_SUCCESS
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE
publish-npm:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_docker_Dependencies
- checkout
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Setup for LATEST release
command: |
echo "export RELEASE_TAG=$RELEASE_TAG_PROD" >> $BASH_ENV
echo "RELEASE_TAG=$RELEASE_TAG_PROD"
PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
- run:
name: Setup Slack config
command: |
echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
echo "export SLACK_RELEASE_TYPE='NPM Release'" >> $BASH_ENV
echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_RELEASE_URL=https://www.npmjs.com/package/@mojaloop/${CIRCLE_PROJECT_REPONAME}/v/${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
- run:
<<: *defaults_npm_auth
- run:
<<: *defaults_npm_publish_release
- slack/notify:
event: pass
template: SLACK_TEMP_RELEASE_SUCCESS
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE
publish-npm-snapshot:
executor: default-docker
environment:
<<: *defaults_environment
steps:
- run:
name: Install general dependencies
command: *defaults_docker_Dependencies
- checkout
- restore_cache:
key: dependency-cache-{{ .Environment.CIRCLE_SHA1 }}
- run:
name: Setup for SNAPSHOT release
command: |
echo "export RELEASE_TAG=${RELEASE_TAG_SNAPSHOT}" >> $BASH_ENV
echo "RELEASE_TAG=${RELEASE_TAG_SNAPSHOT}"
echo "Override package version: ${CIRCLE_TAG:1}"
npx standard-version --skip.tag --skip.commit --skip.changelog --release-as ${CIRCLE_TAG:1}
PACKAGE_VERSION=$(cat package-lock.json | jq -r .version)
echo "export PACKAGE_VERSION=${PACKAGE_VERSION}" >> $BASH_ENV
echo "PACKAGE_VERSION=${PACKAGE_VERSION}"
- run:
name: Setup Slack config
command: |
echo "export SLACK_PROJECT_NAME=${CIRCLE_PROJECT_REPONAME}" >> $BASH_ENV
echo "export SLACK_RELEASE_TYPE='NPM Snapshot'" >> $BASH_ENV
echo "export SLACK_RELEASE_TAG=v${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_RELEASE_URL=https://www.npmjs.com/package/@mojaloop/${CIRCLE_PROJECT_REPONAME}/v/${CIRCLE_TAG:1}" >> $BASH_ENV
echo "export SLACK_BUILD_ID=${CIRCLE_BUILD_NUM}" >> $BASH_ENV
echo "export SLACK_CI_URL=${CIRCLE_BUILD_URL}" >> $BASH_ENV
- run:
<<: *defaults_npm_auth
- run:
<<: *defaults_npm_publish_release
- slack/notify:
event: pass
template: SLACK_TEMP_RELEASE_SUCCESS
- slack/notify:
event: fail
template: SLACK_TEMP_RELEASE_FAILURE
##
# Workflows
#
# CircleCI Workflow config
##
workflows:
build_and_test:
jobs:
- pr-tools/pr-title-check:
context: org-global
- setup:
context: org-global
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- test-dependencies:
context: org-global
requires:
- setup
filters:
tags:
ignore: /.*/
branches:
ignore:
- master
- main
- test-lint:
context: org-global
requires:
- setup
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- test-unit:
context: org-global
requires:
- setup
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- test-coverage:
context: org-global
requires:
- setup
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- test-integration:
context: org-global
requires:
- setup
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- test-functional:
context: org-global
requires:
- setup
- build-local
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- vulnerability-check:
context: org-global
requires:
- setup
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- audit-licenses:
context: org-global
requires:
- setup
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- build-local:
context: org-global
requires:
- setup
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- build:
context: org-global