Skip to content

Commit a999e96

Browse files
committed
fix deploy
1 parent 076d242 commit a999e96

4 files changed

Lines changed: 179 additions & 11 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,21 @@ jobs:
114114
echo "Deploy Path: $DEPLOY_PATH"
115115
116116
# S3에 파일 업로드 (경로별 배포)
117-
aws s3 sync dist/ s3://$BUCKET$DEPLOY_PATH --delete --cache-control "public, max-age=31536000"
117+
# 정적 파일들 업로드 (캐시 설정, HTML/JSON 제외)
118+
aws s3 sync dist/ s3://$BUCKET$DEPLOY_PATH --delete \
119+
--cache-control "public, max-age=31536000" \
120+
--exclude "*.html" \
121+
--exclude "*.json"
118122
119123
# HTML 파일은 캐시하지 않음
120-
aws s3 cp dist/index.html s3://$BUCKET$DEPLOY_PATH/index.html --cache-control "no-cache, no-store, must-revalidate"
124+
aws s3 cp dist/index.html s3://$BUCKET$DEPLOY_PATH/index.html \
125+
--cache-control "no-cache, no-store, must-revalidate"
126+
127+
# manifest.json 파일이 있으면 업로드
128+
if [ -f "dist/manifest.json" ]; then
129+
aws s3 cp dist/manifest.json s3://$BUCKET$DEPLOY_PATH/manifest.json \
130+
--cache-control "no-cache, no-store, must-revalidate"
131+
fi
121132
122133
echo "Deployment completed successfully!"
123134
echo "Application URL: https://$BUCKET.s3-website.ap-northeast-2.amazonaws.com$DEPLOY_PATH"
@@ -126,8 +137,60 @@ jobs:
126137
env:
127138
CLOUD_FRONT_ID: ${{ secrets.AWS_CLOUDFRONT_ID}}
128139
run: |
129-
aws cloudfront create-invalidation \
130-
--distribution-id $CLOUD_FRONT_ID --paths "/*"
140+
if [ -n "$CLOUD_FRONT_ID" ]; then
141+
echo "Invalidating CloudFront cache..."
142+
143+
# 무효화 요청 생성
144+
INVALIDATION_OUTPUT=$(aws cloudfront create-invalidation \
145+
--distribution-id $CLOUD_FRONT_ID \
146+
--paths "/*")
147+
148+
if [ $? -eq 0 ]; then
149+
# 무효화 ID 추출
150+
INVALIDATION_ID=$(echo "$INVALIDATION_OUTPUT" | grep -oP '"Id"\s*:\s*"\K[^"]+' | head -1)
151+
152+
if [ -n "$INVALIDATION_ID" ]; then
153+
echo "✅ CloudFront cache invalidation initiated: $INVALIDATION_ID"
154+
155+
# 무효화 완료까지 대기 (최대 15분)
156+
echo "Waiting for invalidation to complete (this may take up to 15 minutes)..."
157+
MAX_WAIT_TIME=900 # 15분 (초)
158+
WAIT_INTERVAL=10 # 10초마다 확인
159+
ELAPSED_TIME=0
160+
161+
while [ $ELAPSED_TIME -lt $MAX_WAIT_TIME ]; do
162+
sleep $WAIT_INTERVAL
163+
ELAPSED_TIME=$((ELAPSED_TIME + WAIT_INTERVAL))
164+
165+
STATUS_OUTPUT=$(aws cloudfront get-invalidation \
166+
--distribution-id $CLOUD_FRONT_ID \
167+
--id $INVALIDATION_ID 2>&1)
168+
169+
if [ $? -eq 0 ]; then
170+
STATUS=$(echo "$STATUS_OUTPUT" | grep -oP '"Status"\s*:\s*"\K[^"]+' | head -1)
171+
172+
if [ "$STATUS" == "Completed" ]; then
173+
echo "✅ CloudFront cache invalidation completed!"
174+
break
175+
elif [ "$STATUS" == "InProgress" ]; then
176+
PROGRESS=$((ELAPSED_TIME * 100 / MAX_WAIT_TIME))
177+
echo "Invalidation in progress... (${PROGRESS}% of max wait time elapsed)"
178+
fi
179+
fi
180+
done
181+
182+
if [ $ELAPSED_TIME -ge $MAX_WAIT_TIME ]; then
183+
echo "⚠️ Invalidation is still in progress after maximum wait time. It will continue in the background."
184+
fi
185+
else
186+
echo "⚠️ Failed to extract invalidation ID from response"
187+
fi
188+
else
189+
echo "⚠️ Failed to invalidate CloudFront cache"
190+
fi
191+
else
192+
echo "⚠️ CloudFront ID not configured, skipping invalidation"
193+
fi
131194
132195
- name: Notify deployment
133196
if: always()

