Skip to content

Commit 0aaf564

Browse files
authored
Merge pull request #8 from DevKor-github/dev
Chore/#4 main pr
2 parents 6c9934c + 2790b96 commit 0aaf564

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Deploy to EC2
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- chore/#4
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
# 1) 코드 가져오기
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
# 2) JDK 설정
18+
- name: Set up JDK 21
19+
uses: actions/setup-java@v4
20+
with:
21+
distribution: 'temurin'
22+
java-version: '21'
23+
cache: gradle
24+
25+
# 3) Gradle 빌드
26+
- name: Build with Gradle
27+
run: chmod +x ./gradlew && ./gradlew bootjar
28+
29+
# 4) JAR를 EC2로 복사
30+
- name: Copy jar to EC2
31+
uses: appleboy/scp-action@v0.1.7
32+
with:
33+
host: ${{ secrets.EC2_HOST }}
34+
username: ${{ secrets.EC2_USER }}
35+
key: ${{ secrets.EC2_SSH_KEY }}
36+
source: "build/libs/*-SNAPSHOT.jar"
37+
target: "/home/ubuntu/app"
38+
overwrite: true
39+
40+
# 5) EC2에서 앱 재시작
41+
- name: Restart Spring Boot app on EC2
42+
uses: appleboy/ssh-action@v1.0.3
43+
with:
44+
host: ${{ secrets.EC2_HOST }}
45+
username: ${{ secrets.EC2_USER }}
46+
key: ${{ secrets.EC2_SSH_KEY }}
47+
script: |
48+
cd /home/ubuntu/app
49+
50+
echo "[deploy] stop old app"
51+
if [ -f app.pid ]; then
52+
PID=$(cat app.pid)
53+
if ps -p "$PID" > /dev/null 2>&1; then
54+
kill "$PID" || true
55+
sleep 5
56+
fi
57+
rm app.pid
58+
fi
59+
60+
echo "[deploy] start new app"
61+
DB_PASSWORD=${{ secrets.DB_PASSWORD }} \
62+
nohup java -jar build/libs/workingdead-0.0.1-SNAPSHOT.jar > app.log 2>&1 &
63+
64+
echo $! > app.pid
65+
66+
sleep 5
67+
if ps -p "$(cat app.pid)" > /dev/null 2>&1; then
68+
echo "[deploy] Application started successfully"
69+
else
70+
echo "[deploy] Application failed to start"
71+
tail -n 80 app.log || true
72+
exit 1
73+
fi

0 commit comments

Comments
 (0)