Реализовать стенд лабораторной 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:
drunkdiente
2026-11-07 16:04:29 +03:00
parent 0ab3a341aa
commit 3aba500a0e
51 changed files with 1629 additions and 22 deletions
+9
View File
@@ -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
+23
View File
@@ -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"