diff --git a/.gitea/workflows/production.yaml b/.gitea/workflows/production.yaml index 0563e1c..22262be 100644 --- a/.gitea/workflows/production.yaml +++ b/.gitea/workflows/production.yaml @@ -139,6 +139,22 @@ jobs: chmod +x scripts/ci/health-check.sh ./scripts/ci/health-check.sh $TARGET_STACK $HEALTH_CHECK_TIMEOUT + - name: Start Traefik + run: | + cd "$DEPLOY_PATH" + docker compose -f $COMPOSE_FILE -f $COMPOSE_BLUE_GREEN up -d mvp-traefik + + - name: Wait for Traefik + run: | + echo "Waiting for Traefik to be healthy..." + timeout 30 bash -c "until docker inspect --format='{{.State.Health.Status}}' mvp-traefik 2>/dev/null | grep -q healthy; do sleep 2; done" || { + echo "Traefik health check timed out, checking status..." + docker inspect --format='{{.State.Status}}' mvp-traefik + docker logs mvp-traefik --tail 20 + exit 1 + } + echo "Traefik is healthy" + - name: Switch traffic run: | cd "$DEPLOY_PATH" @@ -172,19 +188,43 @@ jobs: - name: External health check run: | + REQUIRED_FEATURES='["admin","auth","onboarding","vehicles","documents","fuel-logs","stations","maintenance","platform","notifications","user-profile","user-preferences","user-export"]' + for i in 1 2 3 4 5 6; do - if curl -sf https://motovaultpro.com/api/health > /dev/null 2>&1; then - echo "OK: Production external health check passed" - exit 0 + RESPONSE=$(curl -sf https://motovaultpro.com/api/health 2>/dev/null) || { + echo "Attempt $i/6: Connection failed, waiting 10s..." + sleep 10 + continue + } + + # Check status is "healthy" + STATUS=$(echo "$RESPONSE" | jq -r '.status') + if [ "$STATUS" != "healthy" ]; then + echo "Attempt $i/6: Status is '$STATUS', not 'healthy'. Waiting 10s..." + sleep 10 + continue fi - if [ $i -eq 6 ]; then - echo "ERROR: Production external health check failed after 6 attempts" - exit 1 + + # Check all required features are present + MISSING=$(echo "$RESPONSE" | jq -r --argjson required "$REQUIRED_FEATURES" ' + $required - .features | if length > 0 then . else empty end | @json + ') + + if [ -n "$MISSING" ]; then + echo "Attempt $i/6: Missing features: $MISSING. Waiting 10s..." + sleep 10 + continue fi - echo "Attempt $i/6: Waiting 10s..." - sleep 10 + + FEATURE_COUNT=$(echo "$RESPONSE" | jq '.features | length') + echo "OK: Production health check passed - status: healthy, features: $FEATURE_COUNT" + exit 0 done + echo "ERROR: Production health check failed after 6 attempts" + echo "Last response: $RESPONSE" + exit 1 + - name: Verify container status run: | for service in mvp-frontend-$TARGET_STACK mvp-backend-$TARGET_STACK; do diff --git a/.gitea/workflows/staging.yaml b/.gitea/workflows/staging.yaml index 8815866..9efc0d8 100644 --- a/.gitea/workflows/staging.yaml +++ b/.gitea/workflows/staging.yaml @@ -205,19 +205,43 @@ jobs: - name: Check external endpoint run: | + REQUIRED_FEATURES='["admin","auth","onboarding","vehicles","documents","fuel-logs","stations","maintenance","platform","notifications","user-profile","user-preferences","user-export"]' + for i in 1 2 3 4 5 6; do - if curl -sf https://staging.motovaultpro.com/api/health > /dev/null 2>&1; then - echo "OK: Staging external health check passed" - exit 0 + RESPONSE=$(curl -sf https://staging.motovaultpro.com/api/health 2>/dev/null) || { + echo "Attempt $i/6: Connection failed, waiting 10s..." + sleep 10 + continue + } + + # Check status is "healthy" + STATUS=$(echo "$RESPONSE" | jq -r '.status') + if [ "$STATUS" != "healthy" ]; then + echo "Attempt $i/6: Status is '$STATUS', not 'healthy'. Waiting 10s..." + sleep 10 + continue fi - if [ $i -eq 6 ]; then - echo "ERROR: Staging external health check failed after 6 attempts" - exit 1 + + # Check all required features are present + MISSING=$(echo "$RESPONSE" | jq -r --argjson required "$REQUIRED_FEATURES" ' + $required - .features | if length > 0 then . else empty end | @json + ') + + if [ -n "$MISSING" ]; then + echo "Attempt $i/6: Missing features: $MISSING. Waiting 10s..." + sleep 10 + continue fi - echo "Attempt $i/6: Waiting 10s..." - sleep 10 + + FEATURE_COUNT=$(echo "$RESPONSE" | jq '.features | length') + echo "OK: Staging health check passed - status: healthy, features: $FEATURE_COUNT" + exit 0 done + echo "ERROR: Staging health check failed after 6 attempts" + echo "Last response: $RESPONSE" + exit 1 + # ============================================ # NOTIFY - Staging ready for production # ============================================