compose.yaml now runs one api service with API_REPLICAS replicas and no published ports, container name or hostname, behind lb, HAProxy 3.2.26 LTS pinned by digest and the only service with ports, bound to 127.0.0.1 (LB_HTTP_PORT for HTTP, LB_STATS_PORT for read-only stats). The balancer finds replicas through Docker DNS with a server template, checks GET /health/ready every second (fall 2, rise 2), balances round robin without stickiness, retries connection failures on another replica and allows a retry after a sent request only for GET and for message posts carrying Idempotency-Key, never for users, chats or login. Its own 502/503/504 answers use the contract error body with the forwarded X-Request-Id. The network is split into edge and an internal backend, every service gets CPU and memory limits, the API runs read-only with a tmpfs /tmp, two workers per replica, an 8 s request limit and a 5 s graceful stop inside an 8 s stop_grace_period. Only api builds the image, migrate reuses it once before the replicas start. PostgreSQL loads pg_stat_statements and allows 200 connections. The short TTL instance of lab 2 published the API around the balancer and is removed; its expiry check stays as an in-process test. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
28 lines
949 B
Bash
28 lines
949 B
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.
|
|
DATABASE_URL_FILE=/run/secrets/database_url
|
|
# Optional on 3, required use on 4 in lab2; Redis OR Valkey:
|
|
SESSION_STORE=postgres
|
|
CACHE_URL_FILE=/run/secrets/cache_url
|
|
API_REPLICAS=2
|
|
IDEMPOTENCY_TTL_SECONDS=86400
|
|
# Solution-specific: published LB ports, replica limits, workers and pool per replica,
|
|
# LB queue per replica, PostgreSQL limits, cursor key file. API_PORT/SHORTTTL_PORT of lab2 are gone:
|
|
# only the load balancer is published.
|
|
LB_HTTP_PORT=8080
|
|
LB_STATS_PORT=8404
|
|
API_CPUS=1
|
|
API_MEMORY=512m
|
|
WEB_CONCURRENCY=2
|
|
DB_POOL_MAX_SIZE=8
|
|
API_SERVER_MAXCONN=64
|
|
PG_MAX_CONNECTIONS=200
|
|
PG_CPUS=2
|
|
PG_MEMORY=1g
|
|
CURSOR_SECRET_FILE=/run/secrets/cursor_secret
|