Skip to content

Commit

Permalink
Update build-and-deploy.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Daewony authored Mar 18, 2024
1 parent 36a6682 commit f7e59bb
Showing 1 changed file with 29 additions and 41 deletions.
70 changes: 29 additions & 41 deletions .github/workflows/build-and-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
---
name: Build and Deploy React App to CloudFront
name: CD


on:
push:
branches:
- main
branches: [ main ]
pull_request:
branches: [ main ]


jobs:
build-and-deploy:
name: Build and Deploy
build:
runs-on: ubuntu-latest
env:
BUCKET: bookpharmacy.store
DIST: build
REGION: ap-northeast-2
DIST_ID: E1PK5JJPVPO0BO

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.REGION }}

- uses: actions/setup-node@v2
with:
node-version: '18'

- name: Install Dependencies
run: |
node --version
yarn install --production=true
- name: Build Static Website
run: yarn build

- name: Copy files to the production website with the AWS CLI
run: |
aws s3 sync --delete ${{ env.DIST }} s3://${{ env.BUCKET }}
- name: Checkout source code
uses: actions/checkout@v2 # workflow에서 액세스할 수 있도록 저장소를 체크아웃

- name: Install dependencies
run: yarn install

- name: Build
run: yarn build

- name: Copy files to the production website with the AWS CLI
run: |
aws cloudfront create-invalidation \
--distribution-id ${{ env.DIST_ID }} \
--paths "/*"
- name: S3 Deploy
run: aws s3 sync ./build s3://csr-test-1-bucket/ --acl bucket-owner-full-control # 현재 build된 폴더에 접근 후 s3 버킷인 csr-test-1-bucket에 파일 업로드
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
- name: Invalidate CloudFront Cache # 새로 리소스를 업데이트할 때 기존 캐시 무효화
uses: chetan/invalidate-cloudfront-action@master
env:
AWS_DISTRIBUTION: ${{ secrets.AWS_DISTRIBUTION_ID }}
PATHS: '/index.html'
continue-on-error: true

0 comments on commit f7e59bb

Please sign in to comment.