Skip to content

Commit 0c8c833

Browse files
author
Deepak Pandey
committed
fix: Implement robust health check best practices
πŸ”‘ Key improvements: 1. βœ… Never use relative paths - validate all URLs are full URLs (https://) 2. βœ… Test production domain reachability before health checks 3. βœ… Increase sleep time from 45s to 60s for Vercel warm-up 4. βœ… Add URL format validation with regex 5. βœ… Auto-prepend https:// if missing from domain URLs 6. βœ… Test domain reachability with 10s timeout before health checks 7. βœ… Better error messages and debugging information This ensures reliable health checks that work with Vercel's deployment timing and URL formats.
1 parent 9c89cc7 commit 0c8c833

File tree

1 file changed

+54
-14
lines changed

1 file changed

+54
-14
lines changed

β€Ž.github/workflows/ci-cd.ymlβ€Ž

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,16 @@ jobs:
325325
- name: Run smoke tests
326326
run: |
327327
echo "⏳ Waiting for deployment to be ready..."
328-
sleep 45
328+
sleep 60
329329
echo "πŸ” Testing health endpoint..."
330330
DEPLOYMENT_URL="${{ steps.deploy-staging.outputs.deployment-url }}"
331331
332+
# Validate deployment URL is a full URL
333+
if [[ ! "$DEPLOYMENT_URL" =~ ^https?:// ]]; then
334+
echo "❌ Invalid deployment URL format: $DEPLOYMENT_URL"
335+
exit 1
336+
fi
337+
332338
# Try main health check with quick parameter (bypasses complex checks)
333339
echo "Testing main health check (quick mode): $DEPLOYMENT_URL/api/health?quick=true"
334340
if curl -f -s --max-time 30 "$DEPLOYMENT_URL/api/health?quick=true"; then
@@ -343,10 +349,25 @@ jobs:
343349
echo "Deployment URL: $DEPLOYMENT_URL"
344350
echo "Trying staging domain instead..."
345351
if [ -n "${{ secrets.STAGING_URL }}" ]; then
346-
if curl -f -s --max-time 30 "${{ secrets.STAGING_URL }}/api/health?quick=true"; then
347-
echo "βœ… Staging domain health check passed"
352+
STAGING_URL="${{ secrets.STAGING_URL }}"
353+
# Ensure staging URL is a full URL
354+
if [[ ! "$STAGING_URL" =~ ^https?:// ]]; then
355+
echo "⚠️ Staging URL is not a full URL: $STAGING_URL"
356+
STAGING_URL="https://$STAGING_URL"
357+
fi
358+
359+
echo "Testing staging domain reachability: $STAGING_URL"
360+
if curl -f -s --max-time 10 "$STAGING_URL" > /dev/null; then
361+
echo "βœ… Staging domain is reachable"
362+
echo "Trying staging domain health check: $STAGING_URL/api/health?quick=true"
363+
if curl -f -s --max-time 30 "$STAGING_URL/api/health?quick=true"; then
364+
echo "βœ… Staging domain health check passed"
365+
else
366+
echo "❌ Both deployment URL and staging domain failed"
367+
echo "⚠️ Health check failed but deployment was successful"
368+
fi
348369
else
349-
echo "❌ Both deployment URL and staging domain failed"
370+
echo "❌ Staging domain is not publicly reachable: $STAGING_URL"
350371
echo "⚠️ Health check failed but deployment was successful"
351372
fi
352373
else
@@ -429,10 +450,16 @@ jobs:
429450
- name: Run production health check
430451
run: |
431452
echo "⏳ Waiting for production deployment to be ready..."
432-
sleep 45
453+
sleep 60
433454
echo "πŸ” Testing production health endpoint..."
434455
DEPLOYMENT_URL="${{ steps.deploy-production.outputs.deployment-url }}"
435456
457+
# Validate deployment URL is a full URL
458+
if [[ ! "$DEPLOYMENT_URL" =~ ^https?:// ]]; then
459+
echo "❌ Invalid deployment URL format: $DEPLOYMENT_URL"
460+
exit 1
461+
fi
462+
436463
# Try main health check with quick parameter (bypasses complex checks)
437464
echo "Testing main health check (quick mode): $DEPLOYMENT_URL/api/health?quick=true"
438465
if curl -f -s --max-time 30 "$DEPLOYMENT_URL/api/health?quick=true"; then
@@ -446,17 +473,30 @@ jobs:
446473
echo "❌ Full health check also failed"
447474
echo "Deployment URL: $DEPLOYMENT_URL"
448475
449-
# Try production domain if available
476+
# Try production domain if available and publicly reachable
450477
if [ -n "${{ secrets.PRODUCTION_URL }}" ]; then
451-
echo "Trying production domain: ${{ secrets.PRODUCTION_URL }}/api/health?quick=true"
452-
if curl -f -s --max-time 30 "${{ secrets.PRODUCTION_URL }}/api/health?quick=true"; then
453-
echo "βœ… Production domain health check passed"
478+
PROD_URL="${{ secrets.PRODUCTION_URL }}"
479+
# Ensure production URL is a full URL
480+
if [[ ! "$PROD_URL" =~ ^https?:// ]]; then
481+
echo "⚠️ Production URL is not a full URL: $PROD_URL"
482+
PROD_URL="https://$PROD_URL"
483+
fi
484+
485+
echo "Testing production domain reachability: $PROD_URL"
486+
if curl -f -s --max-time 10 "$PROD_URL" > /dev/null; then
487+
echo "βœ… Production domain is reachable"
488+
echo "Trying production domain health check: $PROD_URL/api/health?quick=true"
489+
if curl -f -s --max-time 30 "$PROD_URL/api/health?quick=true"; then
490+
echo "βœ… Production domain health check passed"
491+
else
492+
echo "❌ Production domain health check failed"
493+
echo "Both URLs failed - deployment may still be in progress"
494+
echo "Deployment URL: $DEPLOYMENT_URL"
495+
echo "Production URL: $PROD_URL"
496+
echo "⚠️ Health check failed but deployment was successful"
497+
fi
454498
else
455-
echo "❌ Production domain health check also failed"
456-
echo "Both URLs failed - deployment may still be in progress"
457-
echo "Deployment URL: $DEPLOYMENT_URL"
458-
echo "Production URL: ${{ secrets.PRODUCTION_URL }}"
459-
# Don't fail the build - deployment was successful
499+
echo "❌ Production domain is not publicly reachable: $PROD_URL"
460500
echo "⚠️ Health check failed but deployment was successful"
461501
fi
462502
else

0 commit comments

Comments
Β (0)