-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (75 loc) · 2.91 KB
/
application-deployment.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
name: Application Build and Deployment Workflow
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
environment: development
permissions:
id-token: write
contents: read
steps:
- name: Checkout the code
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ secrets.AWS_ROLE }}
role-session-name: 'GitHub_to_AWS_via_FederatedOIDC'
aws-region: 'us-east-1'
- name: Run Unit Test
run: |
npm install
npm run test
- name: Build with Docker
run: |
docker build -t ${{ secrets.IMAGE_NAME }}:${{ github.sha }} .
- name: Image Vulnerability Scan with Trivy
uses: aquasecurity/trivy-action@master
with:
image-ref: '${{ secrets.IMAGE_NAME }}:${{ github.sha }}'
format: 'table'
exit-code: '1'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL'
output: 'trivy-image-scan-results.txt'
- name: Upload Trivy Image Scan Results Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: trivy-image-scan-results
path: trivy-image-scan-results.txt
- name: Push the image to ECR
run: |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ secrets.IMAGE_NAME }}
docker image push ${{ secrets.IMAGE_NAME }}:${{ github.sha }}
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition toomio-backend --query taskDefinition > task-definition.json
- name: Update the Amazon ECS task definition
id: task-definition
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: toomio-backend
image: ${{ secrets.IMAGE_NAME }}:${{ github.sha }}
environment-variables: |
MONGODB_URI=${{ secrets.MONGODB_URI }}
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION=${{ secrets.AWS_REGION }}
AWS_COGNITO_USER_POOL_ID=${{ secrets.AWS_COGNITO_USER_POOL_ID }}
AWS_COGNITO_CLIENT_ID=${{ secrets.AWS_COGNITO_CLIENT_ID }}
AWS_COGNITO_AUTHORITY=${{ secrets.AWS_COGNITO_AUTHORITY }}
AWS_SQS_URL=${{ secrets.AWS_SQS_URL }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-definition.outputs.task-definition }}
service: toomio-backend
cluster: toomio-backend
wait-for-service-stability: true