services: db: image: postgres:16.15-alpine command: postgres -c max_connections=200 -c shared_buffers=256MB -c synchronous_commit=off environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} POSTGRES_DB: ${POSTGRES_DB} volumes: - pgdata:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] interval: 5s timeout: 3s retries: 20 start_period: 10s cpus: ${DB_CPU_LIMIT:-1.0} mem_limit: 512m stop_grace_period: 20s cache: image: valkey/valkey:8.1.10-alpine command: ["valkey-server", "--appendonly", "yes", "--appendfsync", "everysec"] volumes: - valkeydata:/data healthcheck: test: ["CMD", "valkey-cli", "ping"] interval: 5s timeout: 3s retries: 20 start_period: 5s cpus: "0.50" mem_limit: 256m stop_grace_period: 15s api: build: . image: mtusi2026lab3-api:local depends_on: db: condition: service_healthy cache: condition: service_healthy environment: APP_HOST: 0.0.0.0 APP_PORT: "8080" SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} SESSION_STORE: ${SESSION_STORE:-redis} DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400} DRAIN_SECONDS: ${DRAIN_SECONDS:-2} secrets: - database_url - cache_url healthcheck: test: ["CMD", "curl", "-fsS", "http://127.0.0.1:8080/health/ready"] interval: 5s timeout: 3s retries: 12 start_period: 20s deploy: replicas: ${API_REPLICAS:-2} resources: limits: cpus: ${API_CPU_LIMIT:-0.50} memory: ${API_MEM_LIMIT:-256M} cpus: ${API_CPU_LIMIT:-0.50} # для совместимости с docker compose up mem_limit: ${API_MEM_LIMIT:-256m} stop_grace_period: 15s lb: image: nginx:1.28.0-alpine depends_on: api: condition: service_healthy ports: - "8080:8080" volumes: - ./lb/nginx.conf:/etc/nginx/nginx.conf:ro healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/ready"] interval: 5s timeout: 3s retries: 12 start_period: 10s cpus: ${LB_CPU_LIMIT:-0.25} mem_limit: 128m stop_grace_period: 10s secrets: database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url volumes: pgdata: {} valkeydata: {}