Squashed commit of the following: #23
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: CD | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build: | |
name: build & deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout Github Action | |
uses: actions/checkout@v3 | |
- name: .env setting | |
run: | | |
echo "VITE_API_BASE_URL=${{ secrets.VITE_API_BASE_URL }}" >> .env.production | |
echo "VITE_API_ACCESS_TOKEN=${{ secrets.VITE_API_ACCESS_TOKEN }}" >> .env.production | |
echo "VITE_KAKAO_OAUTH_KEY=${{ secrets.VITE_KAKAO_OAUTH_KEY }}" >> .env.production | |
echo "VITE_KAKAO_REDIRECT_URI=${{ secrets.VITE_KAKAO_REDIRECT_URI }}" >> .env.production | |
echo "VITE_GOOGLE_OAUTH_KEY=${{ secrets.VITE_GOOGLE_OAUTH_KEY }}" >> .env.production | |
echo "VITE_GOOGLE_REDIRECT_URI=${{ secrets.VITE_GOOGLE_REDIRECT_URI }}" >> .env.production | |
- name: Get npm cache directory | |
id: npm-cache-dir | |
run: | | |
echo "::set-output name=dir::$(npm config get cache)" | |
- uses: actions/cache@v3 | |
id: npm-cache | |
with: | |
path: ${{ steps.npm-cache-dir.outputs.dir }} | |
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-node- | |
- name: install yarn dependencies | |
run: yarn install | |
- name: react build | |
run: yarn run build | |
# aws에 접근하기 위한 권한을 받아옵니다. | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_S3_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_S3_SECRET_KEY }} | |
aws-region: ap-northeast-2 | |
# S3에 build 파일을 올립니다. | |
- name: Upload to S3 | |
env: | |
BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME}} | |
run: | | |
aws s3 cp --recursive --region ap-northeast-2 dist s3://$BUCKET_NAME | |
# cloudfront로 배포되는 파일은 기본설정 상 24시간동안 캐시가 유지됩니다. | |
# 배포 후 S3에는 최신 정적리소스가 올라가있지만 엣지로케이션엔 이전 파일이 올라가있는 상태라는 의미입니다. | |
# 바로 변화가 반영되길 바란다면 invalidation을 해주면 됩니다. | |
# 해당 부분은 과금될 수 있으니 확인 후 사용하세요! | |
- name: CloudFront Invalidation | |
env: | |
CLOUD_FRONT_ID: ${{ secrets.AWS_CLOUDFRONT_ID}} | |
run: | | |
aws cloudfront create-invalidation \ | |
--distribution-id $CLOUD_FRONT_ID --paths "/*" |