Skip to content

Commit

Permalink
feature: 무중단 배포 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
hgo641 committed Feb 16, 2024
1 parent 2315865 commit b8257d2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
54 changes: 52 additions & 2 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,55 @@ jobs:
script: |
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
cd api/bin/
sudo docker compose down --rmi all
sudo docker compose up -d
# 현재 실행중인 컨테이너 확인
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 "🚀 서버 배포가 완료되었습니다."
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-webflux")

// actuator
implementation("org.springframework.boot:spring-boot-starter-actuator:3.2.0")

// jwt
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
implementation("io.jsonwebtoken:jjwt-impl:0.11.5")
Expand Down

0 comments on commit b8257d2

Please sign in to comment.