services: migrate: build: . command: ["python", "server.py"] environment: RUN_MIGRATIONS_ONLY: "1" DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}@postgres:5432/${POSTGRES_DB:-messenger} depends_on: postgres: { condition: service_healthy } restart: "no" api: build: . restart: unless-stopped environment: APP_HOST: 0.0.0.0 APP_PORT: 8080 SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} CURSOR_SECRET: ${CURSOR_SECRET:?Set CURSOR_SECRET in .env} DATABASE_URL: postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env}@postgres:5432/${POSTGRES_DB:-messenger} CACHE_URL: redis://valkey:6379/0 DB_POOL_MAX: ${DB_POOL_MAX:-10} DB_POOL_MIN: ${DB_POOL_MIN:-1} S3_ENDPOINT: http://rustfs:9000 S3_REGION: us-east-1 S3_BUCKET: ${S3_BUCKET:-messenger-attachments} S3_ACCESS_KEY_ID: ${S3_API_ACCESS_KEY:?Set S3_API_ACCESS_KEY in .env} S3_SECRET_ACCESS_KEY: ${S3_API_SECRET_KEY:?Set S3_API_SECRET_KEY in .env} MAX_UPLOAD_BYTES: 10485760 MAX_IMAGE_PIXELS: 40000000 UPLOAD_CONCURRENCY: ${UPLOAD_CONCURRENCY:-2} depends_on: migrate: { condition: service_completed_successfully } valkey: { condition: service_healthy } bucket-bootstrap: { condition: service_completed_successfully } cpus: ${API_CPUS:-1.0} mem_limit: ${API_MEMORY:-512m} stop_grace_period: 10s healthcheck: test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2)"] interval: 2s timeout: 3s retries: 2 start_period: 10s postgres: image: postgres:16.4-bookworm restart: unless-stopped environment: POSTGRES_USER: ${POSTGRES_USER:-messenger} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in .env} POSTGRES_DB: ${POSTGRES_DB:-messenger} volumes: ["postgres_data:/var/lib/postgresql/data"] cpus: 2.0 mem_limit: 1g healthcheck: test: ["CMD-SHELL", "pg_isready -U \"$$POSTGRES_USER\" -d \"$$POSTGRES_DB\""] interval: 3s timeout: 3s retries: 20 valkey: image: valkey/valkey:8.0.1-alpine restart: unless-stopped command: ["valkey-server", "--appendonly", "yes", "--appendfsync", "everysec"] volumes: ["valkey_data:/data"] cpus: 0.25 mem_limit: 128m healthcheck: test: ["CMD", "valkey-cli", "ping"] interval: 3s timeout: 3s retries: 10 rustfs: image: rustfs/rustfs:1.0.4 restart: unless-stopped command: ["--address", ":9000", "--console-address", ":9001", "/data"] environment: RUSTFS_ACCESS_KEY: ${RUSTFS_ROOT_ACCESS_KEY:?Set RUSTFS_ROOT_ACCESS_KEY in .env} RUSTFS_SECRET_KEY: ${RUSTFS_ROOT_SECRET_KEY:?Set RUSTFS_ROOT_SECRET_KEY in .env} RUSTFS_ADDRESS: :9000 RUSTFS_CONSOLE_ADDRESS: :9001 RUSTFS_CONSOLE_ENABLE: "true" volumes: ["rustfs_data:/data"] expose: ["9000"] cpus: 1.0 mem_limit: 512m bucket-bootstrap: image: rustfs/rc:v0.1.37 entrypoint: ["/bin/sh", "/bootstrap/bootstrap.sh"] environment: RUSTFS_ROOT_ACCESS_KEY: ${RUSTFS_ROOT_ACCESS_KEY:?Set RUSTFS_ROOT_ACCESS_KEY in .env} RUSTFS_ROOT_SECRET_KEY: ${RUSTFS_ROOT_SECRET_KEY:?Set RUSTFS_ROOT_SECRET_KEY in .env} S3_BUCKET: ${S3_BUCKET:-messenger-attachments} S3_API_ACCESS_KEY: ${S3_API_ACCESS_KEY:?Set S3_API_ACCESS_KEY in .env} S3_API_SECRET_KEY: ${S3_API_SECRET_KEY:?Set S3_API_SECRET_KEY in .env} volumes: - ./infra/rustfs-bootstrap.sh:/bootstrap/bootstrap.sh:ro - ./infra/rustfs-api-policy.json:/bootstrap/policy.json:ro depends_on: rustfs: { condition: service_started } restart: "no" haproxy: image: haproxy:3.0.8-alpine restart: unless-stopped ports: ["127.0.0.1:${APP_PORT:-8080}:8080"] volumes: ["./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro"] depends_on: [api] cpus: ${LB_CPUS:-0.25} mem_limit: 128m healthcheck: test: ["CMD", "haproxy", "-c", "-f", "/usr/local/etc/haproxy/haproxy.cfg"] interval: 10s timeout: 3s retries: 3 volumes: postgres_data: valkey_data: rustfs_data: