-
Notifications
You must be signed in to change notification settings - Fork 1
58 lines (54 loc) · 2.25 KB
/
Copy pathdeploy.yml
File metadata and controls
58 lines (54 loc) · 2.25 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
51
52
53
54
55
56
57
58
name: Deploy frontend to S3 and CloudFront
on:
push:
branches: [main, develop]
workflow_dispatch:
concurrency:
group: growit-frontend-${{ github.ref }}
cancel-in-progress: true
env:
AWS_REGION: ap-northeast-2
S3_BUCKET: ${{ github.ref_name == 'main' && vars.PROD_S3_BUCKET || vars.DEV_S3_BUCKET }}
CLOUDFRONT_DISTRIBUTION_ID: ${{ github.ref_name == 'main' && vars.PROD_CLOUDFRONT_DISTRIBUTION_ID || vars.DEV_CLOUDFRONT_DISTRIBUTION_ID }}
DEPLOY_API_URL: ${{ github.ref_name == 'main' && vars.PROD_API_URL || vars.DEV_API_URL }}
DEPLOY_REDIRECT_URL: ${{ github.ref_name == 'main' && vars.PROD_REDIRECT_URL || vars.DEV_REDIRECT_URL }}
DEPLOY_FRONTEND_URL: ${{ github.ref_name == 'main' && vars.PROD_FRONTEND_URL || vars.DEV_FRONTEND_URL }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: yarn
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Build static site
env:
NEXT_PUBLIC_API_URL: ${{ env.DEPLOY_API_URL }}
NEXT_PUBLIC_REDIRECT_URL: ${{ env.DEPLOY_REDIRECT_URL }}
NEXT_PUBLIC_CLOUDFRONT_VIDEO_URL: ${{ vars.NEXT_PUBLIC_CLOUDFRONT_VIDEO_URL }}
run: yarn build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::009075573241:role/growit-github-frontend-deploy
aws-region: ${{ env.AWS_REGION }}
- name: Upload immutable assets
run: |
aws s3 sync out/_next/ "s3://$S3_BUCKET/_next/" --delete \
--cache-control "public,max-age=31536000,immutable"
- name: Upload pages
run: |
aws s3 sync out/ "s3://$S3_BUCKET/" --delete --exclude "_next/*" \
--cache-control "public,max-age=0,must-revalidate"
- name: Invalidate CloudFront
run: aws cloudfront create-invalidation --distribution-id "$CLOUDFRONT_DISTRIBUTION_ID" --paths "/*"
- name: Verify frontend
run: curl --fail --retry 5 --retry-delay 10 "$DEPLOY_FRONTEND_URL/login/"