From 572204950ad5796cd44e81fb9f5c45a0fe79c577 Mon Sep 17 00:00:00 2001 From: Artyom Date: Wed, 28 Oct 2026 19:52:19 +0300 Subject: [PATCH] Replace replicas one by one under load scripts/rolling-update.sh runs migrate once before touching any replica, then for each old replica scales the service to N+1 without recreating the others, waits until the new container is healthy and the balancer sees N+1 UP servers, and only then stops the old one with docker stop -t 6 (so it drains) and removes it. The log names the hostname and image of the old and the new replica of every step, which is what the report quotes. Co-Authored-By: Claude Opus 5.5 (1M context) --- scripts/rolling-update.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 scripts/rolling-update.sh diff --git a/scripts/rolling-update.sh b/scripts/rolling-update.sh new file mode 100755 index 00000000..8bbcb642 --- /dev/null +++ b/scripts/rolling-update.sh @@ -0,0 +1,20 @@ +#!/bin/sh +set -eu +cd "$(dirname "$0")/.." +service=${API_SERVICE:-api} +show() { docker inspect -f '{{.Config.Hostname}} image={{slice .Image 7 19}}' "$1"; } +echo "$(date -u +%T) migrate once before the first replacement" +docker compose run --rm --no-deps -T migrate 2>&1 +old=$(docker compose ps -q "$service") +count=$(printf '%s\n' "$old" | grep -c .) +for id in $old; do + running=$(docker compose ps -q "$service") + docker compose up -d --no-deps --no-recreate --wait --wait-timeout "${WAIT_TIMEOUT:-90}" --scale "$service=$((count + 1))" "$service" 2>&1 + scripts/lb-wait.sh $((count + 1)) + new=$(docker compose ps -q "$service" | grep -v -F "$running") + echo "$(date -u +%T) replace $(show "$id") -> $(show "$new")" + docker stop -t "${STOP_TIMEOUT:-6}" "$id" >/dev/null + docker rm "$id" >/dev/null +done +scripts/lb-wait.sh "$count" +echo "$(date -u +%T) done: $count replicas replaced"