-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (47 loc) · 1.56 KB
/
Copy pathdeploy.yaml
File metadata and controls
50 lines (47 loc) · 1.56 KB
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
name: Deploy to S3
on:
push:
branches:
- main
jobs:
setup-infra:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
env:
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
REPO_NAME: ${{ github.event.repository.name }}
BRANCH_NAME: ${{ github.ref_name }}
steps:
- uses: actions/checkout@v4
- name: Set AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ap-southeast-2
role-to-assume: arn:aws:iam::${{secrets.AWS_ACCOUNT_ID}}:role/gh_deploy_role_${{ github.event.repository.name }}
- uses: hashicorp/setup-terraform@v3
- run: |
cd infra
terraform init -backend-config="bucket=terraform-state-$AWS_ACCOUNT_ID" -backend-config="key=$REPO_NAME/$BRANCH_NAME" -backend-config="dynamodb_table=terraform-state-$AWS_ACCOUNT_ID"
terraform apply --auto-approve
build-and-deploy:
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
steps:
- name: Set AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ap-southeast-2
role-to-assume: arn:aws:iam::${{secrets.AWS_ACCOUNT_ID}}:role/gh_deploy_role_${{ github.event.repository.name }}
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- run: npm install
- run: npm run build
- name: Deploy to S3
run: |
aws s3 sync build/ s3://${{github.event.repository.name}}-static-${{secrets.AWS_ACCOUNT_ID}} --delete