fix: Install curl in production image and improve health check
- Install curl in runner stage for health checks - Increase health check timeout to 90 attempts (3 minutes) - Improve health check logic to prioritize HTTP endpoint - Add better debugging output during health check wait - Show container status and logs during health check failures
This commit is contained in:
@@ -64,29 +64,43 @@ jobs:
|
||||
|
||||
# Wait for new container to be healthy
|
||||
echo "⏳ Waiting for new container to be healthy..."
|
||||
for i in {1..60}; do
|
||||
HEALTH_CHECK_PASSED=false
|
||||
for i in {1..90}; do
|
||||
NEW_CONTAINER=$(docker ps -q -f name=$CONTAINER_NAME)
|
||||
if [ ! -z "$NEW_CONTAINER" ]; then
|
||||
# Check health status
|
||||
# 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
|
||||
HEALTH=$(docker inspect $NEW_CONTAINER --format='{{.State.Health.Status}}' 2>/dev/null || echo "starting")
|
||||
if [ "$HEALTH" == "healthy" ]; then
|
||||
echo "✅ New container is healthy!"
|
||||
echo "✅ New container is healthy (Docker health check)!"
|
||||
HEALTH_CHECK_PASSED=true
|
||||
break
|
||||
fi
|
||||
# Also check HTTP health endpoint
|
||||
if curl -f http://localhost:$HEALTH_PORT/api/health > /dev/null 2>&1; then
|
||||
echo "✅ New container is responding!"
|
||||
break
|
||||
# Show container status for debugging
|
||||
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"
|
||||
docker compose -f $COMPOSE_FILE logs --tail=5 portfolio 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
echo "⏳ Waiting... ($i/60)"
|
||||
echo "⏳ Waiting... ($i/90)"
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Verify new container is working
|
||||
if ! curl -f http://localhost:$HEALTH_PORT/api/health > /dev/null 2>&1; then
|
||||
if [ "$HEALTH_CHECK_PASSED" != "true" ]; then
|
||||
echo "❌ New container failed health check!"
|
||||
docker compose -f $COMPOSE_FILE logs --tail=50 portfolio
|
||||
echo "📋 Container logs:"
|
||||
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"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user