Skip to content

Commit 356070b

Browse files
committed
hotfix
1 parent 045d3c8 commit 356070b

1 file changed

Lines changed: 73 additions & 54 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 73 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,7 @@ jobs:
3535

3636
- name: Setup environment
3737
run: |
38-
# 환경 결정 (개발/프로덕션만)
39-
#if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
4038
ENV="production"
41-
#else
42-
# ENV="development"
43-
#fi
44-
45-
# 환경변수 설정
4639
node scripts/setup-env.js $ENV setup
4740
echo "ENVIRONMENT=$ENV" >> $GITHUB_ENV
4841
@@ -63,13 +56,7 @@ jobs:
6356
echo "✅ Cleanup completed!"
6457
6558
- name: Build application
66-
run: |
67-
#if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
68-
# npm run build:prod
69-
npm run build
70-
#else
71-
# npm run build:dev
72-
#fi
59+
run: npm run build
7360

7461
- name: Upload build artifacts
7562
uses: actions/upload-artifact@v4
@@ -106,54 +93,51 @@ jobs:
10693

10794
- name: Deploy to S3
10895
run: |
109-
# 환경 결정
110-
#if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
111-
ENV="production"
112-
DEPLOY_PATH="/"
113-
#else
114-
# ENV="development"
115-
# DEPLOY_PATH="/dev/"
116-
#fi
117-
118-
DEPLOY_PATH="/"
119-
12096
BUCKET="${{ secrets.S3_BUCKET }}"
12197
122-
echo "Deploying to $ENV environment..."
98+
echo "🚀 Starting deployment..."
12399
echo "S3 Bucket: $BUCKET"
124-
echo "Deploy Path: $DEPLOY_PATH"
125100
126-
# S3에 파일 업로드 (경로별 배포)
127-
# 정적 파일들 업로드 (캐시 설정, HTML/JSON 제외)
128-
aws s3 sync dist/ s3://$BUCKET$DEPLOY_PATH --delete \
129-
--cache-control "no-cache, no-store, must-revalidate" \
101+
# 1. 정적 에셋 업로드 (HTML/JSON 제외, 장기 캐시)
102+
echo "📦 Uploading static assets (JS, CSS, images) with long-term cache..."
103+
aws s3 sync dist/ s3://$BUCKET/ \
104+
--delete \
105+
--cache-control "public, max-age=31536000, immutable" \
130106
--exclude "*.html" \
131107
--exclude "*.json"
132108
133-
# HTML 파일은 캐시하지 않음
134-
aws s3 cp dist/index.html s3://$BUCKET$DEPLOY_PATH/index.html \
135-
--cache-control "no-cache, no-store, must-revalidate"
109+
# 2. JSON 파일 업로드 (no-cache)
110+
echo "📋 Uploading JSON files with no-cache..."
111+
find dist -name "*.json" -type f 2>/dev/null | while read file; do
112+
if [ -f "$file" ]; then
113+
RELATIVE_PATH="${file#dist/}"
114+
aws s3 cp "$file" s3://$BUCKET/$RELATIVE_PATH \
115+
--cache-control "no-cache, no-store, must-revalidate" \
116+
--content-type "application/json"
117+
echo " ✓ Uploaded: $RELATIVE_PATH"
118+
fi
119+
done
136120
137-
# manifest.json 파일이 있으면 업로드
138-
if [ -f "dist/manifest.json" ]; then
139-
aws s3 cp dist/manifest.json s3://$BUCKET$DEPLOY_PATH/manifest.json \
140-
--cache-control "no-cache, no-store, must-revalidate"
141-
fi
121+
# 3. HTML 파일 업로드 (no-cache) - 반드시 마지막!
122+
echo "📄 Uploading HTML files with no-cache..."
123+
aws s3 cp dist/index.html s3://$BUCKET/index.html \
124+
--cache-control "no-cache, no-store, must-revalidate" \
125+
--content-type "text/html"
142126
143-
echo "Deployment completed successfully!"
144-
echo "Application URL: https://$BUCKET.s3-website.ap-northeast-2.amazonaws.com$DEPLOY_PATH"
127+
echo "Deployment completed successfully!"
128+
echo "🌐 Application URL: https://$BUCKET/"
145129
146130
- name: CloudFront Invalidation
147131
env:
148132
CLOUD_FRONT_ID: ${{ secrets.AWS_CLOUDFRONT_ID}}
149133
run: |
150134
if [ -n "$CLOUD_FRONT_ID" ]; then
151-
echo "Invalidating CloudFront cache..."
135+
echo "🔄 Invalidating CloudFront cache..."
152136
153137
# 무효화 요청 생성
154138
INVALIDATION_OUTPUT=$(aws cloudfront create-invalidation \
155139
--distribution-id $CLOUD_FRONT_ID \
156-
--paths "/*")
140+
--paths "/*" 2>&1)
157141
158142
if [ $? -eq 0 ]; then
159143
# 무효화 ID 추출
@@ -163,9 +147,9 @@ jobs:
163147
echo "✅ CloudFront cache invalidation initiated: $INVALIDATION_ID"
164148
165149
# 무효화 완료까지 대기 (최대 15분)
166-
echo "Waiting for invalidation to complete (this may take up to 15 minutes)..."
167-
MAX_WAIT_TIME=900 # 15분 (초)
168-
WAIT_INTERVAL=10 # 10초마다 확인
150+
echo "Waiting for invalidation to complete..."
151+
MAX_WAIT_TIME=900 # 15분
152+
WAIT_INTERVAL=30 # 30초마다 확인
169153
ELAPSED_TIME=0
170154
171155
while [ $ELAPSED_TIME -lt $MAX_WAIT_TIME ]; do
@@ -183,30 +167,65 @@ jobs:
183167
echo "✅ CloudFront cache invalidation completed!"
184168
break
185169
elif [ "$STATUS" == "InProgress" ]; then
186-
PROGRESS=$((ELAPSED_TIME * 100 / MAX_WAIT_TIME))
187-
echo "Invalidation in progress... (${PROGRESS}% of max wait time elapsed)"
170+
MINUTES_ELAPSED=$((ELAPSED_TIME / 60))
171+
echo " ⏳ Still in progress... (${MINUTES_ELAPSED} minutes elapsed)"
188172
fi
189173
fi
190174
done
191175
192176
if [ $ELAPSED_TIME -ge $MAX_WAIT_TIME ]; then
193-
echo "⚠️ Invalidation is still in progress after maximum wait time. It will continue in the background."
177+
echo "⚠️ Invalidation is still in progress after 15 minutes."
178+
echo " It will continue in the background and complete soon."
194179
fi
195180
else
196-
echo "⚠️ Failed to extract invalidation ID from response"
181+
echo "⚠️ Failed to extract invalidation ID"
182+
echo "Response: $INVALIDATION_OUTPUT"
197183
fi
198184
else
199-
echo "⚠️ Failed to invalidate CloudFront cache"
185+
echo "❌ Failed to create CloudFront invalidation"
186+
echo "Error: $INVALIDATION_OUTPUT"
200187
fi
201188
else
202-
echo "⚠️ CloudFront ID not configured, skipping invalidation"
189+
echo "⚠️ CloudFront distribution ID not configured"
190+
echo " Skipping cache invalidation"
203191
fi
204192
193+
- name: Verify deployment
194+
run: |
195+
BUCKET="${{ secrets.S3_BUCKET }}"
196+
197+
echo "🔍 Verifying deployment..."
198+
199+
# index.html 헤더 확인
200+
echo "Checking index.html cache headers..."
201+
aws s3api head-object \
202+
--bucket $BUCKET \
203+
--key index.html \
204+
--query 'CacheControl' \
205+
--output text || echo "Failed to check index.html"
206+
207+
# JS 파일 확인 (첫 번째 JS 파일)
208+
FIRST_JS=$(aws s3 ls s3://$BUCKET/js/ | grep ".js" | head -1 | awk '{print $4}')
209+
if [ -n "$FIRST_JS" ]; then
210+
echo "Checking JS file cache headers..."
211+
aws s3api head-object \
212+
--bucket $BUCKET \
213+
--key "js/$FIRST_JS" \
214+
--query 'CacheControl' \
215+
--output text || echo "Failed to check JS file"
216+
fi
217+
218+
echo "✅ Verification completed!"
219+
205220
- name: Notify deployment
206221
if: always()
207222
run: |
208223
if [[ "${{ job.status }}" == "success" ]]; then
209-
echo "✅ Deployment successful!"
224+
echo "✅ 🎉 Deployment successful!"
225+
echo ""
226+
echo "Your application is now live!"
227+
echo "Users may need to hard refresh (Ctrl+Shift+R) to see changes."
210228
else
211229
echo "❌ Deployment failed!"
212-
fi
230+
echo "Please check the logs above for details."
231+
fi

0 commit comments

Comments
 (0)