name: mtusi-vasilev-lab3 x-application: &application networks: [backend] image: ${API_IMAGE:-mtusi-vasilev:lab3} build: context: . args: VCS_REF: ${VCS_REF:-uncommitted} environment: DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} POOL_MAX_SIZE: ${POOL_MAX_SIZE:-8} secrets: [database_url, cache_url] cpus: ${API_CPUS:-0.5} mem_limit: ${API_MEMORY:-256m} pids_limit: 96 read_only: true tmpfs: ["/tmp:size=16m,noexec,nosuid"] cap_drop: [ALL] security_opt: [no-new-privileges:true] stop_grace_period: 8s services: postgres: networks: [backend] image: postgres:17.10-alpine environment: POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] volumes: [postgres_data:/var/lib/postgresql/data] healthcheck: test: [CMD-SHELL, "pg_isready -U messenger -d messenger"] interval: 2s timeout: 2s retries: 15 cpus: ${PG_CPUS:-1} mem_limit: ${PG_MEMORY:-768m} command: [postgres, -c, fsync=on, -c, synchronous_commit=on, -c, full_page_writes=on] cache: networks: [backend] 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: 2s retries: 15 cpus: 0.5 mem_limit: 128m migrate: <<: *application command: [python, -m, messenger.migrate] healthcheck: disable: true depends_on: postgres: {condition: service_healthy} api: <<: *application networks: [frontend, backend] deploy: replicas: ${API_REPLICAS:-2} depends_on: migrate: {condition: service_completed_successfully} cache: {condition: service_healthy} lb: networks: [frontend] image: haproxy:3.2-alpine@sha256:96ec3c75a9264ba94e733eeacb44051ed6e7b79bb77a73c2c36f236b6423f1f0 ports: ["127.0.0.1:${PUBLIC_PORT:-8083}:8080"] volumes: ["./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro"] depends_on: api: {condition: service_healthy} cpus: 0.5 mem_limit: 128m read_only: true tmpfs: ["/tmp:size=8m"] cap_drop: [ALL] security_opt: [no-new-privileges:true] healthcheck: test: [CMD-SHELL, "wget -q -O /dev/null http://127.0.0.1:8080/health/ready"] interval: 2s timeout: 2s retries: 10 volumes: postgres_data: secrets: postgres_password: {file: ./secrets/postgres_password} database_url: {file: ./secrets/database_url} cache_url: {file: ./secrets/cache_url} networks: frontend: backend: