Brings the system changes of lab 2 from 8cddb09..102579e onto the lab 3 code, resolving each conflict by meaning: - the request pipeline counts the body bytes actually received, so a chunked body over the limit gets 413 instead of reaching the app; - logout revokes through a SessionRevocations port and withdraws the mark when PostgreSQL rejects the delete, so 503 means the session still works; PostgresSessionDirectory loses its no-op invalidate; - an empty cursor is 400 on history and on the chat list; - EventBus.project and the test that allowed importing an event across zones are gone, the config rules speak of the schema foreign key; - the worker waits one second less than the rest of the shutdown budget, so it cancels a stuck request with 500 and exits 0 instead of being killed by the gunicorn master. Lab 3 keeps 3 s after the drain window for the database timeouts, so SHUTDOWN_TIMEOUT_SECONDS becomes 6 s and the stop hooks wait 7 s, still under the 8 s grace; - the lab 3 single statement post already locks the chat only for a member, so lab 2's LOCK_CHAT edit is not needed; its test is kept; - lab 2 tests come along with Idempotency-Key where lab 3 needs it; the short TTL after restart runs without api-shortttl by shortening the session in the database; test_drain adds a stuck request; - make validate uses .venv with openapi-spec-validator, PYTEST_ARGS, faults-evidence, down with the bench profile, the image is tagged by the compose project, start probes every 200 ms, cache evidence fails without a tombstone and checks the key expiry, kdf.txt shows the seed stub apart. The track 2 tooling of lab 2 (track.py, postgres-restore and the database argument of migrate) and its evidence scripts stay out. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
192 lines
5.4 KiB
YAML
192 lines
5.4 KiB
YAML
x-app: &app
|
|
image: ${API_IMAGE:-mtusi-messenger:${COMPOSE_PROJECT_NAME}}
|
|
networks: [backend]
|
|
|
|
services:
|
|
lb:
|
|
image: haproxy:3.2.26-alpine@sha256:5893840576071e6217cd52ebdcc14f454c6f7a631056fa6f4e0f40d3cac4215b
|
|
environment:
|
|
API_SERVER_MAXCONN: ${API_SERVER_MAXCONN:-64}
|
|
volumes: [./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro]
|
|
ports:
|
|
- "127.0.0.1:${LB_HTTP_PORT:-8080}:8080"
|
|
- "127.0.0.1:${LB_STATS_PORT:-8404}:8404"
|
|
networks: [edge, backend]
|
|
healthcheck:
|
|
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8404/healthz"]
|
|
interval: 2s
|
|
timeout: 2s
|
|
retries: 3
|
|
start_period: 10s
|
|
sysctls:
|
|
net.ipv4.ip_local_port_range: "10240 65535"
|
|
net.ipv4.tcp_tw_reuse: "1"
|
|
stop_signal: SIGUSR1
|
|
stop_grace_period: 8s
|
|
restart: unless-stopped
|
|
read_only: true
|
|
cap_drop: [ALL]
|
|
cpuset: ${LB_CPUSET:-}
|
|
deploy:
|
|
resources:
|
|
limits: {cpus: "${LB_CPUS:-1}", memory: 128m}
|
|
|
|
api:
|
|
<<: *app
|
|
build: .
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
CACHE_URL_FILE: /run/secrets/cache_url
|
|
CURSOR_SECRET_FILE: /run/secrets/cursor_secret
|
|
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
|
|
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
|
|
WEB_CONCURRENCY: ${WEB_CONCURRENCY:-2}
|
|
DB_POOL_MAX_SIZE: ${DB_POOL_MAX_SIZE:-8}
|
|
REQUEST_TIMEOUT_SECONDS: ${REQUEST_TIMEOUT_SECONDS:-8}
|
|
DB_ACQUIRE_TIMEOUT_SECONDS: ${DB_ACQUIRE_TIMEOUT_SECONDS:-1}
|
|
DB_COMMAND_TIMEOUT_SECONDS: ${DB_COMMAND_TIMEOUT_SECONDS:-2}
|
|
DRAIN_SECONDS: ${DRAIN_SECONDS:-2}
|
|
SHUTDOWN_TIMEOUT_SECONDS: ${SHUTDOWN_TIMEOUT_SECONDS:-6}
|
|
LOG_LEVEL: ${LOG_LEVEL:-INFO}
|
|
secrets: [database_url, cache_url, cursor_secret]
|
|
healthcheck:
|
|
test: ["CMD", "python", "-c", "import sys,urllib.request;sys.exit(urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=2).status!=200)"]
|
|
interval: 5s
|
|
timeout: 3s
|
|
retries: 3
|
|
start_period: 30s
|
|
start_interval: 200ms
|
|
stop_grace_period: 8s
|
|
restart: unless-stopped
|
|
read_only: true
|
|
tmpfs: [/tmp]
|
|
cpuset: ${API_CPUSET:-}
|
|
depends_on:
|
|
migrate:
|
|
condition: service_completed_successfully
|
|
valkey:
|
|
condition: service_started
|
|
deploy:
|
|
replicas: ${API_REPLICAS:-2}
|
|
resources:
|
|
limits: {cpus: "${API_CPUS:-1}", memory: "${API_MEMORY:-512m}"}
|
|
|
|
migrate:
|
|
<<: *app
|
|
pull_policy: never
|
|
command: ["python", "-m", "messenger.migrate"]
|
|
environment:
|
|
DATABASE_URL_FILE: /run/secrets/database_url
|
|
LOG_LEVEL: ${LOG_LEVEL:-INFO}
|
|
secrets: [database_url]
|
|
healthcheck:
|
|
disable: true
|
|
restart: "no"
|
|
depends_on:
|
|
postgres:
|
|
condition: service_healthy
|
|
deploy:
|
|
resources:
|
|
limits: {cpus: "0.5", memory: 256m}
|
|
|
|
postgres:
|
|
image: postgres:17.11-alpine@sha256:266d3c257594e195b309ae9d1805e54c788f1d7b375f56bf6c367aac6c917e7b
|
|
user: "70:70"
|
|
command:
|
|
- postgres
|
|
- -c
|
|
- max_connections=${PG_MAX_CONNECTIONS:-200}
|
|
- -c
|
|
- shared_buffers=${PG_SHARED_BUFFERS:-256MB}
|
|
- -c
|
|
- shared_preload_libraries=pg_stat_statements
|
|
- -c
|
|
- pg_stat_statements.track=top
|
|
- -c
|
|
- track_io_timing=on
|
|
- -c
|
|
- idle_in_transaction_session_timeout=10s
|
|
environment:
|
|
POSTGRES_DB: messenger
|
|
POSTGRES_USER: messenger
|
|
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
|
secrets: [postgres_password]
|
|
volumes: [pgdata:/var/lib/postgresql/data]
|
|
shm_size: 256m
|
|
cpuset: ${PG_CPUSET:-}
|
|
healthcheck:
|
|
test: ["CMD", "pg_isready", "-h", "127.0.0.1", "-U", "messenger", "-d", "messenger"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 30
|
|
start_period: 10s
|
|
start_interval: 200ms
|
|
stop_grace_period: 10s
|
|
restart: unless-stopped
|
|
networks: [backend]
|
|
deploy:
|
|
resources:
|
|
limits: {cpus: "${PG_CPUS:-2}", memory: "${PG_MEMORY:-1g}"}
|
|
|
|
valkey:
|
|
image: valkey/valkey:8.1.11-alpine@sha256:2602ace2be6569bc2bbb06f873776516ab9089821525be34f4305c67eb9db02a
|
|
user: "999:1000"
|
|
command:
|
|
- valkey-server
|
|
- /run/secrets/valkey.conf
|
|
- --appendonly
|
|
- "yes"
|
|
- --appendfsync
|
|
- always
|
|
- --maxmemory
|
|
- 64mb
|
|
- --maxmemory-policy
|
|
- volatile-lru
|
|
secrets: [valkey.conf]
|
|
volumes: [valkeydata:/data]
|
|
cpuset: ${VALKEY_CPUSET:-}
|
|
healthcheck:
|
|
test: ["CMD-SHELL", "REDISCLI_AUTH=\"$$(sed -n 's/^requirepass //p' /run/secrets/valkey.conf)\" valkey-cli ping | grep -q PONG"]
|
|
interval: 2s
|
|
timeout: 3s
|
|
retries: 30
|
|
stop_grace_period: 10s
|
|
restart: unless-stopped
|
|
networks: [backend]
|
|
deploy:
|
|
resources:
|
|
limits: {cpus: "0.5", memory: 128m}
|
|
|
|
k6:
|
|
image: grafana/k6:2.3.0@sha256:2dd4756ec6e14e62778916e1eb850108e4b499304c02df56760fa0bdb0fba0b8
|
|
profiles: [bench]
|
|
environment:
|
|
BASE_URL: http://lb:8080
|
|
volumes: [./infra/k6:/scripts:ro]
|
|
networks: [edge]
|
|
cpuset: ${K6_CPUSET:-}
|
|
deploy:
|
|
resources:
|
|
limits: {cpus: "${K6_CPUS:-2}", memory: "${K6_MEMORY:-512m}"}
|
|
|
|
secrets:
|
|
postgres_password:
|
|
file: ./secrets/postgres_password
|
|
database_url:
|
|
file: ./secrets/database_url
|
|
valkey.conf:
|
|
file: ./secrets/valkey.conf
|
|
cache_url:
|
|
file: ./secrets/cache_url
|
|
cursor_secret:
|
|
file: ./secrets/cursor_secret
|
|
|
|
volumes:
|
|
pgdata:
|
|
valkeydata:
|
|
|
|
networks:
|
|
edge:
|
|
backend:
|
|
internal: true
|