API Server Deploy to Production #9
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: API Server Deploy to Production | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
AWS_REGION: ap-northeast-2 | |
S3_BUCKET_NAME: adevspoon-api-codedeploy-bucket | |
CODE_DEPLOY_APPLICATION_NAME: adevspoon-api-deploy-app | |
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: adevspoon-api-deploy-group | |
jobs: | |
api-server-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
# Repo checkout | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.TOKEN_GITHUB }} | |
submodules: true | |
# JDK 환경 셋팅 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'zulu' | |
java-version: '17' | |
cache: gradle | |
# Gradle Permission | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
# Build App | |
- name: Gradle Build | |
run: | | |
./gradlew globalCopyConfig | |
./gradlew adevspoon-api:build -x test | |
# AWS Config | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
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 Upload | |
- name: S3 Upload | |
run: | | |
aws deploy push \ | |
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | |
--ignore-hidden-files \ | |
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \ | |
--source ./adevspoon-api | |
# Code Deploy 실행 (블루-그린 배포) | |
- name: CodeDeploy - Blue-Green Deployment | |
run: | | |
aws deploy create-deployment \ | |
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | |
--deployment-config-name CodeDeployDefault.OneAtATime \ | |
--deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \ | |
--s3-location bucket=$S3_BUCKET_NAME,bundleType=zip,key=$GITHUB_SHA.zip |