From ab110fd009a4fd8add9444b18485d9892f44ff8d Mon Sep 17 00:00:00 2001 From: denshooter Date: Fri, 9 Jan 2026 19:18:43 +0100 Subject: [PATCH] fix: Improve health check to use container-internal testing - Prioritize Docker health status (most reliable) - Test HTTP endpoint from inside container using docker exec - Fallback to host-based HTTP test if available - Better debugging output showing both internal and external tests - Final verification uses Docker health status as authoritative --- .gitea/workflows/production-deploy.yml | 38 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/.gitea/workflows/production-deploy.yml b/.gitea/workflows/production-deploy.yml index 25fa53f..9c12d9c 100644 --- a/.gitea/workflows/production-deploy.yml +++ b/.gitea/workflows/production-deploy.yml @@ -68,16 +68,22 @@ jobs: for i in {1..90}; do NEW_CONTAINER=$(docker ps -q -f name=$CONTAINER_NAME) if [ ! -z "$NEW_CONTAINER" ]; then - # First check HTTP health endpoint (more reliable) - if curl -f -s --max-time 5 http://localhost:$HEALTH_PORT/api/health > /dev/null 2>&1; then - echo "✅ New container is responding to HTTP health check!" - HEALTH_CHECK_PASSED=true - break - fi - # Also check Docker health status as fallback + # Check Docker health status first (most reliable) HEALTH=$(docker inspect $NEW_CONTAINER --format='{{.State.Health.Status}}' 2>/dev/null || echo "starting") if [ "$HEALTH" == "healthy" ]; then echo "✅ New container is healthy (Docker health check)!" + # Also verify HTTP endpoint from inside container + if docker exec $NEW_CONTAINER curl -f -s --max-time 5 http://localhost:3000/api/health > /dev/null 2>&1; then + echo "✅ Container HTTP endpoint is also responding!" + HEALTH_CHECK_PASSED=true + break + else + echo "⚠️ Docker health check passed, but HTTP endpoint test failed. Continuing..." + fi + fi + # Try HTTP health endpoint from host (may not work if port not mapped yet) + if curl -f -s --max-time 2 http://localhost:$HEALTH_PORT/api/health > /dev/null 2>&1; then + echo "✅ New container is responding to HTTP health check from host!" HEALTH_CHECK_PASSED=true break fi @@ -85,6 +91,8 @@ jobs: if [ $((i % 10)) -eq 0 ]; then echo "📊 Container status: $(docker inspect $NEW_CONTAINER --format='{{.State.Status}}' 2>/dev/null || echo 'unknown')" echo "📊 Health status: $HEALTH" + echo "📊 Testing from inside container:" + docker exec $NEW_CONTAINER curl -f -s --max-time 2 http://localhost:3000/api/health 2>&1 | head -1 || echo "Container HTTP test failed" docker compose -f $COMPOSE_FILE logs --tail=5 portfolio 2>/dev/null || true fi fi @@ -92,6 +100,16 @@ jobs: sleep 2 done + # Final verification: Check Docker health status (most reliable) + NEW_CONTAINER=$(docker ps -q -f name=$CONTAINER_NAME) + if [ ! -z "$NEW_CONTAINER" ]; then + FINAL_HEALTH=$(docker inspect $NEW_CONTAINER --format='{{.State.Health.Status}}' 2>/dev/null || echo "unknown") + if [ "$FINAL_HEALTH" == "healthy" ]; then + echo "✅ Final verification: Container is healthy!" + HEALTH_CHECK_PASSED=true + fi + fi + # Verify new container is working if [ "$HEALTH_CHECK_PASSED" != "true" ]; then echo "❌ New container failed health check!" @@ -99,8 +117,10 @@ jobs: docker compose -f $COMPOSE_FILE logs --tail=100 portfolio echo "📋 Container inspect:" docker inspect $NEW_CONTAINER 2>/dev/null || echo "Container not found" - echo "📋 Testing health endpoint directly:" - curl -v http://localhost:$HEALTH_PORT/api/health || echo "Health endpoint not reachable" + echo "📋 Testing health endpoint from inside container:" + docker exec $NEW_CONTAINER curl -v http://localhost:3000/api/health 2>&1 || echo "Container HTTP test failed" + echo "📋 Testing health endpoint from host:" + curl -v http://localhost:$HEALTH_PORT/api/health 2>&1 || echo "Host HTTP test failed" exit 1 fi