#7 fix: deploy.yml 스텝 수정 #46
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: Build and Deploy to EC2 | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
defaults: | |
run: | |
shell: bash | |
working-directory: ./backend | |
env: | |
AWS_S3_BUCKET: howabouttrip-backend-bucket | |
AWS_CODE_DEPLOY_APPLICATION: HowAboutTrip-Backend-CD | |
AWS_CODE_DEPLOY_GROUP: HowAboutTrip-Backend-CD-Group | |
jobs: | |
deploy: | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: Build Project and Test | |
run: ./gradlew build test | |
- name: Configure AWS credential | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-region: ap-northeast-2 | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Upload to S3 | |
run: aws deploy push --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --ignore-hidden-files --s3-location s3://$AWS_S3_BUCKET/HowAboutTrip-Backend-EC2/$GITHUB_SHA.zip --source . | |
- name: Code Deploy to EC2 | |
run: aws deploy create-deployment --application-name ${{ env.AWS_CODE_DEPLOY_APPLICATION }} --deployment-config-name CodeDeployDefault.AllAtOnce --deployment-group-name ${{ env.AWS_CODE_DEPLOY_GROUP }} --s3-location bucket=$AWS_S3_BUCKET,key=HowAboutTrip-Backend-EC2/$GITHUB_SHA.zip,bundleType=zip |