services: postgres: image: postgres:17.4-alpine cpus: "1.0" mem_limit: 512m environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"] interval: 5s timeout: 3s retries: 20 redis: image: redis:7.4.2-alpine cpus: "0.25" mem_limit: 128m command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always"] volumes: - redis_data:/data healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 5s timeout: 3s retries: 20 migrate: build: . cpus: "0.5" mem_limit: 256m command: ["alembic", "upgrade", "head"] environment: DATABASE_URL: ${DATABASE_URL} REDIS_URL: ${REDIS_URL} SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS} depends_on: postgres: condition: service_healthy restart: "no" api: build: . cpus: "0.5" mem_limit: 256m environment: DATABASE_URL: ${DATABASE_URL} REDIS_URL: ${REDIS_URL} SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS} LOG_LEVEL: ${LOG_LEVEL:-info} expose: - "8080" deploy: replicas: 2 depends_on: migrate: condition: service_completed_successfully redis: condition: service_healthy healthcheck: test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=3).read()"] interval: 2s timeout: 2s retries: 5 stop_grace_period: 10s lb: image: haproxy:3.2.26-alpine cpus: "0.25" mem_limit: 128m ports: - "${APP_PORT:-8080}:8080" volumes: - ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro depends_on: api: condition: service_healthy healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/live"] interval: 2s timeout: 2s retries: 5 stop_grace_period: 5s volumes: postgres_data: redis_data: