name: mtusi-lab3 x-api-env: &api-env APP_HOST: 0.0.0.0 APP_PORT: "8080" APP_ENV: ${APP_ENV:-lab} SESSION_STORE: ${SESSION_STORE:-valkey} SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} SESSION_CACHE_MAX_TTL_SECONDS: ${SESSION_CACHE_MAX_TTL_SECONDS:-60} IDEMPOTENCY_TTL_SECONDS: ${IDEMPOTENCY_TTL_SECONDS:-86400} SHUTDOWN_DRAIN_MS: ${SHUTDOWN_DRAIN_MS:-3000} DB_MAX_CONNS: ${DB_MAX_CONNS:-10} MESSAGE_WRITE_PATH: ${MESSAGE_WRITE_PATH:-oneshot} DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url services: postgres: image: postgres:17.2-alpine3.21 environment: POSTGRES_DB: messenger POSTGRES_USER: messenger POSTGRES_PASSWORD_FILE: /run/secrets/pg_password command: ["postgres", "-c", "max_connections=${PG_MAX_CONNECTIONS:-100}"] secrets: [pg_password] volumes: - pgdata:/var/lib/postgresql/data networks: [data] shm_size: 256mb healthcheck: test: ["CMD-SHELL", "pg_isready -U messenger -d messenger -h 127.0.0.1"] interval: 2s timeout: 3s retries: 30 deploy: resources: limits: {cpus: "${PG_CPUS:-2.0}", memory: "${PG_MEMORY:-1G}"} stop_grace_period: 30s restart: unless-stopped valkey: image: valkey/valkey:8.0.2-alpine3.21 command: ["valkey-server", "/usr/local/etc/valkey/valkey.conf"] volumes: - ./infra/valkey/valkey.conf:/usr/local/etc/valkey/valkey.conf:ro secrets: [valkey_auth] networks: [data] healthcheck: test: ["CMD-SHELL", "valkey-cli ping | grep -qE 'PONG|NOAUTH'"] interval: 2s timeout: 3s retries: 30 deploy: resources: limits: {cpus: "0.5", memory: 128M} restart: unless-stopped migrate: build: context: . args: APP_BUILD: ${APP_BUILD:-dev} image: mtusi-messenger:lab3 command: ["migrate"] environment: DATABASE_URL_FILE: /run/secrets/database_url secrets: [database_url] networks: [data] depends_on: postgres: condition: service_healthy deploy: resources: limits: {cpus: "0.5", memory: 128M} restart: "no" api: image: mtusi-messenger:lab3 pull_policy: never environment: *api-env secrets: [database_url, cache_url] networks: [app, data] depends_on: migrate: condition: service_completed_successfully postgres: condition: service_healthy valkey: condition: service_healthy healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/health/ready"] interval: 2s timeout: 2s start_period: 5s retries: 3 deploy: replicas: ${API_REPLICAS:-2} resources: limits: {cpus: "${API_CPUS:-1.0}", memory: "${API_MEMORY:-256M}"} stop_grace_period: 15s restart: unless-stopped lb: image: haproxy:3.0.5-alpine volumes: - ./infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro ports: - "127.0.0.1:${APP_PORT:-8080}:8080" - "[::1]:${APP_PORT:-8080}:8080" networks: [app] depends_on: api: condition: service_healthy healthcheck: test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8404/healthz"] interval: 2s timeout: 2s retries: 15 deploy: resources: limits: {cpus: "${LB_CPUS:-1.0}", memory: 128M} restart: unless-stopped networks: app: {} data: {} volumes: pgdata: {} secrets: pg_password: file: ./secrets/pg_password database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url valkey_auth: file: ./secrets/valkey_auth.conf