Merge pull request #40 from 28th-meetup/hotfix/nullPointer #40
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
# This is a basic workflow to help you get started with Actions | |
name: Deploy to Amazon EC2 | |
# Controls when the workflow will run | |
on: | |
# Triggers the 'Deploy' workflow when the pull request closed but only for the "master" branch | |
# pull_request: | |
# types : [ closed ] | |
# branches: [ master ] | |
push: | |
branches: [ "master" ] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Setting environment values | |
env: | |
AWS_REGION: ap-northeast-2 # EC2 Region | |
S3_BUCKET_NAME: jipbap-s3-bucket # S3 bucket name | |
CODE_DEPLOY_APPLICATION_NAME: jipbap-application | |
CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: jipbap-deployment-group | |
SERVER_PORT: ${{ secrets.SERVER_PORT }} | |
MYSQL_URL: ${{ secrets.MYSQL_URL }} | |
MYSQL_USERNAME: ${{ secrets.MYSQL_USERNAME }} | |
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }} | |
SECRET_PWD: ${{ secrets.SECRET_PWD }} | |
SECRET_JWT: ${{ secrets.SECRET_JWT }} | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "deploy" | |
deploy: | |
name: Deploy | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
environment: production | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
# (1) 기본 체크아웃 (v2->v3) | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# (2) JDK 17 세팅 (v1->v3) | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
# (3) Gradle 권한설정 | |
- name: Cache Gradle packages | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
shell: bash | |
# (4) Gradle build (Test 제외) | |
- name: Build with Gradle | |
run: ./gradlew build | |
shell: bash | |
# (5) AWS 인증 (access key 사용) | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
aws-region: ${{ env.AWS_REGION }} | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
# role-to-assume: ${{ env.IAM_ROLE_ARN }} | |
# (6) 빌드 결과물을 S3 버킷에 업로드 | |
- name: Upload to AWS S3 | |
run: | | |
aws deploy push \ | |
--application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ | |
--ignore-hidden-files \ | |
--s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \ | |
--source . | |
# (7) 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,key=$GITHUB_SHA.zip,bundleType=zip |