29 lines
925 B
Bash
29 lines
925 B
Bash
#!/bin/sh
|
|
set -eu
|
|
# Grade-4 rolling replacement: recreate API containers one-by-one under LB.
|
|
# Usage: scripts/rolling-update.sh
|
|
cd "$(dirname "$0")/.."
|
|
REPLICAS="${API_REPLICAS:-2}"
|
|
|
|
ids=$(docker compose --env-file .env ps -q api)
|
|
count=0
|
|
for id in $ids; do
|
|
[ -n "$id" ] || continue
|
|
count=$((count + 1))
|
|
printf '%s\n' "rolling: stopping $id"
|
|
docker stop -t 10 "$id" >/dev/null
|
|
# Bring fleet back to desired scale (starts a fresh replica; old stopped removed by up).
|
|
docker compose --env-file .env up -d --no-deps --scale "api=${REPLICAS}" --remove-orphans api
|
|
# Wait until LB again sees healthy backends via public ready.
|
|
i=0
|
|
while [ "$i" -lt 60 ]; do
|
|
if curl -sf "http://127.0.0.1:8080/health/ready" >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
i=$((i + 1))
|
|
sleep 1
|
|
done
|
|
printf '%s\n' "rolling: step $count ready"
|
|
done
|
|
printf '%s\n' "rolling update finished ($count steps, scale=${REPLICAS})"
|