name: mtusi-lab3 x-application: &application image: mtusi-messenger:lab3 build: . env_file: .env cpus: 1 mem_limit: 256m x-postgres: &postgres image: postgres:17.6-bookworm environment: POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] cpus: 1 mem_limit: 512m healthcheck: test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"] interval: 2s timeout: 3s retries: 30 services: postgres: <<: *postgres volumes: [postgres_data:/var/lib/postgresql/data] valkey: image: valkey/valkey:8.1.3 command: ["valkey-server", "--appendonly", "yes", "--appendfsync", "always", "--save", "", "--maxmemory", "64mb", "--maxmemory-policy", "noeviction"] volumes: [valkey_data:/data] cpus: 0.5 mem_limit: 128m healthcheck: test: ["CMD", "valkey-cli", "ping"] interval: 2s timeout: 3s retries: 30 api: <<: *application deploy: replicas: ${API_REPLICAS:-2} environment: SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} secrets: [database_url, cache_url] depends_on: postgres: {condition: service_healthy} valkey: {condition: service_healthy} migrate: {condition: service_completed_successfully} stop_grace_period: 8s migrate: <<: *application command: ["python", "-m", "src.migrate"] secrets: [database_url] healthcheck: disable: true depends_on: postgres: {condition: service_healthy} lb: image: haproxy:3.2.6-alpine ports: ["127.0.0.1:${HOST_PORT:-8080}:8080"] volumes: [./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro] cpus: 0.5 mem_limit: 64m depends_on: api: {condition: service_healthy} stop_grace_period: 10s healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/ready"] interval: 2s timeout: 2s retries: 3 postgres-restore: <<: *postgres profiles: [research] volumes: [restore_data:/var/lib/postgresql/data] volumes: postgres_data: valkey_data: restore_data: secrets: postgres_password: file: ./secrets/postgres_password database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url