name: mtusi-lab3 x-app: &app build: . image: mtusi-messenger:lab3 cpus: 0.5 mem_limit: 256m environment: SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url secrets: [database_url, cache_url] services: postgres: image: postgres:16.6-bookworm cpus: 1 mem_limit: 512m 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: 3s retries: 30 valkey: image: valkey/valkey:8.0.2-alpine cpus: 0.25 mem_limit: 128m command: [valkey-server, --appendonly, 'yes', --maxmemory, 64mb, --maxmemory-policy, allkeys-lru] volumes: [valkey-data:/data] migrate: <<: *app command: [python, app/migrate.py] depends_on: postgres: {condition: service_healthy} api: <<: *app deploy: replicas: 2 stop_grace_period: 10s depends_on: migrate: {condition: service_completed_successfully} valkey: {condition: service_started} lb: image: haproxy:3.0.5-alpine cpus: 0.5 mem_limit: 128m ports: ['127.0.0.1:${HOST_PORT:-8080}:8080'] volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro'] depends_on: api: {condition: service_healthy} volumes: postgres-data: valkey-data: secrets: postgres_password: file: ./secrets/postgres_password database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url