name: mtusi-lab3-chernenko services: db: image: postgres:17.5-bookworm environment: POSTGRES_DB: messenger POSTGRES_USER: messenger POSTGRES_PASSWORD_FILE: /run/secrets/db_password secrets: [db_password] volumes: [pgdata:/var/lib/postgresql/data] networks: [data] cpus: ${DB_CPUS:-1.0} mem_limit: 512m healthcheck: test: [CMD-SHELL, "pg_isready -U messenger -d messenger"] interval: 2s timeout: 1s retries: 20 stop_grace_period: 15s migrate: image: mtusi-lab3-api:local build: context: . target: api command: [python, -m, src.migrate] environment: DATABASE_URL_FILE: /run/secrets/database_url secrets: [database_url] networks: [data] depends_on: db: condition: service_healthy cpus: 0.5 mem_limit: 128m api: image: mtusi-lab3-api:local build: context: . target: api environment: DATABASE_URL_FILE: /run/secrets/database_url CURSOR_KEY_FILE: /run/secrets/cursor_key SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400} DB_POOL_SIZE: ${DB_POOL_SIZE:-4} secrets: [database_url, cursor_key] networks: [edge, data] depends_on: migrate: condition: service_completed_successfully deploy: replicas: ${API_REPLICAS:-2} cpus: ${API_CPUS:-0.5} mem_limit: ${API_MEMORY:-256m} stop_grace_period: 8s healthcheck: test: [CMD, python, -c, "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"] interval: 2s timeout: 3s retries: 3 start_period: 5s lb: image: haproxy:3.0.11-alpine ports: ["127.0.0.1:${PUBLIC_PORT:-8080}:8080"] volumes: [./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro] networks: [edge] depends_on: api: condition: service_healthy cpus: 0.5 mem_limit: 128m stop_grace_period: 8s tester: image: mtusi-lab3-tester:local profiles: [tools] build: context: . target: tester environment: BASE_URL: http://lb:8080 COMPOSE_PROJECT_NAME: mtusi-lab3-chernenko volumes: - .:/workspace - /var/run/docker.sock:/var/run/docker.sock networks: [edge] cpus: 2.0 mem_limit: 512m secrets: db_password: file: ./secrets/db_password database_url: file: ./secrets/database_url cursor_key: file: ./secrets/cursor_key volumes: pgdata: networks: edge: data: internal: true