x-app: &app build: . image: shemruk-messenger-lab3:local cpus: 1.0 mem_limit: 320m init: true environment: DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url CURSOR_KEY_FILE: /run/secrets/cursor_key SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} secrets: [database_url, cache_url, cursor_key] services: db: image: postgres:17.6-bookworm cpus: 1.0 mem_limit: 512m environment: POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/db_password secrets: [db_password] volumes: [postgres_data:/var/lib/postgresql/data] healthcheck: test: [CMD-SHELL, pg_isready -U messenger -d messenger -h 127.0.0.1] interval: 2s timeout: 2s retries: 20 cache: image: redis:7.4.6-bookworm cpus: 0.5 mem_limit: 128m command: [redis-server, /run/secrets/redis_config] secrets: [redis_config, cache_password] volumes: [redis_data:/data] healthcheck: test: [CMD-SHELL, 'REDISCLI_AUTH=$$(cat /run/secrets/cache_password) redis-cli ping | grep -qx PONG'] interval: 2s timeout: 2s retries: 20 migrate: <<: *app command: [python, -m, db] depends_on: db: {condition: service_healthy} api: <<: *app scale: ${API_REPLICAS:-2} cpus: ${API_CPUS:-0.75} mem_limit: ${API_MEMORY:-256m} stop_grace_period: 12s depends_on: migrate: {condition: service_completed_successfully} cache: {condition: service_healthy} healthcheck: test: [CMD, python, -c, "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=3)"] interval: 2s timeout: 4s retries: 20 lb: image: haproxy:3.2.28-trixie cpus: 0.5 mem_limit: 96m ports: ["127.0.0.1:${HTTP_PORT:-8080}:8080"] volumes: - ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro depends_on: [api] volumes: postgres_data: redis_data: secrets: database_url: {file: ./secrets/database_url} db_password: {file: ./secrets/db_password} cache_url: {file: ./secrets/cache_url} cache_password: {file: ./secrets/cache_password} cursor_key: {file: ./secrets/cursor_key} redis_config: {file: ./secrets/redis.conf}