fix: Improve production health check to use Docker health status
All checks were successful
Production Deployment (Zero Downtime) / deploy-production (push) Successful in 10m54s
All checks were successful
Production Deployment (Zero Downtime) / deploy-production (push) Successful in 10m54s
- Use Docker health check status instead of host-based curl - Test from inside container instead of from host - Better error messages and debugging - More reliable health check that doesn't depend on port mapping
This commit is contained in:
@@ -209,17 +209,62 @@ jobs:
|
||||
- name: Production Health Check
|
||||
run: |
|
||||
echo "🔍 Running production health checks..."
|
||||
for i in {1..20}; do
|
||||
if curl -f http://localhost:3000/api/health && curl -f http://localhost:3000/ > /dev/null; then
|
||||
echo "✅ Production is fully operational!"
|
||||
exit 0
|
||||
COMPOSE_FILE="docker-compose.production.yml"
|
||||
CONTAINER_NAME="portfolio-app"
|
||||
|
||||
# Get the production container ID
|
||||
CONTAINER_ID=$(docker compose -f $COMPOSE_FILE ps -q portfolio 2>/dev/null | head -1)
|
||||
if [ -z "$CONTAINER_ID" ]; then
|
||||
CONTAINER_ID=$(docker ps -q -f "name=^/${CONTAINER_NAME}$")
|
||||
fi
|
||||
echo "⏳ Waiting for production... ($i/20)"
|
||||
sleep 3
|
||||
done
|
||||
echo "❌ Production health check failed!"
|
||||
docker compose -f docker-compose.production.yml logs --tail=50
|
||||
|
||||
if [ -z "$CONTAINER_ID" ]; then
|
||||
echo "❌ Production container not found!"
|
||||
docker ps --filter "name=portfolio" --format "table {{.ID}}\t{{.Names}}\t{{.Status}}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "📦 Found container: $CONTAINER_ID"
|
||||
|
||||
# Wait for container to be healthy (using Docker's health check)
|
||||
HEALTH_CHECK_PASSED=false
|
||||
for i in {1..30}; do
|
||||
HEALTH=$(docker inspect $CONTAINER_ID --format='{{.State.Health.Status}}' 2>/dev/null || echo "starting")
|
||||
STATUS=$(docker inspect $CONTAINER_ID --format='{{.State.Status}}' 2>/dev/null || echo "unknown")
|
||||
|
||||
if [ "$HEALTH" == "healthy" ] && [ "$STATUS" == "running" ]; then
|
||||
echo "✅ Container is healthy and running!"
|
||||
|
||||
# Test from inside the container (most reliable)
|
||||
if docker exec $CONTAINER_ID curl -f -s --max-time 5 http://localhost:3000/api/health > /dev/null 2>&1; then
|
||||
echo "✅ Health endpoint responds from inside container!"
|
||||
HEALTH_CHECK_PASSED=true
|
||||
break
|
||||
else
|
||||
echo "⚠️ Container is healthy but HTTP endpoint test failed. Retrying..."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $((i % 5)) -eq 0 ]; then
|
||||
echo "📊 Status: $STATUS, Health: $HEALTH (attempt $i/30)"
|
||||
fi
|
||||
|
||||
echo "⏳ Waiting for production... ($i/30)"
|
||||
sleep 2
|
||||
done
|
||||
|
||||
if [ "$HEALTH_CHECK_PASSED" != "true" ]; then
|
||||
echo "❌ Production health check failed!"
|
||||
echo "📋 Container status:"
|
||||
docker inspect $CONTAINER_ID --format='Name: {{.Name}}, Status: {{.State.Status}}, Health: {{.State.Health.Status}}' 2>/dev/null || echo "Could not inspect container"
|
||||
echo "📋 Container logs:"
|
||||
docker compose -f $COMPOSE_FILE logs --tail=50 portfolio 2>/dev/null || docker logs $CONTAINER_ID --tail=50 2>/dev/null || echo "Could not get logs"
|
||||
echo "📋 Testing from inside container:"
|
||||
docker exec $CONTAINER_ID curl -v http://localhost:3000/api/health 2>&1 || echo "Container HTTP test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Production is fully operational!"
|
||||
|
||||
- name: Cleanup
|
||||
run: |
|
||||
|
||||
Reference in New Issue
Block a user