forked from mtusi2026/mtusi2026lab3
feat(infra): add replicated API and readiness-aware load balancing
Provide resource profiles, persistent storage, parallel Nginx health checks and graceful restart hooks.
This commit is contained in:
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
project_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
cd "$project_dir"
|
||||
|
||||
for service in api nginx postgres redis; do
|
||||
if [ -z "$(docker compose ps --all --quiet "$service")" ]; then
|
||||
printf '%s\n' "Missing container for $service; start the Compose stack first." >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
replicas=$(docker compose ps --all --quiet api | wc -l | tr -d ' ')
|
||||
if [ "$replicas" -lt 1 ]; then
|
||||
printf 'No API replicas found.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker compose stop --timeout 30 nginx api postgres redis
|
||||
docker compose up --detach --no-recreate --no-build --no-deps --wait --wait-timeout 45 postgres redis
|
||||
docker compose up --detach --no-recreate --no-build --no-deps --scale "api=$replicas" --wait --wait-timeout 45 api
|
||||
docker compose up --detach --no-recreate --no-build --no-deps nginx
|
||||
Reference in New Issue
Block a user