-
Notifications
You must be signed in to change notification settings - Fork 7
/
config.yml
1753 lines (1719 loc) · 64.6 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
version: 2.1
orbs:
node: circleci/[email protected]
executors:
docker-executor:
# for docker you must specify an image to use for the primary container
docker:
- image: cimg/node:18.20.4-browsers
docker-postgres-executor:
docker:
- image: cimg/node:18.20.4-browsers
environment:
DATABASE_URL: postgresql://postgres@localhost/ttasmarthub
- image: cimg/postgres:15.6
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: secretpass
POSTGRES_DB: ttasmarthub
docker-python-executor:
docker:
- image: cimg/python:3.9.20
machine-executor:
machine:
image: ubuntu-2204:current
aws-executor:
docker:
- image: cimg/aws:2024.03
commands:
sparse_checkout:
description: "Checkout sparse directories from a specific branch."
parameters:
directories:
type: string
description: "Comma-separated list of directories to checkout sparsely"
branch:
type: string
description: "Branch to checkout"
steps:
- run:
name: Install Git
command: |
sudo apt-get update && sudo apt-get install -y git
- run:
name: Clone Repository
command: |
git clone --no-checkout --filter=blob:none << pipeline.project.git_url >>.git .
- run:
name: Sparse Checkout
environment:
DIRECTORIES: "<< parameters.directories >>"
command: |
git config core.sparseCheckout true
echo $DIRECTORIES | tr ',' '\n' | while read dir; do
echo "$dir" | tee -a .git/info/sparse-checkout
done
- run:
name: Checkout Branch
command: |
git checkout << parameters.branch >>
create_combined_yarnlock:
description: "Concatenate all yarn.json files into single file.
File is used as checksum source for part of caching key."
parameters:
filename:
type: string
default: "combined-yarnlock.txt"
steps:
- run:
name: Combine package-lock.json files to single file
command: cat yarn.lock frontend/yarn.lock packages/common/yarn.lock > << parameters.filename >>
create_combined_pipfreeze:
description: "Concatenate all requirements.txt files into a single file. File is used as checksum source for part of caching key."
parameters:
filename:
type: string
default: "combined-requirements.txt"
steps:
- run:
name: Combine requirements.txt files to single file
command: cat similarity_api/src/requirements.txt > << parameters.filename >>
notify_new_relic:
description: "Notify new relic of a deploy"
parameters:
env_name:
description: "Name of the environment. Ex. sandbox, dev, staging, prod"
type: string
new_relic_app_id:
description: "App ID used in New Relic"
type: string
new_relic_api_key:
description: "API key from New Relic"
type: string
steps:
- run:
name: Notify New Relic
command: |
curl -X POST "https://api.newrelic.com/v2/applications/<< parameters.new_relic_app_id >>/deployments.json" \
-H "X-Api-Key: << parameters.new_relic_api_key >>" -i \
-H "Content-Type: application/json" \
-d \
"{
\"deployment\": {
\"revision\": \"<< pipeline.git.revision >>\",
\"description\": \"<< parameters.env_name >> Successfully Deployed\"
}
}"
notify_slack:
description: "Notify Slack with message"
parameters:
slack_bot_token:
description: "Slack bot token"
type: string
slack_channel:
description: "Slack channel name to post the message to"
type: string
message_text:
description: "Message text to post to Slack"
type: string
default: ""
message_text_file:
description: "message text_file"
type: string
default: ""
steps:
- run:
name: Notify Slack
command: |
set -x
# Ensure the $BASH_ENV file exists
if [ ! -f $BASH_ENV ]; then
touch $BASH_ENV
fi
source $BASH_ENV
cat $BASH_ENV
# Evaluate message_text_script if provided
if [ -n "<< parameters.message_text_file >>" ]; then
MESSAGE_TEXT=$(cat "<< parameters.message_text_file >>")
else
MESSAGE_TEXT="<< parameters.message_text >>"
fi
echo $MESSAGE_TEXT
# Ensure all parameters are provided
if [ -z "<< parameters.slack_bot_token >>" ] || [ -z "<< parameters.slack_channel >>" ] || [ -z "$MESSAGE_TEXT" ]; then
echo "Missing required parameters. Notification will not be sent."
exit 1
fi
response=$(curl -s -X POST \
-H "Authorization: Bearer << parameters.slack_bot_token >>" \
-H 'Content-type: application/json;charset=utf-8' \
--data "{
\"channel\": \"<< parameters.slack_channel >>\",
\"text\": \"$MESSAGE_TEXT\"
}" \
https://slack.com/api/chat.postMessage)
ok=$(echo $response | jq -r '.ok')
error=$(echo $response | jq -r '.error')
if [ "$ok" != "true" ]; then
echo "Slack notification failed: $error"
exit 1
else
echo "Slack notification sent successfully"
fi
notify_slack_deploy:
parameters:
slack_bot_token:
description: "Slack bot token"
type: string
slack_channel:
description: "Slack channel name to post the message to"
type: string
environment_name:
description: "Name of environment"
type: string
steps:
- checkout
- run:
name: Generate Message
command: |
# Determine the environment URL
case "<< parameters.environment_name >>" in
sandbox)
ENV_URL="https://tta-smarthub-sandbox.app.cloud.gov/"
;;
dev)
ENV_URL="https://tta-smarthub-dev.app.cloud.gov/"
;;
staging)
ENV_URL="https://tta-smarthub-staging.app.cloud.gov/"
;;
production)
ENV_URL="https://ttahub.ohs.acf.hhs.gov"
;;
*)
ENV_URL="#"
;;
esac
env_name="<< parameters.environment_name >>"
if [ -n "${CIRCLE_PULL_REQUEST}" ]; then
PR_NUMBER=${CIRCLE_PULL_REQUEST##*/}
PR_TITLE=$(curl -s "${CIRCLE_PULL_REQUEST}" | sed -e :a -e "N; s/\n/ /g; ta" | grep -oP "<bdi class=\"js-issue-title markdown-title\">[^<]+</bdi>" | sed -re "s~<[^>]+>~~g" | sed -e 's/"/\\"/g')
if [ ! -z "${PR_TITLE}" ]; then
JIRA_URLS=$(curl -s "${CIRCLE_PULL_REQUEST}" | sed -e :a -e "N; s/\n/ /g; ta" | grep -oP "Issue[(]s[)]</h2>.*Checklists</h2>" | grep -oP "\"https[^\"]+\"" | sed -e "s~\"~~g" | grep -o "https://jira.acf.gov/browse/[A-Z0-9-]*")
MESSAGE_TEXT=":rocket: Deployment of PR <${CIRCLE_PULL_REQUEST}|${PR_NUMBER}> (${PR_TITLE}) to <${ENV_URL}|${env_name}> was successful!"
if [ -n "${JIRA_URLS}" ]; then
MESSAGE_TEXT="${MESSAGE_TEXT}\nJIRA URLs in the PR:\n${JIRA_URLS}"
fi
else
MESSAGE_TEXT=":rocket: Deployment of PR <${CIRCLE_PULL_REQUEST}|${PR_NUMBER}> to <${ENV_URL}|${env_name}> was successful!"
fi
else
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
if echo "$COMMIT_MESSAGE" | grep -q "Merge pull request #"; then
PR_NUMBER=$(git log -1 --pretty=%B | grep -oP '(?<=Merge pull request #)\d+')
PR_LINK="https://github.com/HHS/Head-Start-TTADP/pull/${PR_NUMBER}"
MESSAGE_TEXT=":rocket: Deployment of PR <${PR_LINK}|${PR_NUMBER}> to <${ENV_URL}|${env_name}> was successful!"
if [ ! -z "${JIRA_URLS}" ]; then
MESSAGE_TEXT="${MESSAGE_TEXT}\nJIRA URLs in the PR:\n${JIRA_URLS}"
fi
else
MESSAGE_TEXT=":rocket: Deployment to <${ENV_URL}|${env_name}> was successful!"
fi
fi
echo -e "${MESSAGE_TEXT}" > /tmp/message_file
- notify_slack:
slack_bot_token: << parameters.slack_bot_token >>
slack_channel: << parameters.slack_channel >>
message_text_file: "/tmp/message_file"
cf_deploy:
description: "Login to cloud foundry space with service account credentials
and push application using deployment configuration file."
parameters:
app_name:
description: "Name of Cloud Foundry cloud.gov application; must match
application name specified in manifest"
type: string
build_branch:
description: "The branch of the build being deployed"
type: string
default: << pipeline.git.branch >>
build_commit:
description: "The commit of the build being deployed"
type: string
default: << pipeline.git.revision >>
auth_client_id:
description: "Name of CircleCi project environment variable that
holds authentication client id, a required application variable"
type: env_var_name
auth_client_secret:
description: "Name of CircleCi project environment variable that
holds authentication client secret, a required application variable"
type: env_var_name
cloudgov_username:
description: "Name of CircleCi project environment variable that
holds deployer username for cloudgov space"
type: env_var_name
cloudgov_password:
description: "Name of CircleCi project environment variable that
holds deployer password for cloudgov space"
type: env_var_name
cloudgov_space:
description: "Name of CircleCi project environment variable that
holds name of cloudgov space to target for application deployment"
type: env_var_name
deploy_config_file:
description: "Path to deployment configuration file"
type: string
session_secret:
description: "Name of CircleCi project environment variable that
holds session secret, a required application variable"
type: env_var_name
jwt_secret:
description: "CircleCi project environment variable used by the backend
token service for the email verification flow."
type: env_var_name
new_relic_license:
description: "Name of CircleCI project environment variable that
holds the New Relic License key, a required application variable"
type: env_var_name
hses_data_file_url:
description: "Url to download HSES grants and recipient data from"
type: env_var_name
hses_data_username:
description: "Username used to access the HSES grants and recipient data"
type: env_var_name
hses_data_password:
description: "Password used to access the HSES grants and recipient data"
type: env_var_name
smtp_host:
description: "SMTP server"
type: env_var_name
smtp_port:
description: "SMTP port"
type: env_var_name
smtp_host_test:
description: "SMTP server test"
type: env_var_name
smtp_port_test:
description: "SMTP port test"
type: env_var_name
smtp_secure:
description: "SMTP secure transport"
type: env_var_name
smtp_ignore_tls:
description: "SMTP specifies whether to negotiate TLS"
type: env_var_name
from_email_address:
description: "From email address"
type: env_var_name
smtp_user:
description: "SMTP user"
type: env_var_name
smtp_password:
description: "SMTP password"
type: env_var_name
suppress_error_logging:
description: "Stop logging of non-sequelize errors to the db"
type: env_var_name
itams_md_host:
description: "host url for itams monitoring data"
type: env_var_name
itams_md_port:
description: "port for itams monitoring data"
type: env_var_name
itams_md_username:
description: "username for itams monitoring data"
type: env_var_name
itams_md_password:
description: "password for itams monitoring data"
type: env_var_name
smartsheet_access_token:
description: "non-production smartsheet access token"
type: env_var_name
steps:
- run:
name: Login with service account
command: |
cf login -a << pipeline.parameters.cg_api >> \
-u ${<< parameters.cloudgov_username >>} \
-p ${<< parameters.cloudgov_password >>} \
-o << pipeline.parameters.cg_org >> \
-s ${<< parameters.cloudgov_space >>}
- run:
name: Push application with deployment vars
command: |
set -x
cf push \
--vars-file << parameters.deploy_config_file >> \
--var AUTH_CLIENT_ID=${<< parameters.auth_client_id >>} \
--var AUTH_CLIENT_SECRET=${<< parameters.auth_client_secret >>} \
--var NEW_RELIC_LICENSE_KEY=${<< parameters.new_relic_license >>} \
--var SESSION_SECRET=${<< parameters.session_secret >>} \
--var JWT_SECRET=${<< parameters.jwt_secret >>} \
--var HSES_DATA_FILE_URL=${<< parameters.hses_data_file_url >>} \
--var HSES_DATA_USERNAME=${<< parameters.hses_data_username >>} \
--var HSES_DATA_PASSWORD=${<< parameters.hses_data_password >>} \
--var SMTP_HOST=${<< parameters.smtp_host >>} \
--var SMTP_PORT=${<< parameters.smtp_port >>} \
--var SMTP_HOST_TEST=${<< parameters.smtp_host_test >>} \
--var SMTP_PORT_TEST=${<< parameters.smtp_port_test >>} \
--var SMTP_USER=${<< parameters.smtp_user >>} \
--var SMTP_PASSWORD=${<< parameters.smtp_password >>} \
--var SMTP_SECURE=${<< parameters.smtp_secure >>} \
--var SMTP_IGNORE_TLS=${<< parameters.smtp_ignore_tls >>} \
--var FROM_EMAIL_ADDRESS=${<< parameters.from_email_address >>} \
--var SUPPRESS_ERROR_LOGGING=${<< parameters.suppress_error_logging >>} \
--var ITAMS_MD_HOST=${<< parameters.itams_md_host >>} \
--var ITAMS_MD_PORT=${<< parameters.itams_md_port >>} \
--var ITAMS_MD_USERNAME=${<< parameters.itams_md_username >>} \
--var ITAMS_MD_PASSWORD=${<< parameters.itams_md_password >>} \
--var SMARTSHEET_ACCESS_TOKEN=${<< parameters.smartsheet_access_token >>} \
--var BUILD_BRANCH=<< parameters.build_branch >> \
--var BUILD_COMMIT=<< parameters.build_commit >> \
--var BUILD_NUMBER=<< pipeline.number >> \
--var BUILD_TIMESTAMP="$(date +"%Y-%m-%d %H:%M:%S")"
# - run:
# name: Push maintenance application
# command: |
# cd maintenance_page && cf push -s cflinuxfs4 --vars-file ../<<parameters.deploy_config_file >>
cf_migrate:
description: "Login to Cloud Foundry space, run migration"
parameters:
app_name:
description: "Name of Cloud Foundry cloud.gov application; must match
application name specified in manifest"
type: string
cloudgov_username:
description: "Name of CircleCi project environment variable that
holds deployer username for cloudgov space"
type: env_var_name
cloudgov_password:
description: "Name of CircleCi project environment variable that
holds deployer password for cloudgov space"
type: env_var_name
cloudgov_space:
description: "Name of CircleCi project environment variable that
holds name of cloudgov space to target for application deployment"
type: env_var_name
steps:
- run:
name: Login with service account
command: |
cf login -a << pipeline.parameters.cg_api >> \
-u ${<< parameters.cloudgov_username >>} \
-p ${<< parameters.cloudgov_password >>} \
-o << pipeline.parameters.cg_org >> \
-s ${<< parameters.cloudgov_space >>}
- run:
name: Migrate database
command: |
cf run-task << parameters.app_name >> \
--command "yarn db:migrate:prod" \
--name "migrate"
cf_automation_task:
description: "Login to Cloud Foundry space, run automation task, and send notification"
parameters:
auth_client_secret:
description: "Name of CircleCi project environment variable that holds authentication client secret"
type: env_var_name
cloudgov_username:
description: "Name of CircleCi project environment variable that holds deployer username for Cloud Foundry space"
type: env_var_name
cloudgov_password:
description: "Name of CircleCi project environment variable that holds deployer password for Cloud Foundry space"
type: env_var_name
cloudgov_space:
description: "Name of CircleCi project environment variable that holds name of Cloud Foundry space to target for application deployment"
type: env_var_name
task_name:
description: "Name of the automation task to run"
type: string
task_command:
description: "Command to run for the automation task"
type: string
task_args:
description: "Arguments for the automation task"
type: string
config:
description: "Config prefix for the automation task"
type: string
success_message:
description: "Success message for Slack notification"
type: string
timeout:
description: "Max duration allowed for task"
type: string
default: "300"
directory:
description: 'directory to root to push'
type: string
default: "./automation"
steps:
- run:
name: Install Dependencies
command: |
set -e
set -u
set -o pipefail
set -o noglob
set -o noclobber
# update
sudo apt-get update
# Install uuid-runtime to have access to uuidgen
# Install pv wget
sudo apt-get install -y pv uuid-runtime wget coreutils jq
# Install Cloud Foundry CLI
wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list
sudo apt-get update
sudo apt-get install -y cf8-cli
# Install plugin needed for connect-to-service
cf install-plugin -f https://github.com/cloud-gov/cf-service-connect/releases/download/v1.1.3/cf-service-connect_linux_amd64
# The line you want to ensure exists in the /etc/hosts file
line="127.0.0.1 localhost"
# Check if the line already exists
if ! grep -qF "$line" /etc/hosts; then
# If the line does not exist, append it
echo "$line" | sudo tee -a /etc/hosts > /dev/null
echo "Line added to /etc/hosts"
else
echo "Line already exists in /etc/hosts"
fi
# cleanup
sudo rm -rf /var/lib/apt/lists/*
- run:
name: Login with service account
command: |
cf login -a << pipeline.parameters.cg_api >> \
-u ${<< parameters.cloudgov_username >>} \
-p ${<< parameters.cloudgov_password >>} \
-o << pipeline.parameters.cg_org >> \
-s ${<< parameters.cloudgov_space >>}
- run:
name: Start Log Monitoring
command: |
#!/bin/bash
CONTROL_FILE="/tmp/stop_tail"
rm -f $CONTROL_FILE
# Function to start tailing logs
start_log_tailing() {
echo "Starting cf logs for tta-automation..."
cf logs tta-automation &
TAIL_PID=$!
}
# Start tailing logs for the first time
start_log_tailing
# Monitor the cf logs process
while [ ! -f $CONTROL_FILE ]; do
# Check if the cf logs process is still running
if ! kill -0 $TAIL_PID 2>/dev/null; then
echo "cf logs command has stopped unexpectedly. Restarting..."
start_log_tailing
fi
sleep 1
done
# Kill the cf logs command
kill -9 $TAIL_PID
echo "cf logs command for tta-automation has been terminated."
background: true
- run:
name: cf_lambda - script to trigger task
command: |
set -x
json_data=$(jq -n \
--arg directory "<< parameters.directory >>" \
--arg config "<< parameters.config >>" \
--arg task_name "<< parameters.task_name >>" \
--arg command "<< parameters.task_command >>" \
--arg timeout_active_tasks "<< parameters.timeout >>" \
--arg timeout_ensure_app_stopped "<< parameters.timeout >>" \
--argjson args '<< parameters.task_args >>' \
'{
directory: $directory,
config: $config,
task_name: $task_name,
command: $command,
timeout_active_tasks: $timeout_active_tasks,
timeout_ensure_app_stopped: $timeout_ensure_app_stopped,
args: $args
}')
# Set execute permission
find ./automation -name "*.sh" -exec chmod +x {} \;
./automation/ci/scripts/cf_lambda.sh "$json_data"
- run:
name: Generate Message
command: |
if [ ! -z "$CIRCLE_PULL_REQUEST" ]; then
PR_NUMBER=${CIRCLE_PULL_REQUEST##*/}
echo "<< parameters.success_message >> before PR <$CIRCLE_PULL_REQUEST|$PR_NUMBER> successful!" > /tmp/message_file
else
echo "<< parameters.success_message >> successful!" > /tmp/message_file
fi
- notify_slack:
slack_bot_token: $SLACK_BOT_TOKEN
slack_channel: "acf-head-start-eng"
message_text_file: "/tmp/message_file"
- run:
name: Logout of service account
command: |
# Signal the log monitoring to stop
CONTROL_FILE="/tmp/stop_tail"
touch $CONTROL_FILE
# Wait for the log monitoring process to terminate
sleep 5
# Logout from Cloud Foundry
cf logout
cf_backup:
description: "Backup database to S3"
parameters:
auth_client_secret: { type: env_var_name }
cloudgov_username: { type: env_var_name }
cloudgov_password: { type: env_var_name }
cloudgov_space: { type: env_var_name }
rds_service_name: { type: string }
s3_service_name: { type: string }
backup_prefix: { type: string }
steps:
- cf_automation_task:
auth_client_secret: << parameters.auth_client_secret >>
cloudgov_username: << parameters.cloudgov_username >>
cloudgov_password: << parameters.cloudgov_password >>
cloudgov_space: << parameters.cloudgov_space >>
task_name: "backup"
task_command: "cd /home/vcap/app/db-backup/scripts; bash ./db_backup.sh"
task_args: '["<< parameters.backup_prefix >>", "<< parameters.rds_service_name >>", "<< parameters.s3_service_name >>"]'
config: "<< parameters.backup_prefix >>-backup"
success_message: ':download::database: "<< parameters.backup_prefix >>" backup'
cf_restore:
description: "Restore backup database from S3"
parameters:
auth_client_secret: { type: env_var_name }
cloudgov_username: { type: env_var_name }
cloudgov_password: { type: env_var_name }
cloudgov_space: { type: env_var_name }
rds_service_name: { type: string }
s3_service_name: { type: string }
backup_prefix: { type: string }
steps:
- run:
name: Validate Parameters
command: |
if [ "<< parameters.rds_service_name >>" = "ttahub-prod" ]; then
echo "Error: rds_service_name cannot be 'ttahub-prod'"
exit 1
fi
- cf_automation_task:
auth_client_secret: << parameters.auth_client_secret >>
cloudgov_username: << parameters.cloudgov_username >>
cloudgov_password: << parameters.cloudgov_password >>
cloudgov_space: << parameters.cloudgov_space >>
task_name: "restore"
task_command: "cd /home/vcap/app/db-backup/scripts; bash ./db_restore.sh"
task_args: '["<< parameters.backup_prefix >>", "<< parameters.rds_service_name >>", "<< parameters.s3_service_name >>"]'
config: "<< parameters.backup_prefix >>-restore"
success_message: ':database: "<< parameters.backup_prefix >>" Restored to "<< parameters.rds_service_name >>"'
timeout: "900"
cf_process:
description: "Process database from S3"
parameters:
auth_client_secret: { type: env_var_name }
cloudgov_username: { type: env_var_name }
cloudgov_password: { type: env_var_name }
cloudgov_space: { type: env_var_name }
steps:
- cf_automation_task:
auth_client_secret: << parameters.auth_client_secret >>
cloudgov_username: << parameters.cloudgov_username >>
cloudgov_password: << parameters.cloudgov_password >>
cloudgov_space: << parameters.cloudgov_space >>
task_name: "process"
task_command: "cd /home/vcap/app/automation/nodejs/scripts; bash ./run.sh"
task_args: '["/home/vcap/app/build/server/src/tools/processDataCLI.js"]'
config: "process"
success_message: ':database: Restored data processed'
directory: "./"
timeout: "3000"
parameters:
cg_org:
description: "Cloud Foundry cloud.gov organization name"
default: "hhs-acf-ohs-tta"
type: string
cg_api:
description: "URL of Cloud Controller in Cloud Foundry cloud.gov instance"
default: "https://api.fr.cloud.gov"
type: string
prod_git_url:
description: "URL of github repo that will deploy to prod"
default: "https://github.com/HHS/Head-Start-TTADP"
type: string
staging_git_url:
description: "URL of github repo that will deploy to staging"
default: "https://github.com/HHS/Head-Start-TTADP"
type: string
dev_git_url:
description: "URL of github repo that will deploy to dev"
default: "https://github.com/HHS/Head-Start-TTADP"
type: string
sandbox_git_url:
description: "URL of github repo that will deploy to sandbox"
default: "https://github.com/HHS/Head-Start-TTADP"
type: string
prod_git_branch:
description: "Name of github branch that will deploy to prod"
default: "production"
type: string
staging_git_branch:
description: "Name of github branch that will deploy to staging"
default: "main"
type: string
dev_git_branch: # change to feature branch to test deployment
description: "Name of github branch that will deploy to dev"
default: "main"
type: string
sandbox_git_branch: # change to feature branch to test deployment
default: "TTAHUB-3678/login"
type: string
prod_new_relic_app_id:
default: "877570491"
type: string
staging_new_relic_app_id:
default: "868729138"
type: string
dev_new_relic_app_id:
default: "867221900"
type: string
sandbox_new_relic_app_id:
default: "867346799"
type: string
manual-trigger:
type: boolean
default: false
manual-restore:
type: boolean
default: false
manual-process:
type: boolean
default: false
manual-backup:
type: boolean
default: false
manual-full-process:
type: boolean
default: false
manual-restore-staging:
type: boolean
default: false
manual-restore-sandbox:
type: boolean
default: false
manual-restore-dev:
type: boolean
default: false
fail-on-modified-lines:
type: boolean
default: false
jobs:
build_and_lint:
executor: docker-executor
steps:
- checkout
- create_combined_yarnlock
- restore_cache:
keys:
# To manually bust the cache, increment the version e.g. v7-yarn...
- v14-yarn-deps-{{ checksum "combined-yarnlock.txt" }}
# If checksum is new, restore partial cache
- v14-yarn-deps-
- run: yarn deps
- save_cache:
paths:
- node_modules
- frontend/node_modules
- packages/common/node_modules
key: v11-yarn-deps-{{ checksum "combined-yarnlock.txt" }}
- run:
name: Lint backend
command: yarn lint:ci
- run:
name: Audit vulnerability of backend node_modules
command: |
chmod 744 ./run-yarn-audit.sh
./run-yarn-audit.sh;
- run:
name: Lint frontend
command: yarn --cwd frontend lint:ci
- run:
name: Audit vulnerability of frontend node_modules
command: |
cd frontend
chmod 744 ./run-yarn-audit.sh
./run-yarn-audit.sh;
- run:
name: Check nodejs version compatibility with buildpack
command: |
chmod +x ./bin/check_node_version_compatibility.sh
./bin/check_node_version_compatibility.sh
- store_artifacts: # store backend lint reports
path: reports
- store_artifacts: # store frontend lint reports
path: frontend/reports
- run:
name: Remove similarity api data
command: rm -rf similarity_api
- persist_to_workspace:
root: .
paths:
- .
# The resource_class feature allows configuring CPU and RAM resources for each job. Different resource classes are available for different executors. https://circleci.com/docs/2.0/configuration-reference/#resourceclass
resource_class: large
build_and_lint_similarity_api:
executor: docker-python-executor
steps:
- checkout
- create_combined_pipfreeze
- restore_cache:
keys:
# To manually bust the cache, increment the version e.g. v7-pip...
- v2-pip-deps-{{ checksum "combined-requirements.txt" }}
# If checksum is new, restore partial cache
- v2-pip-deps-
- run:
name: Install python dependencies
command: |
cd similarity_api/src
python3 -m venv venv
source venv/bin/activate
pip install -U pip setuptools wheel
pip install -U --use-pep517 -r requirements.txt
- run:
name: Check python version compatibility with buildpack
command: |
chmod +x ./bin/check_python_version_compatibility.sh
./bin/check_python_version_compatibility.sh
- save_cache:
paths:
- similarity_api/src/venv
key: v1-pip-deps-{{ checksum "combined-requirements.txt" }}
- store_artifacts: # store backend lint reports
path: reports
- store_artifacts: # store frontend lint reports
path: similarity_api/reports
- persist_to_workspace:
root: .
paths:
- similarity_api
resource_class: large
test_backend:
executor: docker-postgres-executor
environment:
SFTP_EXPOSED_PORT: 2222
steps:
- attach_workspace:
at: .
- setup_remote_docker:
version: default
- run:
name: Add GitHub to known_hosts
command: ssh-keyscan -H github.com >> ~/.ssh/known_hosts
- run:
name: Run migrations ci
command: yarn db:migrate:ci
- run:
name: Run seeders
command: yarn db:seed:ci
- run:
name: Monitor database
command: |
docker attach $(docker ps | grep postgres | awk '{print $1}')
background: true
- run:
name: Test backend
command: |
chmod 744 ./bin/test-backend-ci
./bin/test-backend-ci
# Run coverage check script
- run:
name: Check coverage for modified lines
command: |
if [ -n "${CIRCLE_PULL_REQUEST}" ]; then
chmod +x ./tools/check-coverage.js
node -r esm ./tools/check-coverage.js \
--directory-filter=src/,tools/ \
--fail-on-uncovered=<< pipeline.parameters.fail-on-modified-lines >> \
--output-format=json,html
else
echo "Not a PR build. Skipping coverage check."
fi
when: always
- run:
name: Compress coverage artifacts
command: tar -cvzf backend-coverage-artifacts.tar coverage/
- store_artifacts:
path: coverage/
- store_artifacts:
path: backend-coverage-artifacts.tar
- store_test_results:
path: reports/
# Store uncovered lines artifact if exists
- store_artifacts:
path: coverage-artifacts/
destination: uncovered-lines
resource_class: large
test_similarity_api:
executor: docker-python-executor
steps:
- attach_workspace:
at: .
- setup_remote_docker:
version: default
- run:
name: Syft SBOM
environment:
SYFT_VERSION: v1.5.0
IMAGE_NAME: ghcr.io/kcirtapfromspace/cloudfoundry_circleci:latest
OUTPUT_FORMAT: json
OUTPUT_FILE: reports/syft_sbom.json
command: |
mkdir -p reports/
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b . "$SYFT_VERSION"
./syft similarity_api/src -vv --scope AllLayers -o "$OUTPUT_FORMAT" > "$OUTPUT_FILE"
echo "scan results saved in $OUTPUT_FILE"
# echo $GITHUB_PAT | ./syft login ghcr.io -u $GITHUB_USERNAME --password-stdin -vv
# echo $GITHUB_PAT | docker login ghcr.io -u $GITHUB_USERNAME --password-stdin
- run:
name: Grype Docker image
environment:
GRYPE_VERSION: v0.78.0
OUTPUT_FORMAT: sarif
OUTPUT_FILE: reports/grype.json
command: |
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b . "$GRYPE_VERSION"
./grype sbom:reports/syft_sbom.json -v -o "$OUTPUT_FORMAT" > "$OUTPUT_FILE"
echo "scan results saved in $OUTPUT_FILE"
- run:
name: Test similarity
command: |
mkdir -p coverage/similarity
cd similarity_api/src
source venv/bin/activate
pip install pytest pytest-cov
pytest -rpP --cov=similarity --cov=. --junitxml=~/project/reports/junit.xml
coverage report --show-missing --skip-covered
coverage html -d ~/project/coverage/similarity --skip-covered
- store_artifacts:
path: reports/
resource_class: large
test_frontend:
executor: docker-executor
steps:
- attach_workspace:
at: .
- run:
name: Audit checksums of color files
command: |
chmod 744 ./checkcolorhash.sh
./checkcolorhash.sh;
- run:
name: Add GitHub to known_hosts
command: |
mkdir -p /home/circleci/.ssh
ssh-keyscan -H github.com >> /home/circleci/.ssh/known_hosts
- run:
name: Test frontend
command: yarn --cwd frontend run test:ci --maxWorkers=50%
- run:
name: Check coverage for modified lines
command: |
if [ -n "${CIRCLE_PULL_REQUEST}" ]; then
chmod +x ./tools/check-coverage.js
node -r esm ./tools/check-coverage.js \
--coverage-file=../frontend/coverage/coverage-final.json \
--artifact-dir=../frontend/coverage-artifacts \
--directory-filter=frontend/ \
--fail-on-uncovered=<< pipeline.parameters.fail-on-modified-lines >> \
--output-format=json,html
else
echo "Not a PR build. Skipping coverage check."
fi
when: always
- store_test_results:
path: frontend/reports/
- store_artifacts:
path: frontend/coverage/
- store_artifacts:
path: frontend/coverage-artifacts/
destination: uncovered-lines
resource_class: large
test_e2e:
executor: docker-postgres-executor
steps:
- attach_workspace:
at: .
- setup_remote_docker:
version: default
- run:
name: Start server
command: |
yarn build
BYPASS_AUTH=true CURRENT_USER_ID=5 yarn start:ci
background: true
- run:
name: Run migrations ci
command: yarn db:migrate:ci
- run:
name: Seed database
command: yarn db:seed:ci
- run:
name: Wait for server to start
command: ./bin/ping-server 3000
- run:
name: Monitor database
command: |