Skip to content

Commit e69e1f2

Browse files
committed
feat : add github action script
1 parent d0d5432 commit e69e1f2

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: develop CI/CD
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: get Github Repository
14+
uses: actions/checkout@v4
15+
16+
- name: install JDK 17
17+
uses: actions/setup-java@v4
18+
with:
19+
distribution: temurin
20+
java-version: 17
21+
22+
- name: Create resources directory if it does not exist
23+
run: mkdir -p ./src/main/resources
24+
25+
- name: create application.yml
26+
run: echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.yml
27+
28+
- name: test and build
29+
run: ./gradlew clean build
30+
31+
- name: change build file name
32+
run: mv ./build/libs/*SNAPSHOT.jar ./project.jar
33+
34+
- name: send build file to EC2 with SCP
35+
uses: appleboy/scp-action@v0.1.7
36+
with:
37+
host: ${{ secrets.EC2_HOST }}
38+
username: ${{ secrets.EC2_USERNAME }}
39+
key: ${{ secrets.EC2_PRIVATE_KEY }}
40+
source: project.jar
41+
target: /home/reconnect_server/tobe
42+
43+
- name: connect to EC2 with SSH
44+
uses: appleboy/ssh-action@v1.0.3
45+
with:
46+
host: ${{ secrets.EC2_HOST }}
47+
username: ${{ secrets.EC2_USERNAME }}
48+
key: ${{ secrets.EC2_PRIVATE_KEY }}
49+
envs: APPLICATION_PROPERTIES
50+
script_stop: true
51+
script: |
52+
# 1. 'current' 디렉토리 제거
53+
sudo rm -rf /home/reconnect_server/current || true
54+
55+
# 2. 필요한 디렉토리 생성
56+
sudo mkdir -p /home/reconnect_server/{tobe,current,logs}
57+
58+
# 3. JAR 파일 이동
59+
sudo mv /home/reconnect_server/tobe/project.jar /home/reconnect_server/current/project.jar
60+
61+
# 4. 포트 8080 실행 중인 프로세스 종료
62+
pid=$(lsof -t -i :8080)
63+
if [ -n "$pid" ]; then
64+
echo "Killing process $pid..."
65+
sudo kill $pid
66+
else
67+
echo "No process found on port 9475."
68+
fi
69+
70+
# 5. 서버 시작
71+
cd /home/reconnect_server/current
72+
nohup java -jar project.jar --spring.profiles.active=local > /home/reconnect_server/logs/server.log 2>&1 &
73+
if [ $? -ne 0 ]; then
74+
echo "Failed to start server process"
75+
exit 1
76+
fi
77+
78+
# 6. 'tobe' 디렉토리 제거
79+
sudo rm -rf /home/reconnect_server/tobe || true

0 commit comments

Comments
 (0)