1+ # .github/workflows/deploy-optimized.yml
2+ name : Deploy to S3 (Optimized)
3+
4+ on :
5+ push :
6+ branches : [main]
7+
8+ env :
9+ AWS_REGION : ap-northeast-2
10+ BUILD_DIR : ./apps/watcha_clone_coding/dist
11+
12+ jobs :
13+ deploy :
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - name : Checkout code
18+ uses : actions/checkout@v4
19+
20+ - name : Setup Node.js
21+ uses : actions/setup-node@v4
22+ with :
23+ node-version : ' 22.13.0'
24+
25+ - name : Setup pnpm
26+ uses : pnpm/action-setup@v4
27+ with :
28+ version : ' 10.15.1'
29+
30+ - name : Get pnpm store directory
31+ shell : bash
32+ run : |
33+ echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
34+
35+ - name : Setup pnpm cache
36+ uses : actions/cache@v4
37+ with :
38+ path : ${{ env.STORE_PATH }}
39+ key : ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
40+ restore-keys : |
41+ ${{ runner.os }}-pnpm-store-
42+
43+ - name : Install dependencies
44+ run : pnpm install --frozen-lockfile
45+
46+ - name : Build workspace packages
47+ run : |
48+ echo "=== 워크스페이스 패키지들 빌드 ==="
49+ pnpm --filter @watcha/carousel build
50+
51+ - name : Run type check
52+ run : pnpm type-check
53+
54+ - name : Build for production
55+ run : pnpm build:production
56+
57+ - name : Configure AWS credentials
58+ uses : aws-actions/configure-aws-credentials@v4
59+ with :
60+ aws-access-key-id : ${{ secrets.AWS_ACCESS_KEY_ID }}
61+ aws-secret-access-key : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
62+ aws-region : ${{ env.AWS_REGION }}
63+
64+ - name : Deploy to S3 with optimized settings
65+ env :
66+ S3_BUCKET_NAME : ${{ secrets.S3_BUCKET_NAME }}
67+ run : |
68+ # HTML 파일 업로드 - 캐시 비활성화
69+ aws s3 sync ${{ env.BUILD_DIR }} s3://$S3_BUCKET_NAME \
70+ --exclude "*" \
71+ --include "*.html" \
72+ --cache-control "max-age=0,must-revalidate,public" \
73+ --content-type "text/html; charset=utf-8" \
74+ --delete
75+
76+ # CSS 파일 업로드 - 1년 캐시
77+ aws s3 sync ${{ env.BUILD_DIR }} s3://$S3_BUCKET_NAME \
78+ --exclude "*" \
79+ --include "*.css" \
80+ --cache-control "max-age=31536000,public" \
81+ --content-type "text/css; charset=utf-8"
82+
83+ # JS 파일 업로드 - 1년 캐시
84+ aws s3 sync ${{ env.BUILD_DIR }} s3://$S3_BUCKET_NAME \
85+ --exclude "*" \
86+ --include "*.js" \
87+ --cache-control "max-age=31536000,public" \
88+ --content-type "application/javascript; charset=utf-8"
89+
90+ # 기타 파일들 (이미지, 폰트 등) 업로드 - 1년 캐시
91+ aws s3 sync ${{ env.BUILD_DIR }} s3://$S3_BUCKET_NAME \
92+ --exclude "*.html" \
93+ --exclude "*.css" \
94+ --exclude "*.js" \
95+ --cache-control "max-age=31536000,public"
96+
97+ - name : Invalidate CloudFront
98+ if : ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID != '' }}
99+ env :
100+ CLOUDFRONT_DISTRIBUTION_ID : ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}
101+ run : |
102+ aws cloudfront create-invalidation \
103+ --distribution-id $CLOUDFRONT_DISTRIBUTION_ID \
104+ --paths "/*.html" "/*.css" "/*.js"
0 commit comments