Update build.gradle: jar 추가 #6
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 for Spring Boot with Gradle | |
on: | |
push: | |
branches: | |
- main # 또는 배포하려는 브랜치 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Grant execute permission for gradlew | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew build | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: spring-boot-app | |
path: build/libs/*.jar # Gradle의 빌드 아웃풋 경로 | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Download Artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: spring-boot-app | |
- name: Deploy to EC2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ec2-user | |
key: ${{ secrets.EC2_KEY }} # SSH 접근을 위한 개인 키 | |
script: | | |
sudo pkill -f 'java -jar' || true # 기존 Java 프로세스 종료 | |
sudo rm -rf /home/ec2-user/app/* # 이전 빌드 파일 삭제 | |
sudo mv *.jar /home/ec2-user/app/app.jar # 새 파일 이동 | |
sudo nohup java -jar /home/ec2-user/app/app.jar > /home/ec2-user/app/app.log 2>&1 & # 새 애플리케이션 실행 |