Skip to content

Commit

Permalink
스크립트 롤백
Browse files Browse the repository at this point in the history
  • Loading branch information
jcw1031 committed Aug 29, 2024
1 parent 094c274 commit 7a87c92
Showing 1 changed file with 73 additions and 68 deletions.
141 changes: 73 additions & 68 deletions .github/workflows/dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,82 +56,87 @@ jobs:
echo "$PRIVATE_KEY" > private_key
chmod 600 private_key
- name: 서비스 배포
- name: 가게노출 서비스 배포
if: steps.check_changes.outputs.restaurant-exposure == 'true'
env:
DEV_EC2_USER: ${{ secrets.DEV_EC2_USER }}
HOST: ${{ secrets.DEV_EC2_HOST1 }}
USER: ${{ secrets.DEV_EC2_USER }}
run: |
deploy_service() {
local service_name="$1"
local host="$2"
local jar_path="$3"
local user="$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
scp -o StrictHostKeyChecking=no -i private_key service/restaurant-exposure-service/build/libs/*.jar ${USER}@${HOST}:~/restaurant-exposure-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar restaurant-exposure-service.jar' || true
rm -rf estaurant-exposure-service.log
source ~/.bash_profile
nohup java -jar restaurant-exposure-service.jar --spring.profiles.active=dev > restaurant-exposure-service.log 2>&1 &
EOF
echo "Removing old log file..."
rm -f ${service_name}.log
- name: 검색 서비스 배포
if: steps.check_changes.outputs.search == 'true'
env:
HOST: ${{ secrets.DEV_EC2_HOST2 }}
USER: ${{ secrets.DEV_EC2_USER }}
run: |
scp -o StrictHostKeyChecking=no -i private_key service/search-service/build/libs/*.jar ${USER}@${HOST}:~/search-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar search-service.jar' || true
rm -rf search-service.log
source ~/.bash_profile
nohup java -jar search-service.jar --spring.profiles.active=dev > search-service.log 2>&1 &
EOF
echo "Starting new process..."
- name: 기타 서비스 배포
if: |
steps.check_changes.outputs.cache == 'true' ||
steps.check_changes.outputs.advertisement == 'true' ||
steps.check_changes.outputs.coupon == 'true' ||
steps.check_changes.outputs.delivery-time == 'true' ||
steps.check_changes.outputs.restaurant == 'true'
env:
HOST: ${{ secrets.DEV_EC2_HOST3 }}
USER: ${{ secrets.DEV_EC2_USER }}
run: |
if [[ "${{ steps.check_changes.outputs.cache }}" == 'true' ]]; then
scp -o StrictHostKeyChecking=no -i private_key service/cache-service/build/libs/*.jar ${USER}@${HOST}:~/cache-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar cache-service.jar' || true
rm -rf cache-service.log
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
nohup java -jar cache-service.jar --spring.profiles.active=dev > cache-service.log 2>&1 &
EOF
}
if [ "${{ steps.check_changes.outputs.restaurant-exposure }}" == "true" ]; then
deploy_service "restaurant-exposure-service" "${{ secrets.DEV_EC2_HOST1 }}" "service/restaurant-exposure-service/build/libs/*.jar"
fi
if [ "${{ steps.check_changes.outputs.search }}" == "true" ]; then
deploy_service "search-service" "${{ secrets.DEV_EC2_HOST2 }}" "service/search-service/build/libs/*.jar"
fi
if [ "${{ steps.check_changes.outputs.cache }}" == "true" ]; then
deploy_service "cache-service" "${{ secrets.DEV_EC2_HOST3 }}" "service/cache-service/build/libs/*.jar"
fi
if [ "${{ steps.check_changes.outputs.advertisement }}" == "true" ]; then
deploy_service "advertisement-service" "${{ secrets.DEV_EC2_HOST3 }}" "service/advertisement-service/build/libs/*.jar"
if [[ "${{ steps.check_changes.outputs.advertisement }}" == 'true' ]]; then
scp -o StrictHostKeyChecking=no -i private_key service/advertisement-service/build/libs/*.jar ${USER}@${HOST}:~/advertisement-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar advertisement-service.jar' || true
rm -rf advertisement-service.log
source ~/.bash_profile
nohup java -jar advertisement-service.jar --spring.profiles.active=dev > advertisement-service.log 2>&1 &
EOF
fi
if [ "${{ steps.check_changes.outputs.coupon }}" == "true" ]; then
deploy_service "coupon-service" "${{ secrets.DEV_EC2_HOST3 }}" "service/coupon-service/build/libs/*.jar"
if [[ "${{ steps.check_changes.outputs.coupon }}" == 'true' ]]; then
scp -o StrictHostKeyChecking=no -i private_key service/coupon-service/build/libs/*.jar ${USER}@${HOST}:~/coupon-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar coupon-service.jar' || true
rm -rf coupon-service.log
source ~/.bash_profile
nohup java -jar coupon-service.jar --spring.profiles.active=dev > coupon-service.log 2>&1 &
EOF
fi
if [ "${{ steps.check_changes.outputs.delivery-time }}" == "true" ]; then
deploy_service "delivery-time-service" "${{ secrets.DEV_EC2_HOST3 }}" "service/delivery-time-service/build/libs/*.jar"
if [[ "${{ steps.check_changes.outputs.delivery-time }}" == 'true' ]]; then
scp -o StrictHostKeyChecking=no -i private_key service/delivery-time-service/build/libs/*.jar ${USER}@${HOST}:~/delivery-time-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar delivery-time-service.jar' || true
rm -rf delivery-time-service.log
source ~/.bash_profile
nohup java -jar delivery-time-service.jar --spring.profiles.active=dev > delivery-time-service.log 2>&1 &
EOF
fi
if [ "${{ steps.check_changes.outputs.restaurant }}" == "true" ]; then
deploy_service "restaurant-service" "${{ secrets.DEV_EC2_HOST3 }}" "service/restaurant-service/build/libs/*.jar"
if [[ "${{ steps.check_changes.outputs.restaurant }}" == 'true' ]]; then
scp -o StrictHostKeyChecking=no -i private_key service/restaurant-service/build/libs/*.jar ${USER}@${HOST}:~/restaurant-service.jar
ssh -o StrictHostKeyChecking=no -i private_key ${USER}@${HOST} << EOF
pkill -f 'java -jar restaurant-service.jar' || true
rm -rf restaurant-service.log
source ~/.bash_profile
nohup java -jar restaurant-service.jar --spring.profiles.active=dev > restaurant-service.log 2>&1 &
EOF
fi

0 comments on commit 7a87c92

Please sign in to comment.