-
Notifications
You must be signed in to change notification settings - Fork 113
72 lines (59 loc) · 2.27 KB
/
deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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 &