-
Notifications
You must be signed in to change notification settings - Fork 0
533 lines (533 loc) · 21.6 KB
/
main-build-and-deploy.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
name: Main branch Build and Deployment
on:
pull_request:
types: [closed]
branches:
- main
jobs:
cancel-incomplete-validations:
name: Cancel all incomplete PR-validations for closed PR (further validation on closed PRs are irrelevant)
permissions:
actions: write
runs-on: ubuntu-22.04
concurrency:
group: PR validation-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
# Execution of this job (step) will cancel all incomplete PR-validation runs on the closed PR through GHA concurrency.
- name: Cancelling all PR validation runs for PR ${{ github.event.pull_request.number }}
run: |
echo "Done."
on-merge:
name: Skip on unmerged
if: github.event.pull_request.merged == true
runs-on: ubuntu-22.04
steps:
- name: Confirm execution
shell: bash
run: |
echo "PR merge detected and deployment wanted."
on-deploy:
name: Skip on 'no-deploy' PRs
needs: on-merge
if: '!contains(github.event.pull_request.labels.*.name, ''no-deploy'')'
runs-on: ubuntu-22.04
steps:
- name: Confirm execution
shell: bash
run: |
echo "PR merge detected and deployment wanted."
commit-deps-lock-updates:
name: Commit dependency lock updates as proposed during PR validation
concurrency:
group: ${{ github.workflow }}-commit-deps-lock-updates
cancel-in-progress: true
runs-on: ubuntu-22.04
needs:
- on-merge
permissions:
contents: write
outputs:
latest-commit-sha: ${{ steps.store-output.outputs.latest-commit-sha }}
git-describe: ${{ steps.store-output.outputs.git-describe }}
env:
latest_commit_sha:
steps:
- name: create token for committing and pushing as agr-github-actions app
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.GH_ACTIONS_APP_ID }}
private-key: ${{ secrets.GH_ACTIONS_APP_PRIVATE_KEY }}
- name: Get GitHub App User ID
id: app-user-id
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
persist-credentials: true
- name: Store checkout sha in env variable
run: |
echo "latest_commit_sha=$(git log -1 --format=%H)" >> "$GITHUB_ENV"
- name: Download updated dependencies lock files bundle
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-deps-lock-updates') }}
uses: dawidd6/action-download-artifact@v6
with:
name: deps_lock_files_bundle
pr: ${{ github.event.pull_request.number }}
workflow: PR-validation.yml
workflow_conclusion: success
workflow_search: false
allow_forks: false
if_no_artifact_found: fail
- name: Unpack the bundle
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-deps-lock-updates') }}
run: |
tar -xzv -f deps-lock-files.tar.gz
- name: commit dependency lock file changes
id: deps-lock-commit
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-deps-lock-updates') }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: ${{ github.base_ref }}
commit_user_name: ${{ steps.app-token.outputs.app-slug }}[bot]
commit_user_email: ${{ steps.app-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com
commit_author: ${{ steps.app-token.outputs.app-slug }}[bot] <${{ steps.app-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>
commit_message: Auto-updated deps lock files [skip actions]
file_pattern: '*requirements.txt *package-lock.json'
disable_globbing: true
skip_checkout: true
skip_fetch: true
- name: Store commit sha in env variable (if updated)
if: steps.deps-lock-commit.outputs.commit_hash
run: |
echo "latest_commit_sha=${{ steps.deps-lock-commit.outputs.commit_hash }}" >> "$GITHUB_ENV"
- name: store latest_commit_sha job output
id: store-output
run: |
echo "latest-commit-sha=${{ env.latest_commit_sha }}" >> "$GITHUB_OUTPUT"
echo "git-describe=$(git describe --tags)" >> $GITHUB_OUTPUT
build-pavi-shared-aws-module:
name: Build pavi_shared_aws package
runs-on: ubuntu-22.04
concurrency:
group: ${{ github.workflow }}-build-pavi-shared-aws-module
cancel-in-progress: true
needs: [commit-deps-lock-updates, on-deploy]
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-deps-lock-updates.outputs.latest-commit-sha }}
fetch-depth: 0
sparse-checkout: |
shared_aws/py_package/
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Build the pavi_shared_aws package
working-directory: ./shared_aws/py_package
run: |
make clean build
- name: Upload package as artifact
uses: actions/upload-artifact@v4
with:
name: shared_aws_py_package
path: shared_aws/py_package/dist/pavi_shared_aws-0.0.0-py3-none-any.whl
deploy-shared-aws-infra:
name: Deploy/update shared PAVI AWS infrastructure
concurrency:
group: ${{ github.workflow }}-deploy-shared-aws-infra
cancel-in-progress: false
needs:
- commit-deps-lock-updates
- on-deploy
- build-pavi-shared-aws-module
permissions:
id-token: write # This is required for requesting the JWT for gaining permissions to assume the IAM role to perform AWS actions
runs-on: ubuntu-22.04
defaults:
run:
working-directory: shared_aws/aws_infra
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-deps-lock-updates.outputs.latest-commit-sha }}
- name: Setup node.js (CDK CLI requirement)
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Download shared AWS package
uses: actions/download-artifact@v4
with:
name: shared_aws_py_package
path: /tmp/
- name: AWS credentials configuration
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.GH_ACTIONS_AWS_ROLE}}
role-session-name: gh-actions-${{github.run_id}}.${{github.run_number}}.${{github.run_attempt}}-cdk-deploy
aws-region: us-east-1
- name: CDK validations (resource assertions and cdk diff)
run: make validate-stack
- name: Deploy CDK Stack
run: make deploy-stack ADD_CDK_ARGS="--require-approval never"
pipeline-deploy-aws-infra:
name: Deploy/update AWS infrastructure for pipeline
concurrency:
group: ${{ github.workflow }}-pipeline-deploy-aws-infra
cancel-in-progress: false
needs:
- commit-deps-lock-updates
- on-deploy
- build-pavi-shared-aws-module
- deploy-shared-aws-infra
permissions:
id-token: write # This is required for requesting the JWT for gaining permissions to assume the IAM role to perform AWS actions
runs-on: ubuntu-22.04
defaults:
run:
working-directory: pipeline/aws_infra
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-deps-lock-updates.outputs.latest-commit-sha }}
- name: Setup node.js (CDK CLI requirement)
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Download shared AWS package
uses: actions/download-artifact@v4
with:
name: shared_aws_py_package
path: /tmp/
- name: AWS credentials configuration
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.GH_ACTIONS_AWS_ROLE}}
role-session-name: gh-actions-${{github.run_id}}.${{github.run_number}}.${{github.run_attempt}}-cdk-deploy
aws-region: us-east-1
- name: CDK validations (resource assertions and cdk diff)
run: make validate
- name: Deploy CDK Stack
run: make deploy ADD_CDK_ARGS="--require-approval never"
api-deploy-image-repo:
name: Deploy/update container image repository stack for API
concurrency:
group: ${{ github.workflow }}-api-deploy-image-repo
cancel-in-progress: false
needs:
- commit-deps-lock-updates
- on-deploy
- build-pavi-shared-aws-module
permissions:
id-token: write # This is required for requesting the JWT for gaining permissions to assume the IAM role to perform AWS actions
runs-on: ubuntu-22.04
defaults:
run:
working-directory: api/aws_infra
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-deps-lock-updates.outputs.latest-commit-sha }}
- name: Setup node.js (CDK CLI requirement)
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Download shared AWS package
uses: actions/download-artifact@v4
with:
name: shared_aws_py_package
path: /tmp/
- name: AWS credentials configuration
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.GH_ACTIONS_AWS_ROLE}}
role-session-name: gh-actions-${{github.run_id}}.${{github.run_number}}.${{github.run_attempt}}-cdk-deploy
aws-region: us-east-1
- name: CDK validations (resource assertions and cdk diff)
run: make validate-image-stack
- name: Deploy CDK stack
run: make deploy-image-stack ADD_CDK_ARGS="--require-approval never"
webui-deploy-image-repo:
name: Deploy/update container image repository stack for web UI
concurrency:
group: ${{ github.workflow }}-webui-deploy-image-repo
cancel-in-progress: false
needs:
- commit-deps-lock-updates
- on-deploy
- build-pavi-shared-aws-module
permissions:
id-token: write # This is required for requesting the JWT for gaining permissions to assume the IAM role to perform AWS actions
runs-on: ubuntu-22.04
defaults:
run:
working-directory: webui/aws_infra
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-deps-lock-updates.outputs.latest-commit-sha }}
- name: Setup node.js (CDK CLI requirement)
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Download shared AWS package
uses: actions/download-artifact@v4
with:
name: shared_aws_py_package
path: /tmp/
- name: AWS credentials configuration
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.GH_ACTIONS_AWS_ROLE}}
role-session-name: gh-actions-${{github.run_id}}.${{github.run_number}}.${{github.run_attempt}}-cdk-deploy
aws-region: us-east-1
- name: CDK validations (resource assertions and cdk diff)
run: make validate-image-stack
- name: Deploy CDK stack
run: make deploy-image-stack ADD_CDK_ARGS="--require-approval never"
pipeline-seq-retrieval-build-and-push-docker-image:
concurrency:
group: ${{ github.workflow }}-pipeline-seq-retrieval-build-and-push-docker-image
cancel-in-progress: false
needs: [on-deploy, pipeline-deploy-aws-infra, commit-deps-lock-updates]
permissions:
id-token: write # This is required for requesting the JWT for gaining permissions to assume the IAM role to perform AWS actions
runs-on: ubuntu-22.04
env:
tagname: ${{ needs.commit-deps-lock-updates.outputs.git-describe }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-deps-lock-updates.outputs.latest-commit-sha }}
sparse-checkout: |
pipeline/seq_retrieval/
# This step will configure environment variables to be used by all steps
# involving AWS interaction further down
- name: AWS credentials configuration
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.GH_ACTIONS_AWS_ROLE}}
role-session-name: gh-actions-${{github.run_id}}.${{github.run_number}}.${{github.run_attempt}}-build-image-pipeline-seq-retrieval
aws-region: us-east-1
- name: Amazon ECR login
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push container image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
with:
context: ./pipeline/seq_retrieval/
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/agr_pavi/pipeline_seq_retrieval:${{ env.tagname }}
${{ steps.login-ecr.outputs.registry }}/agr_pavi/pipeline_seq_retrieval:${{ github.event.pull_request.base.ref }}
platforms: linux/amd64
pipeline-alignment-build-and-push-docker-image:
concurrency:
group: ${{ github.workflow }}-pipeline-alignment-build-and-push-docker-image
cancel-in-progress: false
needs: [on-deploy, pipeline-deploy-aws-infra, commit-deps-lock-updates]
permissions:
id-token: write # This is required for requesting the JWT for gaining permissions to assume the IAM role to perform AWS actions
runs-on: ubuntu-22.04
env:
tagname: ${{ needs.commit-deps-lock-updates.outputs.git-describe }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-deps-lock-updates.outputs.latest-commit-sha }}
sparse-checkout: |
pipeline/alignment/
# This step will configure environment variables to be used by all steps
# involving AWS interaction further down
- name: AWS credentials configuration
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.GH_ACTIONS_AWS_ROLE}}
role-session-name: gh-actions-${{github.run_id}}.${{github.run_number}}.${{github.run_attempt}}-build-image-pipeline-seq-retrieval
aws-region: us-east-1
- name: Amazon ECR login
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push container image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
with:
context: ./pipeline/alignment/
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/agr_pavi/pipeline_alignment:${{ env.tagname }}
${{ steps.login-ecr.outputs.registry }}/agr_pavi/pipeline_alignment:${{ github.event.pull_request.base.ref }}
platforms: linux/amd64
api-build-and-push-docker-image:
concurrency:
group: ${{ github.workflow }}-api-build-and-push-docker-image
cancel-in-progress: false
needs: [on-deploy, api-deploy-image-repo, commit-deps-lock-updates]
permissions:
id-token: write # This is required for requesting the JWT for gaining permissions to assume the IAM role to perform AWS actions
runs-on: ubuntu-22.04
env:
tagname: ${{ needs.commit-deps-lock-updates.outputs.git-describe }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-deps-lock-updates.outputs.latest-commit-sha }}
# This step will configure environment variables to be used by all steps
# involving AWS interaction further down
- name: AWS credentials configuration
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.GH_ACTIONS_AWS_ROLE}}
role-session-name: gh-actions-${{github.run_id}}.${{github.run_number}}.${{github.run_attempt}}-build-image-api
aws-region: us-east-1
- name: Amazon ECR login
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push container image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
with:
context: ./
file: api/Dockerfile
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/agr_pavi/api:${{ env.tagname }}
${{ steps.login-ecr.outputs.registry }}/agr_pavi/api:${{ github.event.pull_request.base.ref }}
platforms: linux/amd64
webui-build-and-push-docker-image:
concurrency:
group: ${{ github.workflow }}-webui-build-and-push-docker-image
cancel-in-progress: false
needs: [on-deploy, webui-deploy-image-repo, commit-deps-lock-updates]
permissions:
id-token: write # This is required for requesting the JWT for gaining permissions to assume the IAM role to perform AWS actions
runs-on: ubuntu-22.04
env:
tagname: ${{ needs.commit-deps-lock-updates.outputs.git-describe }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-deps-lock-updates.outputs.latest-commit-sha }}
# This step will configure environment variables to be used by all steps
# involving AWS interaction further down
- name: AWS credentials configuration
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.GH_ACTIONS_AWS_ROLE}}
role-session-name: gh-actions-${{github.run_id}}.${{github.run_number}}.${{github.run_attempt}}-build-image-webui
aws-region: us-east-1
- name: Amazon ECR login
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build and push container image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
with:
context: ./webui/
push: true
tags: |
${{ steps.login-ecr.outputs.registry }}/agr_pavi/webui:${{ env.tagname }}
${{ steps.login-ecr.outputs.registry }}/agr_pavi/webui:${{ github.event.pull_request.base.ref }}
platforms: linux/amd64
deploy-application:
name: Deploy application (version) (API and WebUI)
concurrency:
group: ${{ github.workflow }}-deploy-application
cancel-in-progress: false
needs:
- on-deploy
- commit-deps-lock-updates
- build-pavi-shared-aws-module
- api-build-and-push-docker-image
- pipeline-alignment-build-and-push-docker-image
- pipeline-seq-retrieval-build-and-push-docker-image
- webui-build-and-push-docker-image
- deploy-shared-aws-infra
permissions:
id-token: write # This is required for requesting the JWT for gaining permissions to assume the IAM role to perform AWS actions
runs-on: ubuntu-22.04
env:
tagname: ${{ needs.commit-deps-lock-updates.outputs.git-describe }}
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: ${{ needs.commit-deps-lock-updates.outputs.latest-commit-sha }}
- name: Setup node.js (CDK CLI requirement)
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Download shared AWS package
uses: actions/download-artifact@v4
with:
name: shared_aws_py_package
path: /tmp/
- name: AWS credentials configuration
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{secrets.GH_ACTIONS_AWS_ROLE}}
role-session-name: gh-actions-${{github.run_id}}.${{github.run_number}}.${{github.run_attempt}}-app-cdk-deploy
aws-region: us-east-1
# API validation and deployment
- name: API CDK validations (resource assertions and cdk diff)
working-directory: api/aws_infra
run: make validate-application-stack validate-environment-stack PAVI_DEPLOY_VERSION_LABEL="${{ env.tagname }}" PAVI_IMAGE_TAG="${{ env.tagname }}"
- name: Deploy API application (and version)
working-directory: api/aws_infra
run: make deploy-application PAVI_DEPLOY_VERSION_LABEL="${{ env.tagname }}" ADD_CDK_ARGS="--require-approval never"
- name: Deploy API to main environment
working-directory: api/aws_infra
run: make deploy-environment PAVI_DEPLOY_VERSION_LABEL="${{ env.tagname }}" PAVI_IMAGE_TAG="${{ env.tagname }}" \
EB_ENV_CDK_STACK_NAME=PaviApiEbMainStack ADD_CDK_ARGS="--require-approval never"
# webUI validation and deployment
- name: webUI CDK validations (resource assertions and cdk diff)
working-directory: webui/aws_infra
run: make validate-application-stack validate-environment-stack PAVI_API_ENV_NAME="PAVI-api-main" \
PAVI_DEPLOY_VERSION_LABEL="${{ env.tagname }}" PAVI_IMAGE_TAG="${{ env.tagname }}"
- name: Deploy webUI application (and version)
working-directory: webui/aws_infra
run: make deploy-application PAVI_DEPLOY_VERSION_LABEL="${{ env.tagname }}" ADD_CDK_ARGS="--require-approval never"
- name: Deploy webUI to main environment
working-directory: webui/aws_infra
run: make deploy-environment PAVI_API_ENV_NAME="PAVI-api-main" \
PAVI_DEPLOY_VERSION_LABEL="${{ env.tagname }}" PAVI_IMAGE_TAG="${{ env.tagname }}" \
EB_ENV_CDK_STACK_NAME=PaviWebUiEbMainStack ADD_CDK_ARGS="--require-approval never"