Skip to content

Commit 4f0b7ce

Browse files
authored
Merge pull request #59 from f-lab-edu/refactoring
S3 배포 스크립트에서 비밀 변수 사용 개선 및 CloudFront 무효화 조건 추가
2 parents cf07ee3 + 149db16 commit 4f0b7ce

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

.github/workflows/deploy-optimized.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,48 @@ jobs:
6262
aws-region: ${{ env.AWS_REGION }}
6363

6464
- name: Deploy to S3 with optimized settings
65+
env:
66+
S3_BUCKET: ${{ secrets.S3_BUCKET_NAME }}
6567
run: |
6668
# HTML 파일 업로드 - 캐시 비활성화
67-
aws s3 sync ${{ env.BUILD_DIR }} s3://${{ secrets.S3_BUCKET_NAME }} \
69+
aws s3 sync ${{ env.BUILD_DIR }} s3://$S3_BUCKET \
6870
--exclude "*" \
6971
--include "*.html" \
7072
--cache-control "max-age=0,must-revalidate,public" \
7173
--content-type "text/html; charset=utf-8" \
7274
--delete
7375
7476
# CSS 파일 업로드 - 1년 캐시
75-
aws s3 sync ${{ env.BUILD_DIR }} s3://${{ secrets.S3_BUCKET_NAME }} \
77+
aws s3 sync ${{ env.BUILD_DIR }} s3://$S3_BUCKET \
7678
--exclude "*" \
7779
--include "*.css" \
7880
--cache-control "max-age=31536000,public" \
7981
--content-type "text/css; charset=utf-8"
8082
8183
# JS 파일 업로드 - 1년 캐시
82-
aws s3 sync ${{ env.BUILD_DIR }} s3://${{ secrets.S3_BUCKET_NAME }} \
84+
aws s3 sync ${{ env.BUILD_DIR }} s3://$S3_BUCKET \
8385
--exclude "*" \
8486
--include "*.js" \
8587
--cache-control "max-age=31536000,public" \
8688
--content-type "application/javascript; charset=utf-8"
8789
88-
# 기타 파일들 (이미지, 폰트 등) 업로드 - 1년 캐시
89-
aws s3 sync ${{ env.BUILD_DIR }} s3://${{ secrets.S3_BUCKET_NAME }} \
90+
# 기타 파일들 업로드 - 1년 캐시
91+
aws s3 sync ${{ env.BUILD_DIR }} s3://$S3_BUCKET \
9092
--exclude "*.html" \
9193
--exclude "*.css" \
9294
--exclude "*.js" \
9395
--cache-control "max-age=31536000,public"
9496
9597
- name: Invalidate CloudFront
96-
if: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
98+
env:
99+
DISTRIBUTION_ID: ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
97100
run: |
98-
aws cloudfront create-invalidation \
99-
--distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \
100-
--paths "/*.html" "/*.css" "/*.js"
101+
if [ -n "$DISTRIBUTION_ID" ]; then
102+
echo "CloudFront 무효화 시작..."
103+
aws cloudfront create-invalidation \
104+
--distribution-id $DISTRIBUTION_ID \
105+
--paths "/*.html" "/*.css" "/*.js"
106+
echo "CloudFront 무효화 완료"
107+
else
108+
echo "CloudFront Distribution ID가 설정되지 않았습니다. 무효화를 건너뜁니다."
109+
fi

0 commit comments

Comments
 (0)