x-api: &api image: mtusi2026lab3-api:local build: . dns_opt: - timeout:1 - attempts:1 environment: APP_HOST: 0.0.0.0 APP_PORT: 8080 POSTGRES_HOST: postgres POSTGRES_DB: ${POSTGRES_DB:-messenger} POSTGRES_USER: ${POSTGRES_USER:-messenger} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env} REDIS_URL: redis://redis:6379/0 SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} CACHE_TTL_SECONDS: ${CACHE_TTL_SECONDS:-30} MAX_REQUEST_BYTES: ${MAX_REQUEST_BYTES:-65536} MAX_INFLIGHT: ${MAX_INFLIGHT:-32} networks: [backend] cpus: 1.0 mem_limit: 512m stop_grace_period: 10s services: api: <<: *api deploy: 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://127.0.0.1:8080/health/ready', timeout=1).read()"] interval: 2s timeout: 2s start_period: 5s retries: 2 migrate: <<: *api command: [python, -m, src.database] healthcheck: disable: true restart: 'no' depends_on: postgres: condition: service_healthy nginx: image: nginx:1.28.0-alpine entrypoint: [sh, /etc/nginx/readiness.sh] dns_opt: - timeout:1 - attempts:1 ports: - '127.0.0.1:${APP_PORT:-8080}:8080' volumes: - ./infra/nginx.conf:/etc/nginx/nginx.conf:ro - ./infra/readiness.sh:/etc/nginx/readiness.sh:ro networks: [edge, backend] depends_on: api: condition: service_healthy healthcheck: test: [CMD-SHELL, 'wget -q -O /dev/null http://127.0.0.1:8080/health/ready'] interval: 2s timeout: 2s retries: 3 cpus: 0.5 mem_limit: 128m stop_grace_period: 10s postgres: image: postgres:17.4-bookworm environment: POSTGRES_DB: ${POSTGRES_DB:-messenger} POSTGRES_USER: ${POSTGRES_USER:-messenger} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env} volumes: - postgres_data:/var/lib/postgresql/data networks: [backend] healthcheck: test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"] interval: 2s timeout: 2s retries: 30 cpus: 1.0 mem_limit: 512m redis: image: redis:7.4.2-bookworm command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always", "--maxmemory", "128mb", "--maxmemory-policy", "noeviction"] volumes: - redis_data:/data networks: [backend] healthcheck: test: ["CMD", "redis-cli", "ping"] interval: 2s timeout: 2s retries: 30 cpus: 0.5 mem_limit: 256m networks: edge: backend: internal: true volumes: postgres_data: redis_data: