-
Notifications
You must be signed in to change notification settings - Fork 3
134 lines (114 loc) · 4.86 KB
/
dev-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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: 개발 서버 배포
on:
push:
branches:
- dev
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: JDK 21 설정
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'zulu'
- name: gradlew 실행 권한 부여
run: chmod +x gradlew
- name: JAR 빌드
run: ./gradlew clean build
- name: 빌드된 JAR 파일 확인
run: |
echo "빌드된 JAR 파일 목록:"
find service/*/build/libs -name "*.jar"
- name: 변경된 서비스 확인
id: check_changes
uses: dorny/paths-filter@v2
with:
filters: |
restaurant-exposure:
- 'service/restaurant-exposure-service/**'
search:
- 'service/search-service/**'
cache:
- 'service/cache-service/**'
advertisement:
- 'service/advertisement-service/**'
coupon:
- 'service/coupon-service/**'
delivery-time:
- 'service/delivery-time-service/**'
restaurant:
- 'service/restaurant-service/**'
- name: SSH 키 설정
env:
PRIVATE_KEY: ${{ secrets.DEV_EC2_SSH_KEY }}
run: |
echo "$PRIVATE_KEY" > private_key
chmod 600 private_key
- name: 서비스 배포 함수 정의
run: |
deploy_service() {
local service_name=$1
local host=$2
local jar_path=$3
local user=${{ secrets.DEV_EC2_USER }}
echo "Deploying $service_name to $host"
scp -o StrictHostKeyChecking=no -i private_key $jar_path ${user}@${host}:~/${service_name}.jar
ssh -o StrictHostKeyChecking=no -i private_key ${user}@${host} << EOF
# 기존 프로세스 종료
pid=\$(pgrep -f "java -jar ${service_name}.jar")
if [ ! -z "\$pid" ]; then
echo "Stopping existing process..."
kill \$pid
for i in {1..30}; do
if ! ps -p \$pid > /dev/null; then
break
fi
echo "Waiting for process to stop... (\$i seconds)"
sleep 1
done
if ps -p \$pid > /dev/null; then
echo "Force killing the process..."
kill -9 \$pid
fi
fi
echo "Removing old log file..."
rm -f ${service_name}.log
echo "Starting new process..."
source ~/.bash_profile
nohup java -jar ${service_name}.jar --spring.profiles.active=dev > ${service_name}.log 2>&1 &
echo "Waiting for service to start..."
for i in {1..60}; do
if grep -q "Started .* in .*. seconds" ${service_name}.log; then
echo "Service started successfully"
exit 0
fi
echo "Waiting for service to start... (\$i seconds)"
sleep 1
done
echo "Service did not start within the expected time"
exit 1
EOF
}
- name: 가게노출 서비스 배포
if: steps.check_changes.outputs.restaurant-exposure == 'true'
run: deploy_service "restaurant-exposure-service" "${{ secrets.DEV_EC2_HOST1 }}" "service/restaurant-exposure-service/build/libs/*.jar"
- name: 검색 서비스 배포
if: steps.check_changes.outputs.search == 'true'
run: deploy_service "search-service" "${{ secrets.DEV_EC2_HOST2 }}" "service/search-service/build/libs/*.jar"
- name: 캐시 서비스 배포
if: steps.check_changes.outputs.cache == 'true'
run: deploy_service "cache-service" "${{ secrets.DEV_EC2_HOST3 }}" "service/cache-service/build/libs/*.jar"
- name: 광고 서비스 배포
if: steps.check_changes.outputs.advertisement == 'true'
run: deploy_service "advertisement-service" "${{ secrets.DEV_EC2_HOST3 }}" "service/advertisement-service/build/libs/*.jar"
- name: 쿠폰 서비스 배포
if: steps.check_changes.outputs.coupon == 'true'
run: deploy_service "coupon-service" "${{ secrets.DEV_EC2_HOST3 }}" "service/coupon-service/build/libs/*.jar"
- name: 배달시간 서비스 배포
if: steps.check_changes.outputs.delivery-time == 'true'
run: deploy_service "delivery-time-service" "${{ secrets.DEV_EC2_HOST3 }}" "service/delivery-time-service/build/libs/*.jar"
- name: 레스토랑 서비스 배포
if: steps.check_changes.outputs.restaurant == 'true'
run: deploy_service "restaurant-service" "${{ secrets.DEV_EC2_HOST3 }}" "service/restaurant-service/build/libs/*.jar"