-
Notifications
You must be signed in to change notification settings - Fork 0
84 lines (71 loc) · 2.74 KB
/
Copy pathdeploy.yml
File metadata and controls
84 lines (71 loc) · 2.74 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
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
name: Deploy to AWS S3 + CloudFront
on:
push:
branches:
- prod
pull_request:
branches:
- prod
types: [closed]
workflow_dispatch: # 수동 실행 가능
env:
AWS_REGION: ap-northeast-2
S3_BUCKET: ${{ secrets.S3_BUCKET_NAME }}
CLOUDFRONT_DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
# PR이 머지되었을 때만 실행 (closed + merged)
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build project
run: npm run build
env:
VITE_API_URL: ${{ secrets.VITE_API_URL }}
VITE_WS_URL: ${{ secrets.VITE_WS_URL }}
VITE_GRAMMAR_WS_URL: ${{ secrets.VITE_GRAMMAR_WS_URL }}
VITE_AWS_REGION: ${{ secrets.VITE_AWS_REGION }}
VITE_COGNITO_REGION: ${{ secrets.VITE_AWS_REGION }}
VITE_USER_POOL_ID: ${{ secrets.VITE_USER_POOL_ID }}
VITE_USER_POOL_CLIENT_ID: ${{ secrets.VITE_USER_POOL_CLIENT_ID }}
VITE_COGNITO_POOL_ID: ${{ secrets.VITE_USER_POOL_ID }}
VITE_COGNITO_CLIENT_ID: ${{ secrets.VITE_USER_POOL_CLIENT_ID }}
VITE_APP_ENV: production
VITE_USE_MOCK: false
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Deploy to S3
run: |
aws s3 sync dist/ s3://${{ env.S3_BUCKET }} \
--delete \
--cache-control "public, max-age=31536000" \
--exclude "index.html" \
--exclude "*.json"
# index.html과 JSON은 캐시하지 않음
aws s3 cp dist/index.html s3://${{ env.S3_BUCKET }}/index.html \
--cache-control "no-cache, no-store, must-revalidate"
# manifest.json 등
aws s3 sync dist/ s3://${{ env.S3_BUCKET }} \
--exclude "*" \
--include "*.json" \
--cache-control "no-cache"
- name: Invalidate CloudFront cache
run: |
aws cloudfront create-invalidation \
--distribution-id ${{ env.CLOUDFRONT_DISTRIBUTION_ID }} \
--paths "/*"
- name: Deployment complete
run: echo "Deployment to S3 and CloudFront completed successfully!"