name: mtusi_lab3_solution x-app: &app image: mtusi-lab3-api:local build: . environment: DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} POOL_MAX: ${POOL_MAX:-8} MESSAGE_ACCESS_FAST: ${MESSAGE_ACCESS_FAST:-1} secrets: [database_url, cache_url] cpus: ${API_CPUS:-0.5} mem_limit: ${API_MEMORY:-256m} stop_grace_period: 7s restart: unless-stopped services: postgres: image: postgres:16.10-alpine environment: POSTGRES_USER: messenger POSTGRES_DB: messenger POSTGRES_PASSWORD_FILE: /run/secrets/db_password secrets: [db_password] volumes: [pgdata:/var/lib/postgresql/data] cpus: ${DB_CPUS:-1.0} mem_limit: 512m healthcheck: test: [CMD-SHELL, 'pg_isready -U messenger -d messenger'] interval: 1s timeout: 1s retries: 30 redis: image: redis:7.4.6-alpine command: [redis-server, --maxmemory, 64mb, --maxmemory-policy, allkeys-lru] cpus: 0.25 mem_limit: 128m healthcheck: test: [CMD, redis-cli, ping] interval: 2s timeout: 1s retries: 20 migrate: <<: *app environment: DATABASE_URL_FILE: /run/secrets/database_url secrets: [database_url] command: [python, -m, app.migrate] restart: 'no' depends_on: postgres: {condition: service_healthy} api: <<: *app deploy: replicas: ${API_REPLICAS:-2} depends_on: migrate: {condition: service_completed_successfully} redis: {condition: service_healthy} healthcheck: test: [CMD, python, -c, "import urllib.request; urllib.request.urlopen('http://localhost:8080/health/ready', timeout=4)"] interval: 2s timeout: 5s retries: 2 start_period: 5s lb: image: haproxy:3.0.11-alpine ports: ['127.0.0.1:8080:8080'] volumes: ['./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro'] cpus: 0.5 mem_limit: 128m depends_on: api: {condition: service_healthy} volumes: pgdata: secrets: db_password: {file: ./secrets/db_password} database_url: {file: ./secrets/database_url} cache_url: {file: ./secrets/cache_url}