forked from mtusi2026/mtusi2026lab3
ЛР 3 — БПИ2303 — Морару — на 5: API на TypeScript/Node, HAProxy, failover, трек 1
This commit is contained in:
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
# Rolling replacement for Compose: rebuild the image, then for each old replica start one new replica,
|
||||
# wait until it is healthy (HAProxy picks it up via DNS), and only then stop/remove the old one.
|
||||
# Migrations run before (expand-only, compatible with the running version).
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
docker compose build api >/dev/null
|
||||
docker compose run --rm migrate >/dev/null
|
||||
old=$(docker compose ps -q api)
|
||||
known=$old
|
||||
n=$(printf '%s\n' "$old" | grep -c .)
|
||||
for cid in $old; do
|
||||
docker compose up -d --no-deps --no-recreate --scale api=$((n + 1)) api >/dev/null 2>&1
|
||||
new=$(docker compose ps -q api | grep -v -F "$known")
|
||||
known="$known
|
||||
$new"
|
||||
until [ "$(docker inspect -f '{{.State.Health.Status}}' "$new")" = healthy ]; do sleep 1; done
|
||||
sleep 2 # rise 2 x inter 1 s: LB marks the new replica UP
|
||||
docker stop "$cid" >/dev/null && docker rm "$cid" >/dev/null
|
||||
echo "replaced $(echo "$cid" | cut -c1-12) -> $(echo "$new" | cut -c1-12)"
|
||||
done
|
||||
Reference in New Issue
Block a user