Update main.yml #26
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
#main.yml | |
name: master | |
on: | |
push: | |
branches: [develop] | |
env: | |
AWS_REGION: ap-northeast-2 | |
S3_BUCKET_NAME: pick-read-me-actions-s3-bucket | |
CODE_DEPLOY_APPLICATION_NAME: pick-read-me-codedeploy-app | |
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: pick-read-me-codedeploy-group-front | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v2 | |
- name: Cache node modules | |
uses: actions/cache@v1 | |
with: | |
path: node_modules | |
key: ${{ runner.OS }}-master-build-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.OS }}-build- | |
${{ runner.OS }}- | |
- name: Install Dependencies | |
run: yarn | |
- name: Build | |
run: yarn build | |
- name: Include appspec.yml | |
run: mv appspec.yml ./build | |
- name: Include Scripts | |
run: mv deploy.sh ./build | |
- name: Make Zip File | |
run: zip -r ./$GITHUB_SHA.zip build/ | |
shell: bash | |
# AWS 인증 (IAM 사용자 Access Key, Secret Key 활용) | |
- 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.AWS_REGION }} | |
# 빌드 결과물을 S3 버킷에 업로드 | |
- name: Upload to S3 | |
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$S3_BUCKET_NAME/fe/$GITHUB_SHA.zip | |
# S3 버킷에 있는 파일을 대상으로 CodeDeploy 실행 | |
- name: Deploy to AWS EC2 from S3 | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | |
--deployment-config-name CodeDeployDefault.AllAtOnce \ | |
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \ | |
--s3-location bucket=$S3_BUCKET_NAME,fe,key=$GITHUB_SHA.zip,bundleType=zip |