🔧 Improve health check logic in Gitea workflows
Some checks failed
CI/CD Pipeline (Fast) / production (push) Successful in 7m47s
CI/CD Pipeline (Reliable & Simple) / production (push) Failing after 8m46s
CI/CD Pipeline (Simple & Reliable) / production (push) Failing after 6m17s

- Enhanced health check mechanisms in `ci-cd-fast.yml` and `ci-cd-zero-downtime-fixed.yml` to utilize `docker exec` for internal checks, addressing issues with direct port access.
- Updated health check logic to provide better error messages and fallback methods, ensuring more reliable deployment verification.
- Documented changes in `DEPLOYMENT-FIXES.md` to reflect improvements in health check processes.

 These updates enhance the reliability of health checks during deployments and improve debugging capabilities.
This commit is contained in:
2025-09-15 14:15:49 +02:00
parent fc3f9ebf12
commit ed95163f55
3 changed files with 69 additions and 20 deletions

View File

@@ -160,10 +160,10 @@ EOF
echo "📊 Checking container status..."
docker compose -f docker-compose.zero-downtime-fixed.yml ps
# Wait for application containers to be healthy
# Wait for application containers to be healthy (internal check)
echo "🏥 Waiting for application containers to be healthy..."
for i in {1..30}; do
# Check if both app containers are healthy
# Check if both app containers are healthy internally
if docker exec portfolio-app-1 curl -f http://localhost:3000/api/health > /dev/null 2>&1 && \
docker exec portfolio-app-2 curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
echo "✅ Both application containers are healthy!"
@@ -173,15 +173,20 @@ EOF
sleep 3
done
# Wait for nginx to be healthy
echo "🌐 Waiting for nginx to be healthy..."
for i in {1..20}; do
# Wait for nginx to be healthy and proxy to work
echo "🌐 Waiting for nginx to be healthy and proxy to work..."
for i in {1..30}; do
# Check nginx health endpoint
if curl -f http://localhost/health > /dev/null 2>&1; then
echo "✅ Nginx is healthy!"
break
echo "✅ Nginx health endpoint is working!"
# Now check if nginx can proxy to the application
if curl -f http://localhost/api/health > /dev/null 2>&1; then
echo "✅ Nginx proxy to application is working!"
break
fi
fi
echo "⏳ Waiting for nginx... ($i/20)"
sleep 2
echo "⏳ Waiting for nginx and proxy... ($i/30)"
sleep 3
done
- name: Health check
@@ -192,7 +197,7 @@ EOF
echo "📊 Container status:"
docker compose -f docker-compose.zero-downtime-fixed.yml ps
# Check individual application containers
# Check individual application containers (internal)
echo "🏥 Checking individual application containers..."
if docker exec portfolio-app-1 curl -f http://localhost:3000/api/health; then
echo "✅ portfolio-app-1 health check passed!"
@@ -219,11 +224,13 @@ EOF
exit 1
fi
# Check application health through nginx
# Check application health through nginx (this is the main test)
if curl -f http://localhost/api/health; then
echo "✅ Application health check through nginx passed!"
else
echo "❌ Application health check through nginx failed!"
echo "Nginx logs:"
docker logs portfolio-nginx --tail=20
exit 1
fi