выполнение ЛР3 на 4
This commit is contained in:
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
N=$(docker compose ps -q api | wc -l | tr -d ' ')
|
||||
[ "$N" -ge 1 ] || { echo "api is not running" >&2; exit 1; }
|
||||
OLD=$(docker compose ps -q api)
|
||||
|
||||
docker compose build api
|
||||
docker compose run --rm --no-deps migrate
|
||||
|
||||
wait_healthy() {
|
||||
i=0
|
||||
until [ "$(docker inspect -f '{{.State.Health.Status}}' "$1")" = healthy ]; do
|
||||
i=$((i + 1)); [ "$i" -le 60 ] || { echo "replica $1 not healthy" >&2; exit 1; }
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
for old in $OLD; do
|
||||
before=$(docker compose ps -q api | sort)
|
||||
docker compose up -d --no-deps --no-recreate --scale api=$((N + 1)) api >/dev/null 2>&1
|
||||
new=$(docker compose ps -q api | sort | grep -vxF "$before" || true)
|
||||
[ -n "$new" ] || { echo "no new replica started" >&2; exit 1; }
|
||||
wait_healthy "$new"
|
||||
sleep 2
|
||||
printf '%s new %s healthy; stopping old %s\n' "$(date -u +%H:%M:%S)" \
|
||||
"$(docker inspect -f '{{.Name}}' "$new")" "$(docker inspect -f '{{.Name}}' "$old")"
|
||||
docker stop --time 8 "$old" >/dev/null
|
||||
docker rm "$old" >/dev/null
|
||||
done
|
||||
docker compose ps api --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}'
|
||||
Reference in New Issue
Block a user