Skip to content

Commit

Permalink
Update gradle.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
yooooonshine authored Feb 3, 2025
1 parent 38c4e82 commit 7429541
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- uses: actions/checkout@v4

# ✅ 공통 application-common.properties 생성
- run: |
touch ./backend/src/main/resources/application-common.properties
Expand Down Expand Up @@ -66,6 +65,7 @@ jobs:

- name: Deploy to EC2
run: |
# ✅ 환경에 맞는 EC2 키 및 호스트 설정
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
echo "${{ secrets.MAIN_EC2_PEM }}" > sync_spot.pem
scp_host="${{ secrets.MAIN_EC2_HOST }}"
Expand All @@ -76,11 +76,25 @@ jobs:
profile="common,dev"
fi
# ✅ SSH 키 권한 설정
chmod 600 sync_spot.pem
scp -i sync_spot.pem -o StrictHostKeyChecking=no ./backend/build/libs/backend-0.0.1-SNAPSHOT.jar ${{ secrets.EC2_USERNAME }}@$scp_host:/home/${{ secrets.EC2_USERNAME }}/backend-0.0.1-SNAPSHOT.jar
# ✅ 기존 실행 중인 프로세스를 안전하게 종료
ssh -i sync_spot.pem -o StrictHostKeyChecking=no ${{ secrets.EC2_USERNAME }}@$scp_host "
pgrep java | xargs kill -9;
nohup java -jar /home/${{ secrets.EC2_USERNAME }}/backend-0.0.1-SNAPSHOT.jar --spring.profiles.active=$profile > /dev/null 2>&1 & disown"
echo 'Stopping existing application...';
pkill -9 -f 'java' || true;
sleep 2
"
# ✅ 빌드된 JAR 파일 배포 (속도 제한 추가)
scp -i sync_spot.pem -o StrictHostKeyChecking=no -l 4096 ./backend/build/libs/backend-0.0.1-SNAPSHOT.jar \
${{ secrets.EC2_USERNAME }}@$scp_host:/home/${{ secrets.EC2_USERNAME }}/backend-0.0.1-SNAPSHOT.jar
# ✅ 새 애플리케이션 실행 후 SSH 세션 종료 보장
ssh -i sync_spot.pem -o StrictHostKeyChecking=no ${{ secrets.EC2_USERNAME }}@$scp_host "
echo 'Starting new application...';
nohup java -jar /home/${{ secrets.EC2_USERNAME }}/backend-0.0.1-SNAPSHOT.jar --spring.profiles.active=$profile > /dev/null 2>&1 & exit
"
# ✅ SSH 키 파일 삭제
rm -f sync_spot.pem

0 comments on commit 7429541

Please sign in to comment.