scripts/deploy.ps1

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ if ($LASTEXITCODE -ne 0) {
8383
exit 1
8484
}
8585

86+
# 빌드 전 dist 폴더 완전 삭제 (캐시 무효화 보장)
87+
Write-Info "Cleaning dist folder..."
88+
if (Test-Path "dist") {
89+
Remove-Item -Path "dist" -Recurse -Force
90+
Write-Success "Dist folder cleaned"
91+
} else {
92+
Write-Info "Dist folder does not exist, skipping cleanup"
93+
}
94+
8695
# 빌드
8796
Write-Info "Building application..."
8897
switch ($Environment) {
@@ -170,13 +179,45 @@ if (Test-Path "dist/manifest.json") {
170179
}
171180
}
172181

173-
# CloudFront 캐시 무효화
182+
# CloudFront 캐시 무효화 및 완료 대기
174183
if ($CloudFrontId) {
175184
Write-Info "Invalidating CloudFront cache..."
176-
aws cloudfront create-invalidation --distribution-id $CloudFrontId --paths "/*"
177185

178-
if ($LASTEXITCODE -eq 0) {
179-
Write-Success "CloudFront cache invalidation initiated"
186+
# 무효화 요청 생성
187+
$invalidationOutput = aws cloudfront create-invalidation --distribution-id $CloudFrontId --paths "/*" | ConvertFrom-Json
188+
189+
if ($LASTEXITCODE -eq 0 -and $invalidationOutput) {
190+
$invalidationId = $invalidationOutput.Invalidation.Id
191+
Write-Success "CloudFront cache invalidation initiated: $invalidationId"
192+
193+
# 무효화 완료까지 대기 (최대 15분)
194+
Write-Info "Waiting for invalidation to complete (this may take up to 15 minutes)..."
195+
$maxWaitTime = 900 # 15분 (초)
196+
$waitInterval = 10 # 10초마다 확인
197+
$elapsedTime = 0
198+
199+
while ($elapsedTime -lt $maxWaitTime) {
200+
Start-Sleep -Seconds $waitInterval
201+
$elapsedTime += $waitInterval
202+
203+
$statusOutput = aws cloudfront get-invalidation --distribution-id $CloudFrontId --id $invalidationId | ConvertFrom-Json
204+
205+
if ($statusOutput -and $statusOutput.Invalidation) {
206+
$status = $statusOutput.Invalidation.Status
207+
208+
if ($status -eq "Completed") {
209+
Write-Success "CloudFront cache invalidation completed!"
210+
break
211+
} elseif ($status -eq "InProgress") {
212+
$progress = [math]::Round(($elapsedTime / $maxWaitTime) * 100, 1)
213+
Write-Info "Invalidation in progress... ($progress% of max wait time elapsed)"
214+
}
215+
}
216+
}
217+
218+
if ($elapsedTime -ge $maxWaitTime) {
219+
Write-Warning "Invalidation is still in progress after maximum wait time. It will continue in the background."
220+
}
180221
} else {
181222
Write-Warning "Failed to invalidate CloudFront cache"
182223
}

scripts/deploy.sh

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ if ! node scripts/setup-env.js $ENVIRONMENT validate; then
6565
exit 1
6666
fi
6767

68+
# 빌드 전 dist 폴더 완전 삭제 (캐시 무효화 보장)
69+
log_info "Cleaning dist folder..."
70+
if [[ -d "dist" ]]; then
71+
rm -rf dist
72+
log_success "Dist folder cleaned"
73+
else
74+
log_info "Dist folder does not exist, skipping cleanup"
75+
fi
76+
6877
# 빌드
6978
log_info "Building application..."
7079
case $ENVIRONMENT in
@@ -129,11 +138,54 @@ if [[ -f "dist/manifest.json" ]]; then
129138
--cache-control "no-cache, no-store, must-revalidate"
130139
fi
131140

132-
# CloudFront 캐시 무효화
141+
# CloudFront 캐시 무효화 및 완료 대기
133142
if [[ -n "$CLOUDFRONT_ID" ]]; then
134143
log_info "Invalidating CloudFront cache..."
135-
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths "/*"
136-
log_success "CloudFront cache invalidation initiated"
144+
145+
# 무효화 요청 생성
146+
INVALIDATION_OUTPUT=$(aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths "/*" 2>&1)
147+
148+
if [[ $? -eq 0 ]]; then
149+
# 무효화 ID 추출
150+
INVALIDATION_ID=$(echo "$INVALIDATION_OUTPUT" | grep -oP '"Id"\s*:\s*"\K[^"]+' | head -1)
151+
152+
if [[ -n "$INVALIDATION_ID" ]]; then
153+
log_success "CloudFront cache invalidation initiated: $INVALIDATION_ID"
154+
155+
# 무효화 완료까지 대기 (최대 15분)
156+
log_info "Waiting for invalidation to complete (this may take up to 15 minutes)..."
157+
MAX_WAIT_TIME=900 # 15분 (초)
158+
WAIT_INTERVAL=10 # 10초마다 확인
159+
ELAPSED_TIME=0
160+
161+
while [[ $ELAPSED_TIME -lt $MAX_WAIT_TIME ]]; do
162+
sleep $WAIT_INTERVAL
163+
ELAPSED_TIME=$((ELAPSED_TIME + WAIT_INTERVAL))
164+
165+
STATUS_OUTPUT=$(aws cloudfront get-invalidation --distribution-id $CLOUDFRONT_ID --id $INVALIDATION_ID 2>&1)
166+
167+
if [[ $? -eq 0 ]]; then
168+
STATUS=$(echo "$STATUS_OUTPUT" | grep -oP '"Status"\s*:\s*"\K[^"]+' | head -1)
169+
170+
if [[ "$STATUS" == "Completed" ]]; then
171+
log_success "CloudFront cache invalidation completed!"
172+
break
173+
elif [[ "$STATUS" == "InProgress" ]]; then
174+
PROGRESS=$((ELAPSED_TIME * 100 / MAX_WAIT_TIME))
175+
log_info "Invalidation in progress... (${PROGRESS}% of max wait time elapsed)"
176+
fi
177+
fi
178+
done
179+
180+
if [[ $ELAPSED_TIME -ge $MAX_WAIT_TIME ]]; then
181+
log_warning "Invalidation is still in progress after maximum wait time. It will continue in the background."
182+
fi
183+
else
184+
log_warning "Failed to extract invalidation ID from response"
185+
fi
186+
else
187+
log_warning "Failed to invalidate CloudFront cache"
188+
fi
137189
fi
138190

139191
log_success "Deployment completed successfully!"

vue.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ module.exports = defineConfig({
8181
},
8282
extensions: ['.js', '.vue', '.json']
8383
},
84+
// 파일명에 contenthash를 명시적으로 포함하여 캐시 무효화 보장
85+
output: {
86+
filename: 'js/[name].[contenthash:8].js',
87+
chunkFilename: 'js/[name].[contenthash:8].js'
88+
},
8489
plugins: [
8590
new (require('html-webpack-plugin'))({
8691
template: 'public/index.html',
@@ -89,5 +94,12 @@ module.exports = defineConfig({
8994
}
9095
})
9196
]
97+
},
98+
// CSS 파일도 해시 포함
99+
css: {
100+
extract: {
101+
filename: 'css/[name].[contenthash:8].css',
102+
chunkFilename: 'css/[name].[contenthash:8].css'
103+
}
92104
}
93105
})

0 commit comments

Comments
 (0)