fix(deploy): use docker inspect for healthcheck (호스트/컨테이너 둘 다 동작)

기존 curl http://lotto:8000/health은 deployer 컨테이너 내부에서만
Docker DNS가 'lotto'를 해석. 호스트 셸에서 sudo bash로 직접 실행 시
DNS 해석 실패해 모든 서비스가 HEALTH_FAIL로 오판정. docker inspect로
이미 정의된 compose healthcheck 결과를 직접 조회하도록 변경. starting
상태는 최대 60초 대기 후 최종 판정.
This commit is contained in:
2026-05-16 02:11:38 +09:00
parent be322557ee
commit 088bbaa097

View File

@@ -96,13 +96,25 @@ docker compose up -d --build $BUILD_TARGETS
docker exec frontend nginx -s reload 2>/dev/null || true docker exec frontend nginx -s reload 2>/dev/null || true
# ── 배포 후 헬스체크 ── # ── 배포 후 헬스체크 ──
echo "Waiting for services to start..." # Docker compose의 healthcheck 블록이 이미 모든 컨테이너에 정의되어 있으므로
sleep 5 # `docker inspect`로 컨테이너 health state를 직접 조회. 이 방식은
# (a) deployer 컨테이너 내부에서도 호스트에서도 동일하게 동작
# (b) 호스트네임 DNS 해석에 의존하지 않음 (호스트 셸에서는 'lotto' 등 미해석)
echo "Waiting for services to become healthy..."
HEALTH_OK=true HEALTH_OK=true
for svc in $HEALTH_ENDPOINTS; do for svc in $HEALTH_ENDPOINTS; do
if ! curl -sf --max-time 10 --retry 2 --retry-delay 3 "http://$svc:8000/health" > /dev/null 2>&1; then health="starting"
echo "HEALTH_FAIL: http://$svc:8000/health" # 최대 60초 (5초×12) 동안 starting → healthy 전이 대기
for _ in $(seq 1 12); do
health=$(docker inspect --format='{{.State.Health.Status}}' "$svc" 2>/dev/null || echo "missing")
if [ "$health" = "healthy" ] || [ "$health" = "unhealthy" ] || [ "$health" = "missing" ]; then
break
fi
sleep 5
done
if [ "$health" != "healthy" ]; then
echo "HEALTH_FAIL: $svc (state=$health)"
HEALTH_OK=false HEALTH_OK=false
fi fi
done done