forked from mtusi2026/mtusi2026lab3
Реализовать стенд лабораторной 3: две API-реплики и балансировка
FastAPI + PostgreSQL как единый источник истины: пользователи, Basic/Bearer-сессии, чаты, сообщения. Сессии и идемпотентные ключи хранятся в БД, поэтому реплики взаимозаменяемы. Общая идемпотентность POST сообщения по Idempotency-Key, включая конкурентный повтор через разные реплики. compose.yaml: postgres, one-shot migrate, api1, api2 и nginx как единственная публичная точка входа. Добавлены scripts/stop-one.sh и scripts/restart.sh, student-tests, evidence и заполненный REPORT.md.
This commit is contained in:
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
# Restart the API replicas, the load balancer and the shared PostgreSQL.
|
||||
# Volumes are preserved: no `down -v`, no re-seed, no data removal.
|
||||
set -eu
|
||||
|
||||
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
cd "$ROOT"
|
||||
|
||||
docker compose --env-file .env -f compose.yaml restart postgres api1 api2 lb
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
# Stop exactly one API replica identified by the X-Instance-Id alias supplied
|
||||
# by the failover test. The replica is intentionally left stopped; restore it
|
||||
# explicitly with: docker compose start api1 (or api2).
|
||||
set -eu
|
||||
|
||||
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
|
||||
|
||||
case "$TARGET_INSTANCE_ID" in
|
||||
api-1) service=api1 ;;
|
||||
api-2) service=api2 ;;
|
||||
*)
|
||||
printf 'unknown API instance alias: %s\n' "$TARGET_INSTANCE_ID" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
cd "$ROOT"
|
||||
|
||||
# -t 2 keeps the hook well inside the test's 10 second budget. `stop` keeps the
|
||||
# container (and volumes) in place and the container is not restarted by policy.
|
||||
exec docker compose --env-file .env -f compose.yaml stop --timeout 2 "$service"
|
||||
Reference in New Issue
Block a user