-
Notifications
You must be signed in to change notification settings - Fork 10
641 lines (608 loc) · 21.7 KB
/
deploy-experimental.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
name: "Deploy Experimental"
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
id-token: write
contents: read
actions: read
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
deploy-static:
environment:
name: "dev"
url: ${{ steps.deploy-regulations-site-server.outputs.url }}
runs-on: ubuntu-22.04
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existign action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# should build first and save the artifact
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.14
# setup python
- uses: actions/setup-python@v5
if: success() && steps.findPr.outputs.number
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./solution/static-assets/requirements.txt
# build the static assets for the website
- name: build static assets
if: success() && steps.findPr.outputs.number
env:
STATIC_URL: http://localhost:8888/
STATIC_ROOT: ../static-assets/regulations
VITE_ENV: dev${{ steps.findPr.outputs.pr }}
run: |
pushd solution/backend
python manage.py collectstatic --noinput
cd ..
popd
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# deploy static assets to AWS
- name: deploy static assets
if: success() && steps.findPr.outputs.number
env:
PR: ${{ steps.findPr.outputs.pr }}
run: |
pushd solution/static-assets
npm install serverless@">=3.38.0 <4" -g
npm install
serverless deploy --stage dev${PR}
popd
deploy-zip-lambdas-cdk:
if: github.event.action != 'closed'
runs-on: ubuntu-22.04
environment:
name: "dev"
env:
ENVIRONMENT_NAME: "dev"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
state: open
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Deploy ZIP-based Lambdas
if: success() && steps.findPr.outputs.number
env:
PR_NUMBER: ${{ steps.findPr.outputs.pr }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
run: |
pushd cdk-eregs
npm install -g aws-cdk@latest @aws-sdk/client-ssm
npm install
# Get exact stack names
REDIRECT_STACK="cms-eregs-eph-$PR_NUMBER-redirect-api"
MAINTENANCE_STACK="cms-eregs-eph-$PR_NUMBER-maintenance-api"
cdk deploy ${REDIRECT_STACK} ${MAINTENANCE_STACK} \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--require-approval never \
--exclusively \
--app "npx ts-node bin/zip-lambdas.ts"
popd
deploy-text-extractor-cdk:
needs: deploy-zip-lambdas-cdk
if: github.event.action != 'closed'
runs-on: ubuntu-22.04
environment:
name: "dev"
env:
ENVIRONMENT_NAME: "dev"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
state: open
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Deploy Text Extractor
if: success() && steps.findPr.outputs.number
env:
PR_NUMBER: ${{ steps.findPr.outputs.pr }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
run: |
pushd cdk-eregs
npm install -g aws-cdk@latest @aws-sdk/client-ssm
npm install
TEXT_EXTRACTOR_STACK="cms-eregs-eph-$PR_NUMBER-text-extractor"
cdk deploy $TEXT_EXTRACTOR_STACK \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--require-approval never \
--exclusively \
--app "npx ts-node bin/docker-lambdas.ts"
popd
deploy-fr-parser-cdk:
needs: [deploy-zip-lambdas-cdk, deploy-text-extractor-cdk]
if: github.event.action != 'closed'
runs-on: ubuntu-22.04
environment:
name: "dev"
env:
ENVIRONMENT_NAME: "dev"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
state: open
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Deploy FR Parser
if: success() && steps.findPr.outputs.number
env:
PR_NUMBER: ${{ steps.findPr.outputs.pr }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
run: |
pushd cdk-eregs
npm install -g aws-cdk@latest @aws-sdk/client-ssm
npm install
FR_PARSER_STACK="cms-eregs-eph-$PR_NUMBER-fr-parser"
cdk deploy $FR_PARSER_STACK \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--require-approval never \
--exclusively \
--app "npx ts-node bin/docker-lambdas.ts"
popd
deploy-ecfr-parser-cdk:
needs: [deploy-zip-lambdas-cdk, deploy-text-extractor-cdk, deploy-fr-parser-cdk]
if: github.event.action != 'closed'
runs-on: ubuntu-22.04
environment:
name: "dev"
env:
ENVIRONMENT_NAME: "dev"
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
state: open
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Deploy ECFR Parser
if: success() && steps.findPr.outputs.number
env:
PR_NUMBER: ${{ steps.findPr.outputs.pr }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
CDK_DEBUG: true
run: |
pushd cdk-eregs
npm install -g aws-cdk@latest @aws-sdk/client-ssm
npm install
ECFR_PARSER_STACK="cms-eregs-eph-$PR_NUMBER-ecfr-parser"
cdk deploy $ECFR_PARSER_STACK \
-c environment=${{ env.ENVIRONMENT_NAME }} \
--require-approval never \
--exclusively \
--app "npx ts-node bin/docker-lambdas.ts"
popd
deployment-status-cdk:
needs: [deploy-zip-lambdas-cdk, deploy-text-extractor-cdk, deploy-fr-parser-cdk, deploy-ecfr-parser-cdk]
if: always()
runs-on: ubuntu-22.04
environment: "dev"
steps:
- name: Deployment Status Summary
run: |
echo "Deployment Summary for ${{ env.ENVIRONMENT_NAME }}"
echo "1. ZIP-based Lambdas: ${{ needs.deploy-zip-lambdas-cdk.result == 'success' && '✅' || '❌' }}"
echo "2. Text Extractor: ${{ needs.deploy-text-extractor-cdk.result == 'success' && '✅' || '❌' }}"
echo "3. FR Parser: ${{ needs.deploy-fr-parser-cdk.result == 'success' && '✅' || '❌' }}"
echo "4. ECFR Parser: ${{ needs.deploy-ecfr-parser-cdk.result == 'success' && '✅' || '❌' }}"
# deploy-hello-world-cdk:
# environment:
# name: "dev"
# runs-on: ubuntu-22.04
# steps:
# # Checkout the code
# - name: Checkout
# uses: actions/checkout@v3
# with:
# submodules: true
# # Find the PR number. This is not always trivial which is why this uses an existign action
# - name: Find PR number
# uses: jwalton/gh-find-current-pr@v1
# id: findPr
# with:
# # Can be "open", "closed", or "all". Defaults to "open".
# state: open
# # Configure AWS credentials for GitHub Actions
# - name: Configure AWS credentials for GitHub Actions
# uses: aws-actions/configure-aws-credentials@v4
# with:
# role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
# aws-region: us-east-1
# # Deploy the text extractor lambda to AWS
# - name: Deploy the hello world test lambda via CDK
# id: deploy-redirect-api-test
# if: success() && steps.findPr.outputs.number
# env:
# PR_NUMBER: ${{ steps.findPr.outputs.pr }}
# RUN_ID: ${{ github.run_id }}
# AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
# AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
# run: |
# pushd cdk-eregs
# npm install -g aws-cdk
# npm install
# STAGE=dev${PR_NUMBER} cdk synth -c stage=dev${PR_NUMBER} -c account=${AWS_ACCOUNT_ID} -c region=${AWS_DEFAULT_REGION}
# STAGE=dev${PR_NUMBER} cdk deploy -c stage=dev${PR_NUMBER} -c account=${AWS_ACCOUNT_ID} -c region=${AWS_DEFAULT_REGION} \
# dev${PR_NUMBER}-HelloWorldStack --require-approval never
# popd
deploy-text-extractor:
environment:
name: "dev"
runs-on: ubuntu-22.04
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existign action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# Deploy the text extractor lambda to AWS
- name: Deploy text extractor lambda
id: deploy-text-extractor
if: success() && steps.findPr.outputs.number
env:
PR: ${{ steps.findPr.outputs.pr }}
RUN_ID: ${{ github.run_id }}
run: |
pushd solution/text-extractor
npm install serverless@">=3.38.0 <4" -g
serverless deploy --stage dev${PR}
popd
deploy-django:
environment:
name: "dev"
outputs:
url: ${{ steps.deploy-regulations-site-server.outputs.url }}
runs-on: ubuntu-22.04
needs: [deploy-static, deploy-text-extractor]
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existign action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# should build first and save the artifact
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.14
# setup python
- uses: actions/setup-python@v5
if: success() && steps.findPr.outputs.number
with:
python-version: "3.12"
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# Deploy the regulation site to AWS
- name: deploy regulations site server
id: deploy-regulations-site-server
if: success() && steps.findPr.outputs.number
env:
PR: ${{ steps.findPr.outputs.pr }}
RUN_ID: ${{ github.run_id }}
run: |
pushd solution/backend
npm install serverless@">=3.38.0 <4" -g
npm install
serverless deploy --config ./serverless-experimental.yml --stage dev${PR} | tee output.log
serverless invoke --config ./serverless-experimental.yml --function create_database --stage dev${PR}
serverless invoke --config ./serverless-experimental.yml --function reg_core_migrate --stage dev${PR}
serverless invoke --config ./serverless-experimental.yml --function create_su --stage dev${PR}
url=$(cat output.log | grep -m1 'ANY -' | cut -c 9-)
url=${url%/}
echo "url=$(echo $url)" >> $GITHUB_OUTPUT
popd
test-python:
needs: [deploy-django]
runs-on: ubuntu-22.04
env:
STATIC_URL: http://localhost:8888/
DB_HOST: localhost
DB_NAME: eregs
DB_USER: eregs
DB_PASSWORD: sgere
DB_PORT: 5432
HTTP_AUTH_USER: ${{ secrets.HTTP_AUTH_USER }}
HTTP_AUTH_PASSWORD: ${{ secrets.HTTP_AUTH_PASSWORD }}
services:
postgres:
image: postgres
env:
STATIC_URL: http://localhost:8888/
POSTGRES_HOST: localhost
POSTGRES_DB: eregs
POSTGRES_USER: eregs
POSTGRES_PASSWORD: sgere
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
# checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# setup Python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./solution/static-assets/requirements.txt
# run Python unit tests
- name: Run Python unit tests
working-directory: ./solution/backend
run: |
DJANGO_SETTINGS_MODULE="cmcs_regulations.settings.test_settings" pytest -vv
build-and-deploy-vue:
environment:
name: "dev"
runs-on: ubuntu-22.04
needs: deploy-django
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existing action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# Setup node environment
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version:
18.14
# setup python
- uses: actions/setup-python@v5
if: success() && steps.findPr.outputs.number
with:
python-version: "3.12"
- name: Make envfile
uses: SpicyPizza/[email protected]
with:
envkey_VITE_API_URL: ${{ needs.deploy-django.outputs.url }}
directory: solution/ui/regulations/eregs-vite
file_name: .env
# build the static assets for the website
- name: build static assets
if: success() && steps.findPr.outputs.number
env:
STATIC_URL: http://localhost:8888/
STATIC_ROOT: ../static-assets/regulations
VITE_ENV: dev${{ steps.findPr.outputs.pr }}
run: |
pushd solution
make regulations
popd
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# deploy static assets to AWS
- name: deploy static assets
if: success() && steps.findPr.outputs.number
env:
PR: ${{ steps.findPr.outputs.pr }}
run: |
pushd solution/static-assets
npm install serverless@">=3.38.0 <4" -g
npm install
serverless deploy --stage dev${PR}
popd
deploy-go:
environment:
name: "dev"
runs-on: ubuntu-22.04
needs: deploy-django
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Find the PR number. This is not always trivial which is why this uses an existign action
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# deploy and run eCFR parser
- name: deploy and run eCFR parser
id: deploy-run-ecfr-parser
timeout-minutes: 20
env:
PR: ${{ steps.findPr.outputs.pr }}
run: |
pushd solution/parser
npm install serverless@">=3.38.0 <4" -g
serverless deploy --stage dev${PR} --config ./serverless-ecfr.yml
AWS_CLIENT_TIMEOUT=360000 serverless invoke --function ecfr_parser --stage dev${PR} --config ./serverless-ecfr.yml
popd
# deploy and run Federal Register parser
- name: deploy and run FR parser
id: deploy-run-fr-parser
env:
PR: ${{ steps.findPr.outputs.pr }}
run: |
pushd solution/parser
npm install serverless@">=3.38.0 <4" -g
serverless deploy --stage dev${PR} --config ./serverless-fr.yml
AWS_CLIENT_TIMEOUT=360000 serverless invoke --function fr_parser --stage dev${PR} --config ./serverless-fr.yml
popd
notify:
permissions:
pull-requests: write
runs-on: ubuntu-22.04
needs: [deploy-go, deploy-django]
steps:
- name: Find PR number
uses: jwalton/gh-find-current-pr@v1
id: findPr
with:
# Can be "open", "closed", or "all". Defaults to "open".
state: open
# Notify github that this is deployed and ready to look at
- name: Create deployment comment
uses: peter-evans/create-or-update-comment@v2
env:
django_url: ${{ needs.deploy-django.outputs.url }}
with:
issue-number: ${{ steps.findPr.outputs.pr }}
body: |
:sparkles: See the Django Site [in action][1] :sparkles:
[1]: ${{ env.django_url }}
reactions: "+1"
test-cypress:
environment:
name: "dev"
runs-on: ubuntu-22.04
needs: [deploy-django, build-and-deploy-vue]
#needs: [deploy-go, deploy-django, build-and-deploy-vue]
steps:
# Checkout the code
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
# Configure AWS credentials for GitHub Actions
- name: Configure AWS credentials for GitHub Actions
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_OIDC_ROLE_TO_ASSUME }}
aws-region: us-east-1
# Get test user credentials from AWS Parameter Store
- name: Get test user credentials
uses: dkershner6/aws-ssm-getparameters-action@v1
with:
parameterPairs: "/eregulations/http/user = CYPRESS_TEST_USERNAME,
/eregulations/http/password = CYPRESS_TEST_PASSWORD,
/eregulations/http/reader_user = CYPRESS_READER_USERNAME,
/eregulations/http/reader_password = CYPRESS_READER_PASSWORD"
withDecryption: "true" # defaults to true
# Setup node environment
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.14
# Run the cypress tests
- name: end-to-end tests
uses: cypress-io/github-action@v6
with:
working-directory: solution/ui/e2e
config: baseUrl=${{ needs.deploy-django.outputs.url }}
env:
CYPRESS_DEPLOYING: true
- uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-screenshots
path: /home/runner/work/cmcs-eregulations/cmcs-eregulations/solution/ui/e2e/cypress/screenshots/*/*
# Test run video was always captured, so this action uses "always()" condition
- uses: actions/upload-artifact@v4
if: always()
with:
name: cypress-videos
path: /home/runner/work/cmcs-eregulations/cmcs-eregulations/solution/ui/e2e/cypress/videos/*