경북대 BE_김동현 6주차 과제 (2-3단계) #2
Workflow file for this run
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: Deploy Spring Boot Application | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- step2-3 # 배포할 브랜치 이름 | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'zulu' | ||
java-version: '21' | ||
- name: Build Spring Boot application | ||
run: ./gradlew build -x test # Gradle build 수행 | ||
- name: Verify JAR file location | ||
run: ls -l ./build/libs/spring-gift-0.0.1-SNAPSHOT.jar | ||
- name: Upload JAR file to remote server | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.REMOTE_SSH_HOST }} | ||
username: ${{ secrets.REMOTE_SSH_USERNAME }} | ||
key: ${{ secrets.REMOTE_SSH_KEY }} | ||
port: ${{ secrets.REMOTE_SSH_PORT }} | ||
source: "./build/libs/spring-gift-0.0.1-SNAPSHOT.jar" # 빌드된 JAR 파일을 | ||
target: "/home/ubuntu/katecam" # 원격 서버의 디렉토리에 옮김 | ||
- name: Restart Spring Boot application on remote server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.REMOTE_SSH_HOST }} | ||
username: ${{ secrets.REMOTE_SSH_USERNAME }} | ||
key: ${{ secrets.REMOTE_SSH_KEY }} | ||
port: ${{ secrets.REMOTE_SSH_PORT }} | ||
script: | | ||
#!/bin/bash | ||
set -e | ||
# 디렉토리 변경 | ||
pwd | ||
cd /home/ubuntu/katecam/build/libs # 절대 | ||
# 현재 실행 중인 애플리케이션 종료 | ||
echo "Stopping existing Java process..." | ||
# pkill -f "java -jar spring-gift.jar" || echo "No existing Java process found." | ||
# 기존 JAR 파일 삭제 | ||
echo "Removing old JAR file..." | ||
if [ -f "spring-gift.jar" ]; then | ||
rm -f spring-gift.jar | ||
else | ||
echo "Old JAR file does not exist." | ||
fi | ||
# 새로운 JAR 파일 이름 변경 | ||
echo "Renaming new JAR file..." | ||
mv spring-gift-0.0.1-SNAPSHOT.jar spring-gift.jar | ||
# 새로운 JAR 파일 실행 | ||
echo "Starting new JAR file..." | ||
nohup java -jar spring-gift.jar > /dev/null 2>&1 & |