|
| 1 | +# ===================================================================== |
| 2 | +# develop push → Vite 빌드 → S3 업로드 → CloudFront 캐시 무효화 |
| 3 | +# |
| 4 | +# 필요한 GitHub Secrets (repo Settings > Secrets and variables > Actions): |
| 5 | +# AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY : S3+CloudFront 권한 IAM 키 |
| 6 | +# S3_FRONTEND_BUCKET : 프론트 정적 호스팅 버킷 (예: studyflow-frontend) |
| 7 | +# CLOUDFRONT_DISTRIBUTION_ID : CloudFront 배포 ID |
| 8 | +# VITE_API_BASE : 백엔드 주소 (예: https://studyflow-api.duckdns.org) |
| 9 | +# |
| 10 | +# 자세한 절차는 BE repo의 DEPLOY.md 참고 |
| 11 | +# ===================================================================== |
| 12 | +name: Deploy Frontend to S3/CloudFront |
| 13 | + |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: [develop] |
| 17 | + workflow_dispatch: {} # 수동 실행 버튼 |
| 18 | + |
| 19 | +jobs: |
| 20 | + build-and-deploy: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Setup Node |
| 28 | + uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: 20 |
| 31 | + cache: npm |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: npm ci |
| 35 | + |
| 36 | + - name: Build |
| 37 | + run: npm run build |
| 38 | + env: |
| 39 | + # 프로덕션 빌드는 VITE_API_BASE 미설정 시 의도적으로 실패한다 (src/api/config.js) |
| 40 | + VITE_API_BASE: ${{ secrets.VITE_API_BASE }} |
| 41 | + |
| 42 | + - name: Configure AWS credentials |
| 43 | + uses: aws-actions/configure-aws-credentials@v4 |
| 44 | + with: |
| 45 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 46 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 47 | + aws-region: ap-northeast-2 |
| 48 | + |
| 49 | + - name: Upload to S3 |
| 50 | + run: aws s3 sync dist "s3://${{ secrets.S3_FRONTEND_BUCKET }}" --delete |
| 51 | + |
| 52 | + - name: Invalidate CloudFront cache |
| 53 | + run: | |
| 54 | + aws cloudfront create-invalidation \ |
| 55 | + --distribution-id "${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }}" \ |
| 56 | + --paths "/*" |
0 commit comments