name: mtusi-lab3 x-application: &application image: mtusi-messenger:lab3 networks: [backend] environment: &environment DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} HTTP_WORKERS: ${HTTP_WORKERS:-16} DB_POOL_MAX: ${DB_POOL_MAX:-8} DB_ACCESS_MODE: ${DB_ACCESS_MODE:-optimized} LOG_LEVEL: WARNING secrets: [database_url, cache_url] mem_limit: ${API_MEMORY:-256m} cpus: ${API_CPUS:-1} stop_grace_period: 10s services: migrate: <<: *application command: [python, src/migrate.py] healthcheck: disable: true deploy: replicas: 1 depends_on: postgres: condition: service_healthy api: <<: *application build: . deploy: replicas: ${API_REPLICAS:-2} depends_on: migrate: condition: service_completed_successfully redis: condition: service_healthy lb: image: haproxy:3.0.5-alpine@sha256:43a2591a6a62a41dd22edb4452880e9c70de489fbd7c54ffb52d035cccbfe949 ports: ["127.0.0.1:${APP_PORT:-18087}:8080"] volumes: - ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro networks: [edge, backend] depends_on: api: condition: service_healthy mem_limit: 64m cpus: 0.5 stop_grace_period: 12s healthcheck: test: [CMD, wget, -q, -O, /dev/null, http://127.0.0.1:8080/health/ready] interval: 2s timeout: 2s retries: 10 postgres: image: postgres:17.2-bookworm@sha256:3267c505060a0052e5aa6e5175a7b41ab6b04da2f8c4540fc6e98a37210aa2d3 environment: POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] volumes: [postgres_data:/var/lib/postgresql/data] networks: [backend] healthcheck: test: [CMD, pg_isready, -h, 127.0.0.1, -U, messenger, -d, messenger] interval: 2s timeout: 1s retries: 30 mem_limit: 512m cpus: ${POSTGRES_CPUS:-1} redis: image: redis:7.4.1-bookworm@sha256:bb142a9c18ac18a16713c1491d779697b4e107c22a97266616099d288237ef47 command: [redis-server, --maxmemory, 32mb, --maxmemory-policy, allkeys-lru, --save, "", --appendonly, "no"] networks: [backend] healthcheck: test: [CMD, redis-cli, ping] interval: 2s timeout: 1s retries: 30 mem_limit: 64m cpus: 0.25 volumes: postgres_data: networks: edge: backend: internal: true secrets: postgres_password: file: ./secrets/postgres_password database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url