33800 Docs

← Retour

Proposition : Hooks pre/post deploy pour strategie Docker (smart-deploy)

Date : 29/01/2026 17:15 Status : IMPLEMENTEE Projet : smart-deploy (scripts/deploy) Priorite : HAUTE

Contexte

La strategie Docker de smart-deploy (strategies/docker.sh) n'a pas de mecanisme de hooks pre/post deploy. Les strategies files et remote en ont deja (pre_deploy / post_deploy dans la section deploy: du YAML).

Le cas d'usage principal : ai-orchestrator doit etre mis en pause avant deploiement (pour finir les jobs en cours et liberer la VRAM), puis remis en marche apres.

Endpoints existants ai-orchestrator

Endpoint Methode Description
/api/worker/pause?stop_tools=true POST Met en pause + arrete les outils (libere VRAM)
/api/worker/status GET Retourne {"status": "paused"\|"running", ...}
/api/worker/resume POST Reprend le traitement des jobs

Solution proposee

1. Nouveau format YAML : section hooks:

# conf.prod.gouroubleu.yml (ai-orchestrator)
name: ai-orchestrator
target: prod-portainer
type: python
port: 5501
domain: ai-orchestrator.33800.nowhere84.com

hooks:
  pre_deploy:
    - action: http
      method: POST
      url: "http://localhost:5501/api/worker/pause?stop_tools=true"
      description: "Pause worker + stop tools"
    - action: wait_http
      method: GET
      url: "http://localhost:5501/api/worker/status"
      jq_condition: ".status == \"paused\""
      timeout: 60
      interval: 3
      description: "Attendre que le worker soit en pause"
  post_deploy:
    - action: http
      method: POST
      url: "http://localhost:5501/api/worker/resume"
      description: "Resume worker"

2. Types d'actions supportees

Action Description Parametres
http Requete HTTP simple (fire & forget) method, url, headers (optionnel), body (optionnel)
wait_http Requete HTTP en boucle jusqu'a condition method, url, jq_condition, timeout (sec, defaut 60), interval (sec, defaut 5)
shell Commande shell locale command
ssh Commande SSH sur le target command

3. Implementation dans smart-deploy

Fichier a creer : lib/hooks.sh (~120 lignes)

# Fonctions principales :
# parse_hooks()       - Parse la section hooks: du YAML
# run_hooks()         - Execute une liste de hooks (pre ou post)
# run_hook_http()     - Execute une requete HTTP via curl
# run_hook_wait_http() - Boucle avec condition jq
# run_hook_shell()    - Execute commande locale
# run_hook_ssh()      - Execute commande SSH sur target

Fichier a modifier : strategies/docker.sh

Fichier a modifier : lib/parse-yaml.sh

4. Flux de deploiement modifie

1. Parse YAML config
2. Resolve target, inject env
3. >>> run_hooks "pre_deploy" <<<     (NOUVEAU)
4. Build image, push to registry
5. docker compose down / up (ou ZDT swap)
6. Health check (avec rollback si echec)
7. >>> run_hooks "post_deploy" <<<    (NOUVEAU)
8. Update registry, notify

Important : Si un hook pre_deploy echoue, le deploiement est ANNULE (exit 1). Si un hook post_deploy echoue, un warning est emis mais le deploiement est considere reussi (le service tourne deja).

5. Securite / edge cases

Fichiers a modifier/creer

Fichier Action
scripts/deploy/lib/hooks.sh CREER
scripts/deploy/lib/parse-yaml.sh MODIFIER (ajouter parse_yaml_hooks)
scripts/deploy/strategies/docker.sh MODIFIER (appels run_hooks)
scripts/deploy/smart-deploy.sh MODIFIER (source hooks.sh)
projects/ai-orchestrator/conf.prod.gouroubleu.yml MODIFIER (ajouter section hooks)

Estimation