forked from mtusi2026/mtusi2026lab3
- compose: один масштабируемый сервис api (deploy.replicas=2, без ports и container_name), HAProxy 3.2 LTS по digest — единственная точка входа (127.0.0.1), разовый migrate до старта реплик, CPU/RAM-лимиты у всех сервисов, каждому сервису только его secrets. - HAProxy: server-template + Docker DNS (re-resolve 1 с), активная проверка GET /health/ready каждую 1 с (fall 2 / rise 2), без backup-серверов, retry только conn-failure, ошибки самого LB — в формате контракта с X-Request-Id. - API: X-Instance-Id = hostname контейнера на каждом ответе (и на 500/503); Idempotency-Key обязателен; ключ, сообщение и результат пишутся в ОДНОЙ транзакции (миграция 0002), конкурентный повтор ждёт уникальный индекс; другой body — 409, посторонний — всегда 404; attachment_ids=[] равен отсутствию поля; дубли ключей JSON и тело у POST /auth/sessions — 400. - SIGTERM: readiness 503 + DRAIN_SECONDS=3 обслуживания, затем graceful stop. - scripts: stop-one.sh (+ .cmd для Windows), restore-api.sh, restart.sh перезапускает и LB, lbctl.py — состояние бэкендов HAProxy -> контейнеры. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.5 KiB
Bash
40 lines
1.5 KiB
Bash
# Copy to .env for your LOCAL synthetic test environment; never commit .env.
|
|
# These are logical interface suggestions; map actual framework names in REPORT.md.
|
|
APP_HOST=0.0.0.0
|
|
APP_PORT=8080
|
|
APP_ENV=lab
|
|
SESSION_TTL_SECONDS=3600
|
|
# Choose credentials locally. File paths contain no secret values.
|
|
# The files are created by `python scripts/init_secrets.py` and mounted by compose as secrets.
|
|
DATABASE_URL_FILE=/run/secrets/database_url
|
|
# Optional on 3, required use on 4 in lab2; Redis OR Valkey:
|
|
# valkey = sessions live only in Valkey (AOF, appendfsync always); postgres = table `sessions`.
|
|
SESSION_STORE=valkey
|
|
CACHE_URL_FILE=/run/secrets/cache_url
|
|
# Number of interchangeable API replicas behind HAProxy (compose deploy.replicas).
|
|
API_REPLICAS=2
|
|
# Idempotency-Key results are kept at least this long (contract: >= 24 h).
|
|
IDEMPOTENCY_TTL_SECONDS=86400
|
|
# Additional settings of this implementation (defaults shown; all optional):
|
|
LOG_LEVEL=info
|
|
DB_POOL_MIN=1
|
|
DB_POOL_MAX=10
|
|
DB_TIMEOUT_SECONDS=3
|
|
CACHE_TIMEOUT_SECONDS=0.5
|
|
PASSWORD_HASH_CONCURRENCY=2
|
|
DOCS_ENABLED=true
|
|
# Graceful stop of a replica: readiness 503 + drain, then up to SHUTDOWN for in-flight requests.
|
|
DRAIN_SECONDS=3
|
|
SHUTDOWN_TIMEOUT_SECONDS=8
|
|
# CPU/RAM limits (docker compose deploy.resources.limits); API_* are per replica.
|
|
API_CPUS=1.0
|
|
API_MEMORY=256m
|
|
PG_CPUS=2.0
|
|
PG_MEMORY=1g
|
|
VALKEY_CPUS=0.5
|
|
LB_CPUS=1.0
|
|
PG_MAX_CONNECTIONS=100
|
|
# Host ports of the load balancer (published on 127.0.0.1 only; API replicas publish nothing)
|
|
APP_PUBLISH_PORT=8080
|
|
LB_STATS_PORT=8404
|