feat: deploy 워크플로우에 CloudFront 캐시 무효화 추가 #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy to S3 | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup pnpm | |
uses: pnpm/action-setup@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'pnpm' | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build | |
run: pnpm run build | |
env: | |
VITE_API_URL: ${{ secrets.VITE_API_URL }} | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Upload to S3 | |
run: | | |
aws s3 sync dist/ s3://${{ secrets.AWS_S3_BUCKET }} \ | |
--delete \ | |
--cache-control "max-age=31536000, immutable" \ | |
--exclude "index.html" | |
- name: Upload index.html | |
run: | | |
aws s3 cp dist/index.html s3://${{ secrets.AWS_S3_BUCKET }}/index.html \ | |
--cache-control "no-cache" \ | |
--content-type "text/html; charset=utf-8" | |
- name: Invalidate CloudFront | |
run: | | |
aws cloudfront create-invalidation \ | |
--distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} \ | |
--paths "/*" |