name: mtusi-lab3 x-api: &api build: context: . args: APP_REVISION: ${API_IMAGE_TAG:-local} image: mtusi-lab3-api:${API_IMAGE_TAG:-local} environment: &api-env APP_HOST: 0.0.0.0 APP_PORT: '8080' APP_ENV: lab3 CURSOR_SECRET_FILE: /run/secrets/cursor_secret DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} SESSION_STORE: redis SHUTDOWN_GRACE_SECONDS: '8' DB_POOL_MIN: '2' DB_POOL_MAX: '10' DB_CONNECT_TIMEOUT: '1' DB_STATEMENT_TIMEOUT: '4' secrets: [database_url, cache_url, cursor_secret] depends_on: migrate: condition: service_completed_successfully redis: condition: service_healthy networks: [backend] cpus: 0.50 mem_limit: 256m stop_grace_period: 9s healthcheck: test: [CMD, python, -c, "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=1)"] interval: 2s timeout: 2s retries: 2 start_period: 3s # Deliberately no auto-restart: failover hook must leave its target stopped. restart: 'no' services: postgres: image: postgres:15-alpine@sha256:54e0dd8e8cddcdbb9156c2486eed5a43eccb7214d7c6828097d41ce049fb3984 environment: POSTGRES_DB: messenger POSTGRES_USER: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] volumes: [pg_data:/var/lib/postgresql/data] networks: [backend] cpus: 1.0 mem_limit: 512m healthcheck: test: [CMD-SHELL, 'pg_isready -U messenger -d messenger'] interval: 2s timeout: 2s retries: 20 redis: image: redis:7-alpine@sha256:8da19c7399dca900c6822a1cf30f9d2285585e2c4b457ff4095b0f4500054d3f command: [redis-server, --appendonly, 'yes', --maxmemory, 96mb, --maxmemory-policy, allkeys-lru] volumes: [redis_data:/data] networks: [backend] cpus: 0.25 mem_limit: 128m healthcheck: test: [CMD, redis-cli, ping] interval: 2s timeout: 1s retries: 10 migrate: build: context: . args: APP_REVISION: ${API_IMAGE_TAG:-local} image: mtusi-lab3-api:${API_IMAGE_TAG:-local} command: [python, -m, messenger.migrate] environment: *api-env secrets: [database_url, cache_url, cursor_secret] depends_on: postgres: condition: service_healthy networks: [backend] cpus: 0.50 mem_limit: 256m restart: 'no' healthcheck: disable: true api-a: <<: *api api-b: <<: *api nginx: image: nginx:1.28.2-alpine@sha256:5b4900b042ccfa8b0a73df622c3a60f2322faeb2be800cbee5aa7b44d241649e entrypoint: [/bin/sh, -ec] command: - 'cp /etc/nginx/lab/upstreams.conf /etc/nginx/upstreams.conf; /bin/sh /etc/nginx/lab/healthwatch.sh & exec nginx -g "daemon off;"' volumes: - ./infra/nginx.conf:/etc/nginx/nginx.conf:ro - ./infra:/etc/nginx/lab:ro ports: ['127.0.0.1:${PUBLIC_PORT:-8080}:8080'] networks: [frontend, backend] depends_on: api-a: condition: service_healthy api-b: condition: service_healthy cpus: 0.50 mem_limit: 128m stop_grace_period: 10s healthcheck: test: [CMD-SHELL, 'kill -0 $$(cat /tmp/healthwatch.pid) && wget -T 1 -q -O /dev/null http://127.0.0.1:8080/health/ready'] interval: 2s timeout: 2s retries: 3 networks: frontend: backend: internal: true volumes: pg_data: redis_data: secrets: postgres_password: file: ./secrets/postgres_password database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url cursor_secret: file: ./secrets/cursor_secret