Merge pull request #9 from NALANCE/feature/#7 #3
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: CI/CD Pipeline | |
on: | |
push: | |
branches: [ develop ] # develop 브랜치에 push가 일어날 때 실행 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 # 저장소 코드 체크아웃 | |
- name: Set up JDK 17 # Java 개발 킷 설정 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
# - name: Make application.yml # application.yml 파일 생성 | |
# run: | | |
# cd ./src/main/resources | |
# echo "${{ secrets.APPLICATION_YML }}" > ./application.yml | |
# shell: bash | |
- name: Grant execute permission for gradlew # gradlew 실행 권한 부여 | |
run: chmod +x gradlew | |
- name: Build with Gradle # Gradle을 사용하여 프로젝트 빌드 | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: build | |
- name: Upload build artifact # 빌드된 아티팩트 업로드 | |
uses: actions/upload-artifact@v3 | |
with: | |
name: umc7thServer | |
path: build/libs/*.jar | |
deploy: | |
needs: build # build 작업이 성공적으로 완료된 후 실행 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download build artifact # 이전 단계에서 업로드한 아티팩트 다운로드 | |
uses: actions/download-artifact@v3 | |
with: | |
name: umc7thServer | |
path: build/libs/ | |
- name: Deploy to EC2 Configure RDS Connection # EC2에 배포 및 RDS 연동 설정 | |
env: | |
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }} | |
EC2_USERNAME: ${{ secrets.EC2_USERNAME }} | |
EC2_HOST: ${{ secrets.EC2_HOST }} | |
RDS_USERNAME: ${{ secrets.RDS_USERNAME }} | |
RDS_PASSWORD: ${{ secrets.RDS_PASSWORD }} | |
RDS_HOST: ${{ secrets.RDS_HOST }} | |
RDS_DB_NAME: ${{ secrets.RDS_DB_NAME }} | |
run: | | |
echo "$EC2_SSH_KEY" > private_key.pem | |
chmod 600 private_key.pem | |
jar_file=$(find build/libs -name '*.jar' ! -name '*plain.jar' | head -n 1) | |
scp -i private_key.pem -o StrictHostKeyChecking=no "$jar_file" $EC2_USERNAME@$EC2_HOST:/home/$EC2_USERNAME/umc7thServer.jar | |
ssh -i private_key.pem -o StrictHostKeyChecking=no $EC2_USERNAME@$EC2_HOST " | |
pgrep java | xargs -r kill -15 # 기존에 실행 중인 Java 프로세스 종료 | |
sleep 10 | |
nohup java -Dspring.profiles.active=database \ | |
-DDB_URL=jdbc:mysql://${RDS_HOST}:3306/${RDS_DB_NAME} \ | |
-DDB_USERNAME=$RDS_USERNAME \ | |
-DDB_PASSWORD=$RDS_PASSWORD \ | |
-jar /home/$EC2_USERNAME/umc7thServer.jar > app.log 2>&1 & # 새 버전 애플리케이션 실행 | |
" | |
rm -f private_key.pem # 민감한 정보 삭제 |