From 088bbaa0978974f3aeaef7bbe78901ba4b06c75c Mon Sep 17 00:00:00 2001 From: gahusb Date: Sat, 16 May 2026 02:11:38 +0900 Subject: [PATCH] =?UTF-8?q?fix(deploy):=20use=20docker=20inspect=20for=20h?= =?UTF-8?q?ealthcheck=20(=ED=98=B8=EC=8A=A4=ED=8A=B8/=EC=BB=A8=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EB=84=88=20=EB=91=98=20=EB=8B=A4=20=EB=8F=99=EC=9E=91?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 curl http://lotto:8000/health은 deployer 컨테이너 내부에서만 Docker DNS가 'lotto'를 해석. 호스트 셸에서 sudo bash로 직접 실행 시 DNS 해석 실패해 모든 서비스가 HEALTH_FAIL로 오판정. docker inspect로 이미 정의된 compose healthcheck 결과를 직접 조회하도록 변경. starting 상태는 최대 60초 대기 후 최종 판정. --- scripts/deploy.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index ecbd9ce..c00679a 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -96,13 +96,25 @@ docker compose up -d --build $BUILD_TARGETS docker exec frontend nginx -s reload 2>/dev/null || true # ── 배포 후 헬스체크 ── -echo "Waiting for services to start..." -sleep 5 +# Docker compose의 healthcheck 블록이 이미 모든 컨테이너에 정의되어 있으므로 +# `docker inspect`로 컨테이너 health state를 직접 조회. 이 방식은 +# (a) deployer 컨테이너 내부에서도 호스트에서도 동일하게 동작 +# (b) 호스트네임 DNS 해석에 의존하지 않음 (호스트 셸에서는 'lotto' 등 미해석) +echo "Waiting for services to become healthy..." HEALTH_OK=true 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 - echo "HEALTH_FAIL: http://$svc:8000/health" + health="starting" + # 최대 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 fi done