Skip to content

hotfix

hotfix #25

Workflow file for this run

name: Build and Deploy to EC2
# 워크플로우가 언제 실행될 것인지 조건 명시
on:
push:
branches: [ "develop"]
# AWS 관련 값 변수로 설정
env:
AWS_REGION: ap-northeast-2
AWS_S3_BUCKET: imdang-bucket
AWS_CODE_DEPLOY_APPLICATION: imdang-application
AWS_CODE_DEPLOY_GROUP: imdang-deployment-group
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
# JDK 17 설치
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
# 공개되면 안되는 정보를 담은 .yml 파일을 생성
- name: make application.yml
run: |
mkdir -p ./imdang-container/src/main/resources
cd ./imdang-container/src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION }}" > ./application.yml
- name: make key
run: |
mkdir -p ./imdang-container/src/main/resources/key
cd ./imdang-container/src/main/resources/key
touch ./AuthKey_2AGQTHACLC.p8
echo "${{ secrets.APPLE_KEY }}" > ./AuthKey_2AGQTHACLC.p8
touch ./firebase_imdang.json
echo "${{ secrets.FIREBASE_KEY }}" | base64 -d > ./firebase_imdang.json
# 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Build and Test
run: ./gradlew imdang-container:clean imdang-container:assemble
# 빌드 파일을 zip 형식으로 압축 - S3에서는 jar 저장이 안되기 때문에 zip으로 생성
- name: Make zip file
run: zip -r ./$GITHUB_SHA.zip .
shell: bash
# AWS 권한
- name: AWS credential 설정
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# S3 버킷에 빌드파일(zip 파일)을 업로드
- name: Upload to S3
run: aws s3 cp --region ap-northeast-2 ./$GITHUB_SHA.zip s3://$AWS_S3_BUCKET/$GITHUB_SHA.zip
# EC2 인스턴스에 S3에 저장되어 있던 zip 파일을 받아와 배포 시작
- name: 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=$GITHUB_SHA.zip,bundleType=zip