-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (114 loc) · 3.48 KB
/
Copy pathdeploy.yml
File metadata and controls
139 lines (114 loc) · 3.48 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
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
name: Deploy to S3
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
AWS_REGION: ap-northeast-2
NODE_VERSION: '18'
jobs:
# 빌드 및 테스트
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GIT_PERSONAL_ACCESS_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Setup environment
run: |
# 환경 결정 (개발/프로덕션만)
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
ENV="production"
else
ENV="development"
fi
# 환경변수 설정
node scripts/setup-env.js $ENV setup
echo "ENVIRONMENT=$ENV" >> $GITHUB_ENV
- name: Validate environment
run: npm run env:validate
- name: Lint code
run: npm run lint
- name: Clean dist folder
run: rm -rf dist
- name: Build application
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
npm run build:prod
else
npm run build:dev
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 1
# S3 배포
deploy:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GIT_PERSONAL_ACCESS_TOKEN }}
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- 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: ap-northeast-2
- name: Deploy to S3
run: |
# 환경 결정
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
ENV="production"
DEPLOY_PATH="/"
else
ENV="development"
DEPLOY_PATH="/dev/"
fi
BUCKET="${{ secrets.S3_BUCKET }}"
echo "Deploying to $ENV environment..."
echo "S3 Bucket: $BUCKET"
echo "Deploy Path: $DEPLOY_PATH"
# S3에 파일 업로드 (경로별 배포)
aws s3 sync dist/ s3://$BUCKET$DEPLOY_PATH --delete --cache-control "public, max-age=31536000"
# HTML 파일은 캐시하지 않음
aws s3 cp dist/index.html s3://$BUCKET$DEPLOY_PATH/index.html --cache-control "no-cache, no-store, must-revalidate"
echo "Deployment completed successfully!"
echo "Application URL: https://$BUCKET.s3-website.ap-northeast-2.amazonaws.com$DEPLOY_PATH"
- name: CloudFront Invalidation
env:
CLOUD_FRONT_ID: ${{ secrets.AWS_CLOUDFRONT_ID}}
run: |
aws cloudfront create-invalidation \
--distribution-id $CLOUD_FRONT_ID --paths "/*"
- name: Notify deployment
if: always()
run: |
if [[ "${{ job.status }}" == "success" ]]; then
echo "✅ Deployment successful!"
else
echo "❌ Deployment failed!"
fi