fix: Improve health check to use container-internal testing
Some checks failed
Production Deployment (Zero Downtime) / deploy-production (push) Has been cancelled
Some checks failed
Production Deployment (Zero Downtime) / deploy-production (push) Has been cancelled
- 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
This commit is contained in:
@@ -68,16 +68,22 @@ jobs:
|
|||||||
for i in {1..90}; do
|
for i in {1..90}; do
|
||||||
NEW_CONTAINER=$(docker ps -q -f name=$CONTAINER_NAME)
|
NEW_CONTAINER=$(docker ps -q -f name=$CONTAINER_NAME)
|
||||||
if [ ! -z "$NEW_CONTAINER" ]; then
|
if [ ! -z "$NEW_CONTAINER" ]; then
|
||||||
# First check HTTP health endpoint (more reliable)
|
# Check Docker health status first (most 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
|
|
||||||
HEALTH=$(docker inspect $NEW_CONTAINER --format='{{.State.Health.Status}}' 2>/dev/null || echo "starting")
|
HEALTH=$(docker inspect $NEW_CONTAINER --format='{{.State.Health.Status}}' 2>/dev/null || echo "starting")
|
||||||
if [ "$HEALTH" == "healthy" ]; then
|
if [ "$HEALTH" == "healthy" ]; then
|
||||||
echo "✅ New container is healthy (Docker health check)!"
|
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
|
HEALTH_CHECK_PASSED=true
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@@ -85,6 +91,8 @@ jobs:
|
|||||||
if [ $((i % 10)) -eq 0 ]; then
|
if [ $((i % 10)) -eq 0 ]; then
|
||||||
echo "📊 Container status: $(docker inspect $NEW_CONTAINER --format='{{.State.Status}}' 2>/dev/null || echo 'unknown')"
|
echo "📊 Container status: $(docker inspect $NEW_CONTAINER --format='{{.State.Status}}' 2>/dev/null || echo 'unknown')"
|
||||||
echo "📊 Health status: $HEALTH"
|
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
|
docker compose -f $COMPOSE_FILE logs --tail=5 portfolio 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -92,6 +100,16 @@ jobs:
|
|||||||
sleep 2
|
sleep 2
|
||||||
done
|
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
|
# Verify new container is working
|
||||||
if [ "$HEALTH_CHECK_PASSED" != "true" ]; then
|
if [ "$HEALTH_CHECK_PASSED" != "true" ]; then
|
||||||
echo "❌ New container failed health check!"
|
echo "❌ New container failed health check!"
|
||||||
@@ -99,8 +117,10 @@ jobs:
|
|||||||
docker compose -f $COMPOSE_FILE logs --tail=100 portfolio
|
docker compose -f $COMPOSE_FILE logs --tail=100 portfolio
|
||||||
echo "📋 Container inspect:"
|
echo "📋 Container inspect:"
|
||||||
docker inspect $NEW_CONTAINER 2>/dev/null || echo "Container not found"
|
docker inspect $NEW_CONTAINER 2>/dev/null || echo "Container not found"
|
||||||
echo "📋 Testing health endpoint directly:"
|
echo "📋 Testing health endpoint from inside container:"
|
||||||
curl -v http://localhost:$HEALTH_PORT/api/health || echo "Health endpoint not reachable"
|
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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user