-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
41 deletions.
There are no files selected for viewing
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
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 |