33800 Docs

← Retour

Proposition : Split Health Check en etapes granulaires

Date : 10/02/2026 Status : REPORTEE AU BACKLOG Scope : smart-deploy (lib/health.sh + smart-deploy.sh)

Probleme actuel

L'etape 9 (Health Check) est un bloc monolithique :

9. HEALTH CHECK
   - sleep 5
   - health_check_with_rollback() → 10 retries x 3s → rollback si echec

Quand ca fail, on sait juste "health check failed" sans savoir OU ca coince exactement.

Proposition : 4 etapes distinctes

Etape 9a - Container Running

Verifie que le container Docker est effectivement up et running (pas crashed, pas restarting).

docker inspect --format '{{.State.Status}}' <container>  # == "running"
docker inspect --format '{{.State.Health.Status}}' <container>  # si healthcheck Docker

Fail rapide : si le container n'est meme pas up, pas la peine de tester le reste.

Etape 9b - Port Readiness

Verifie que le port TCP repond (le process ecoute).

# Depuis prod-portainer
timeout 2 bash -c "echo > /dev/tcp/localhost/<port>"
# Ou nc -z localhost <port>

Retry : 10 tentatives x 2s (le service peut demarrer lentement). Fail = le process a crash ou ne bind pas le port.

Etape 9c - HTTP Health

Verifie que /health retourne HTTP 200 + status: healthy.

curl -sf --max-time 5 http://localhost:<port>/health

Retry : 5 tentatives x 3s (le service peut etre en init). Fail = le process tourne mais l'app n'est pas prete (DB, config, etc.)

Etape 9d - HTTPS External (si domain)

Verifie la chaine complete nginx → container via le domaine HTTPS.

curl -sf --max-time 10 https://<domain>/health

1 seule tentative : si 9c a passe, un echec ici = probleme nginx/SSL, pas l'app. Optionnel : skip si pas de domain configure.

Rollback

Declenche uniquement si 9b ou 9c echouent (probleme app). Pas de rollback sur 9a (container crash = probleme d'image/config, rollback inutile). Pas de rollback sur 9d (probleme nginx, pas l'app).

Changements fichiers

  1. lib/health.sh : ajouter check_container_running(), check_port_ready(), refactorer health_check() en version sans retry (single attempt), garder la boucle dans smart-deploy.sh
  2. smart-deploy.sh : remplacer le bloc 9 par 9a/9b/9c/9d avec des log_step separes et un diagnostic clair a chaque etape

Output attendu dans le CI/CD

[STEP] 9a. Container Check...
  ✓ Container ai-orchestrator is running (Up 5 seconds)

[STEP] 9b. Port Readiness...
  ○ Attempt 1/10: port 5501 not ready, waiting 2s...
  ○ Attempt 2/10: port 5501 not ready, waiting 2s...
  ✓ Port 5501 is accepting connections

[STEP] 9c. Health Check (internal)...
  ○ Attempt 1/5: service starting...
  ✓ Service healthy (HTTP 200, status: healthy)

[STEP] 9d. Health Check (external HTTPS)...
  ✓ https://ai-orchestrator.33800.nowhere84.com/health OK

Impact