name: mtusi-lab3 x-api: &api image: ${API_IMAGE:-mtusi-messenger:lab3} build: context: . args: VCS_REF: ${VCS_REF:-uncommitted} user: "10001:10001" read_only: true tmpfs: ["/tmp:rw,noexec,nosuid,size=16m"] cap_drop: [ALL] security_opt: [no-new-privileges:true] pids_limit: 96 cpus: ${API_CPU:-1} mem_limit: ${API_MEMORY:-512m} memswap_limit: ${API_MEMORY:-512m} stop_grace_period: 7s secrets: [database_url, cache_url] environment: APP_HOST: 0.0.0.0 APP_PORT: 8080 APP_ENV: lab3 SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400} DATABASE_READ_AUTOCOMMIT: ${DATABASE_READ_AUTOCOMMIT:-1} DATABASE_POOL_SIZE: ${DATABASE_POOL_SIZE:-8} DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url networks: [backend] services: postgres: image: postgres:18.3 environment: POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] volumes: [postgres_data:/var/lib/postgresql] command: [postgres, -c, fsync=on, -c, synchronous_commit=on, -c, full_page_writes=on, -c, shared_preload_libraries=pg_stat_statements] healthcheck: test: [CMD-SHELL, "pg_isready -U messenger -d messenger"] interval: 2s timeout: 2s retries: 30 cpus: ${POSTGRES_CPU:-1} mem_limit: 768m memswap_limit: 768m networks: [backend] valkey: image: valkey/valkey:8.1.3-alpine command: [valkey-server, --save, "", --appendonly, "no", --maxmemory, 64mb, --maxmemory-policy, allkeys-lru] healthcheck: test: [CMD, valkey-cli, ping] interval: 2s timeout: 1s retries: 20 cpus: 0.5 mem_limit: 128m memswap_limit: 128m networks: [backend] migrate: <<: *api command: [python, -m, messenger.migrate] healthcheck: {disable: true} depends_on: postgres: {condition: service_healthy} api: <<: *api deploy: replicas: ${API_REPLICAS:-2} depends_on: migrate: {condition: service_completed_successfully} valkey: {condition: service_healthy} lb: image: haproxy:3.2.1-alpine volumes: [./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro] ports: ["127.0.0.1:${PUBLIC_PORT:-8083}:8080"] read_only: true tmpfs: ["/tmp:rw,noexec,nosuid,size=4m"] cap_drop: [ALL] security_opt: [no-new-privileges:true] cpus: 0.5 mem_limit: 128m memswap_limit: 128m healthcheck: test: [CMD, wget, -q, -O, /dev/null, http://127.0.0.1:8080/health/ready] interval: 2s timeout: 2s retries: 30 depends_on: api: {condition: service_healthy} networks: [backend] networks: backend: {} volumes: postgres_data: secrets: postgres_password: file: ./secrets/postgres_password database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url