Files
mtusi2026lab3/compose.benchmark.yaml
2026-10-16 11:48:49 +03:00

103 lines
2.5 KiB
YAML

x-api: &api
build:
context: .
environment:
APP_HOST: 0.0.0.0
APP_PORT: 8080
APP_ENV: benchmark
DATABASE_URL_FILE: /run/secrets/database_url
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400}
CURSOR_SECRET_FILE: /run/secrets/cursor_secret
secrets:
- database_url
- cursor_secret
depends_on:
migrate:
condition: service_completed_successfully
expose:
- "8080"
healthcheck:
test: ["CMD", "/app/.venv/bin/python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2).read()"]
interval: 5s
timeout: 3s
retries: 12
start_period: 10s
deploy:
resources:
limits:
cpus: "${BENCH_API_CPUS}"
memory: ${BENCH_API_MEMORY}
services:
postgres:
image: postgres:17.6-alpine
environment:
POSTGRES_DB: messenger
POSTGRES_USER: messenger
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
secrets:
- postgres_password
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"]
interval: 5s
timeout: 3s
retries: 12
start_period: 5s
deploy:
resources:
limits:
cpus: "${BENCH_DB_CPUS:-0.75}"
memory: ${BENCH_DB_MEMORY:-512M}
migrate:
build:
context: .
command: ["/app/.venv/bin/python", "-m", "src.migrate"]
environment:
DATABASE_URL_FILE: /run/secrets/database_url
CURSOR_SECRET_FILE: /run/secrets/cursor_secret
secrets:
- database_url
- cursor_secret
depends_on:
postgres:
condition: service_healthy
api:
<<: *api
load_balancer:
image: haproxy:3.0.11-alpine
ports:
- "8081:8080"
volumes:
- ./infra/haproxy.benchmark.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on:
api:
condition: service_healthy
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8080/health/ready"]
interval: 5s
timeout: 3s
retries: 12
start_period: 5s
deploy:
resources:
limits:
cpus: "${BENCH_LB_CPUS:-0.25}"
memory: ${BENCH_LB_MEMORY:-128M}
secrets:
postgres_password:
file: ./secrets/postgres_password
database_url:
file: ./secrets/database_url
cursor_secret:
file: ./secrets/cursor_secret
volumes:
postgres_data: