Skip to content

fix: DB 환경 변수 전달 과정 수정 #10

fix: DB 환경 변수 전달 과정 수정

fix: DB 환경 변수 전달 과정 수정 #10

Workflow file for this run

name: Build and Deploy to EC2
# 워크플로우가 언제 실행될 것인지 조건 명시
on:
pull_request:
types: [closed]
# AWS 관련 값 변수로 설정
env:
AWS_REGION: ap-northeast-2
AWS_S3_BUCKET: devcard-deploy-bucket
AWS_CODE_DEPLOY_APPLICATION: Devcard-Application-CD
AWS_CODE_DEPLOY_GROUP: Devcard-Deployment-Group
jobs:
deploy:
runs-on: ubuntu-latest
if: github.repository == 'kakao-tech-campus-2nd-step3/Team28_BE' && github.event.pull_request.merged == true
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
# JDK 21 설치
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
# `application-secret.properties` 생성 단계 제거
# 환경 변수 확인 단계 수정
- name: Check environment variables
run: |
echo "AWS_REGION: ${{ env.AWS_REGION }}"
echo "AWS_S3_BUCKET: ${{ env.AWS_S3_BUCKET }}"
echo "AWS_CODE_DEPLOY_APPLICATION: ${{ env.AWS_CODE_DEPLOY_APPLICATION }}"
echo "AWS_CODE_DEPLOY_GROUP: ${{ env.AWS_CODE_DEPLOY_GROUP }}"
echo "DB_USERNAME: ${{ secrets.DB_USERNAME }}"
echo "DB_PASSWORD: ${{ secrets.DB_PASSWORD }}"
echo "KAKAO_JAVASCRIPT_KEY: ${{ secrets.KAKAO_JAVASCRIPT_KEY }}"
echo "GH_CLIENT_ID: ${{ secrets.GH_CLIENT_ID }}"
echo "GH_CLIENT_SECRET: ${{ secrets.GH_CLIENT_SECRET }}"
echo "GH_REDIRECT_URI: ${{ secrets.GH_REDIRECT_URI }}"
# 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
# Build and Test 단계에서 환경 변수 사용
- name: Build and Test
env:
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
KAKAO_JAVASCRIPT_KEY: ${{ secrets.KAKAO_JAVASCRIPT_KEY }}
GH_CLIENT_ID: ${{ secrets.GH_CLIENT_ID }}
GH_CLIENT_SECRET: ${{ secrets.GH_CLIENT_SECRET }}
GH_REDIRECT_URI: ${{ secrets.GH_REDIRECT_URI }}
run: ./gradlew build test --info
# 빌드 파일을 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.CICD_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.CICD_SECRET_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