From f7e59bbf0744034cb6e8aedad0c3490a0ba8dc03 Mon Sep 17 00:00:00 2001 From: Daewon Kang <96184691+Daewony@users.noreply.github.com> Date: Tue, 19 Mar 2024 02:07:38 +0900 Subject: [PATCH] Update build-and-deploy.yaml --- .github/workflows/build-and-deploy.yaml | 70 ++++++++++--------------- 1 file changed, 29 insertions(+), 41 deletions(-) diff --git a/.github/workflows/build-and-deploy.yaml b/.github/workflows/build-and-deploy.yaml index 3a61aa0..ae61610 100644 --- a/.github/workflows/build-and-deploy.yaml +++ b/.github/workflows/build-and-deploy.yaml @@ -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