API - Deploy Production Environment #2
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 - Deploy Production Environment | |
on: | |
push: | |
tags: | |
- Api-v* | |
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@v4 | |
with: | |
token: ${{ secrets.MY_TOKEN }} | |
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 |