Skip to content

Commit

Permalink
refactor: 배포 스크립트를 파일로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
hgo641 committed Feb 16, 2024
1 parent e01763f commit 7f34980
Showing 1 changed file with 1 addition and 54 deletions.
55 changes: 1 addition & 54 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,57 +56,4 @@ jobs:
key: ${{ secrets.AWS_SSH_KEY }}
script: |
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
cd api/bin/
# 현재 실행중인 컨테이너 확인
sudo docker compose pull
api1_running=$(sudo docker ps --filter "name=petqua-api1" --format "{{.Names}}" | grep -w "petqua-api1" | wc -l)
if [ $api1_running -eq 1 ]; then
# petqua-api1이 실행중이면, petqua-api2 실행
sudo docker compose up -d petqua-api2
# port 설정
port=8081
blue_container="petqua-api1"
echo -e "▶️ petqua-api2에 배포를 시작합니다"
else
# petqua-api2가 실행중이거나 실행중인 컨테이너가 없다면, petqua-api1 실행
sudo docker compose up -d petqua-api1
# port 설정
port=8080
blue_container="petqua-api2"
echo -e "▶️ petqua-api1에 배포를 시작합니다"
fi
# 헬스 체크 - 최대 10번 재시도
for retry in {1..10}
do
# spring boot actuator로 지정한 url, ~/management/health-check에 요청을 보내 헬스 체크 검사
response=$(curl -s http://127.0.0.1:$port/management/health-check)
isHealth=$(echo ${response} | grep 'UP' | wc -l)
if [ $isHealth -eq 1 ]
then
break
else
echo -e "⚠️ 헬스체크에 실패했습니다. 10초 슬립 후 재시도합니다."
sleep 10
fi
if [ $isHealth - eq 0]
then
echo -e "❗️ 서버 헬스체크에 실패했습니다. 배포를 중단합니다."
exit 0
else
echo -e "✅ 서버 헬스체크에 성공했습니다. Nginx를 리로드합니다."
fi
# Nginx 설정 업데이트
echo "set \$backend_port $port;" | sudo tee /etc/nginx/conf.d/port.inc
sudo nginx -s reload
# 구버전 컨테이너 중단
docker stop $blue_container
echo -e "🚀 서버 배포가 완료되었습니다."
cd api/bin/ && ./deploy.sh

0 comments on commit 7f34980

Please sign in to comment.