https://github.com/sudo-bmitch/docker-stack-wait/blob/main/docker-stack-wait.sh
version: '3.7'
services:
normal:
image: busybox
command: /bin/sh -c ":>/healthy; tail -f /dev/null"
healthcheck:
test: /bin/sh -c "[ -f /healthy ] && exit 0 || exit 1"
interval: 15s
start_period: 60s
retries: 3
slow:
image: busybox:1.34
command: /bin/sh -c "sleep 50; :>/healthy; tail -f /dev/null"
healthcheck:
test: /bin/sh -c "[ -f /healthy ] && exit 0 || exit 1"
interval: 15s
start_period: 60s
retries: 3
tooslow:
image: busybox
command: /bin/sh -c "sleep 300; :>/healthy; tail -f /dev/null"
healthcheck:
test: /bin/sh -c "[ -f /healthy ] && exit 0 || exit 1"
interval: 15s
start_period: 60s
retries: 3lorsqu'on deploie une stack :
docker service inspect nous renvoie rien d'utile pour savoir si le service est deployé
par contre lorsqu'on redeploie,
ya un champ UpdateStatus.State = updating
qui devient UpdateStatus.State = completed
quand ça echoue à cause d'un healthcheck en erreur ça dit paused
quand ça dit rollback_* c'est que ça fait un rollback
quand un rollback echoue ça dit rollback_paused
quand un rollback marche ça dit rollback_completed
# detruire toutes les stacks
docker stack rm swarm
# lancer la stack
docker stack deploy --prune --with-registry-auth -c docker-compose.yml swarm
# attendre que ça win
docker-stack-wait.sh swarm
docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock sudobmitch/docker-stack-wait -f label=deploy.wait=true swarm
# voir le status des services
docker service inspect $(docker stack services -q swarm)
# ou mieux, mais ne parchera qu'apres un redeploiement (car sinon .UpdateStatus est null et ça plante)
docker service inspect -f '{{.UpdateStatus.State}}' $(docker stack services -q swarm)
# une fois que le service est ok, on peut checker le nombre de répliques
docker service ls --format '{{.Replicas}}' --filter "id=ofakl80n44ki"