name: mtusi-messenger-lab5 services: db: image: postgres:16.4-alpine restart: unless-stopped environment: POSTGRES_DB: messenger POSTGRES_USER: messenger POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password secrets: [postgres_password] volumes: [postgres_data:/var/lib/postgresql/data] networks: [backend] healthcheck: test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"] interval: 3s timeout: 3s retries: 20 start_period: 5s deploy: resources: limits: {cpus: "1.00", memory: 1G} redis: image: redis:7.4.1-alpine restart: unless-stopped command: - sh - -ec - exec redis-server --dir /data --appendonly yes --appendfsync everysec --save 60 1 --requirepass "$$(cat /run/secrets/redis_password)" secrets: [redis_password] volumes: [redis_data:/data] networks: [backend] healthcheck: test: ["CMD-SHELL", "REDISCLI_AUTH=\"$$(cat /run/secrets/redis_password)\" redis-cli ping | grep -q PONG"] interval: 3s timeout: 3s retries: 20 start_period: 5s deploy: resources: limits: {cpus: "0.25", memory: 256M} broker: image: redis:7.4.1-alpine restart: unless-stopped command: - sh - -ec - exec redis-server --dir /data --appendonly yes --appendfsync everysec --save 60 1 --requirepass "$$(cat /run/secrets/broker_password)" secrets: [broker_password] volumes: [broker_data:/data] networks: [backend] healthcheck: test: ["CMD-SHELL", "REDISCLI_AUTH=\"$$(cat /run/secrets/broker_password)\" redis-cli ping | grep -q PONG"] interval: 3s timeout: 3s retries: 20 start_period: 5s deploy: resources: limits: {cpus: "0.25", memory: 256M} s3-init: image: alpine:3.24.1 user: "0:0" command: ["sh", "-ec", "chown -R 10001:10001 /data && chmod 0750 /data"] volumes: [s3_data:/data] restart: "no" s3: image: rustfs/rustfs:1.0.5 restart: unless-stopped environment: RUSTFS_VOLUMES: /data RUSTFS_ADDRESS: 0.0.0.0:9000 RUSTFS_CONSOLE_ADDRESS: 0.0.0.0:9001 RUSTFS_CONSOLE_ENABLE: "false" RUSTFS_OBS_LOGGER_LEVEL: warn RUSTFS_CHECK_UPDATE: "false" RUSTFS_ACCESS_KEY_FILE: /run/secrets/s3_root_access_key_id RUSTFS_SECRET_KEY_FILE: /run/secrets/s3_root_secret_access_key secrets: [s3_root_access_key_id, s3_root_secret_access_key] volumes: [s3_data:/data] networks: [backend] depends_on: s3-init: condition: service_completed_successfully healthcheck: test: ["CMD-SHELL", "curl -fsS http://127.0.0.1:9000/health/ready >/dev/null"] interval: 3s timeout: 2s retries: 20 start_period: 10s deploy: resources: limits: {cpus: "1.00", memory: 1G} migrate: image: mtusi-messenger-lab5-api:local build: context: . dockerfile: Dockerfile args: BUILD_REVISION: "${BUILD_REVISION:-local}" command: ["python", "-m", "src.app.migrate"] environment: DATABASE_URL_FILE: /run/secrets/database_url secrets: [database_url] networks: [backend] depends_on: db: condition: service_healthy restart: "no" deploy: resources: limits: {cpus: "0.25", memory: 256M} s3-bootstrap: image: mtusi-messenger-lab5-api:local build: context: . dockerfile: Dockerfile args: BUILD_REVISION: "${BUILD_REVISION:-local}" command: ["python", "-m", "src.app.s3_bootstrap"] environment: S3_ENDPOINT: http://s3:9000 S3_REGION: us-east-1 S3_BUCKET: messenger-attachments S3_ROOT_ACCESS_KEY_FILE: /run/secrets/s3_root_access_key_id S3_ROOT_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_root_secret_access_key S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key secrets: [s3_root_access_key_id, s3_root_secret_access_key, s3_access_key_id, s3_secret_access_key] networks: [backend] depends_on: s3: condition: service_healthy restart: "no" deploy: resources: limits: {cpus: "0.25", memory: 256M} api: image: mtusi-messenger-lab5-api:local build: context: . dockerfile: Dockerfile args: BUILD_REVISION: "${BUILD_REVISION:-local}" restart: unless-stopped stop_grace_period: 8s environment: APP_HOST: 0.0.0.0 APP_PORT: 8080 SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600} DATABASE_URL_FILE: /run/secrets/database_url CACHE_URL_FILE: /run/secrets/cache_url S3_ENDPOINT: http://s3:9000 S3_REGION: us-east-1 S3_BUCKET: messenger-attachments S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760} MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000} JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5} JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60} JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-180} secrets: [database_url, cache_url, s3_access_key_id, s3_secret_access_key] networks: [backend, edge] depends_on: db: condition: service_healthy redis: condition: service_healthy s3: condition: service_healthy s3-bootstrap: condition: service_completed_successfully migrate: condition: service_completed_successfully healthcheck: test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready',timeout=2)"] interval: 3s timeout: 2s retries: 3 start_period: 10s tmpfs: ["/tmp:size=64m,noexec,nosuid"] deploy: resources: limits: {cpus: "0.50", memory: 512M} dispatcher: image: mtusi-messenger-lab5-api:local build: context: . dockerfile: Dockerfile args: BUILD_REVISION: "${BUILD_REVISION:-local}" command: ["python", "-m", "src.app.dispatcher"] restart: unless-stopped stop_grace_period: 10s environment: DATABASE_URL_FILE: /run/secrets/database_url BROKER_URL_FILE: /run/secrets/broker_url BROKER_STREAM: ${BROKER_STREAM:-messenger:attachment-jobs:v1} JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5} JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-180} JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60} secrets: [database_url, broker_url] networks: [backend] depends_on: db: condition: service_healthy broker: condition: service_healthy migrate: condition: service_completed_successfully healthcheck: test: ["CMD", "python", "-c", "from pathlib import Path; import sys; sys.exit(0 if b'src.app.dispatcher' in Path('/proc/1/cmdline').read_bytes() else 1)"] interval: 5s timeout: 2s retries: 3 start_period: 5s deploy: resources: limits: {cpus: "0.25", memory: 256M} worker: image: mtusi-messenger-lab5-api:local build: context: . dockerfile: Dockerfile args: BUILD_REVISION: "${BUILD_REVISION:-local}" command: ["python", "-m", "src.app.worker"] restart: unless-stopped stop_grace_period: 10s environment: DATABASE_URL_FILE: /run/secrets/database_url BROKER_URL_FILE: /run/secrets/broker_url BROKER_STREAM: ${BROKER_STREAM:-messenger:attachment-jobs:v1} S3_ENDPOINT: http://s3:9000 S3_REGION: us-east-1 S3_BUCKET: messenger-attachments S3_ACCESS_KEY_ID_FILE: /run/secrets/s3_access_key_id S3_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_secret_access_key MAX_UPLOAD_BYTES: ${MAX_UPLOAD_BYTES:-10485760} MAX_IMAGE_PIXELS: ${MAX_IMAGE_PIXELS:-40000000} WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-1} JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5} JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-60} JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-180} secrets: [database_url, broker_url, s3_access_key_id, s3_secret_access_key] networks: [backend] depends_on: db: condition: service_healthy broker: condition: service_healthy s3: condition: service_healthy s3-bootstrap: condition: service_completed_successfully migrate: condition: service_completed_successfully tmpfs: ["/tmp:size=64m,noexec,nosuid"] healthcheck: test: ["CMD", "python", "-c", "from pathlib import Path; import sys; sys.exit(0 if b'src.app.worker' in Path('/proc/1/cmdline').read_bytes() else 1)"] interval: 5s timeout: 2s retries: 3 start_period: 5s deploy: resources: limits: {cpus: "0.75", memory: 768M} lb: image: nginx:1.28.0-alpine restart: unless-stopped ports: ["127.0.0.1:${APP_PORT:-8080}:8080"] volumes: [./infra/nginx.conf:/etc/nginx/conf.d/default.conf:ro] networks: [edge] depends_on: api: condition: service_healthy healthcheck: test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8080/health/ready"] interval: 3s timeout: 2s retries: 5 start_period: 5s deploy: resources: limits: {cpus: "0.25", memory: 128M} s3-maintenance: image: mtusi-messenger-lab5-api:local build: context: . dockerfile: Dockerfile args: BUILD_REVISION: "${BUILD_REVISION:-local}" profiles: [maintenance] command: ["python", "-m", "src.app.reconcile_s3_orphans"] environment: DATABASE_URL_FILE: /run/secrets/database_url S3_ENDPOINT: http://s3:9000 S3_REGION: us-east-1 S3_BUCKET: messenger-attachments S3_ROOT_ACCESS_KEY_FILE: /run/secrets/s3_root_access_key_id S3_ROOT_SECRET_ACCESS_KEY_FILE: /run/secrets/s3_root_secret_access_key ORPHAN_GRACE_SECONDS: ${ORPHAN_GRACE_SECONDS:-86400} STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-86400} secrets: [database_url, s3_root_access_key_id, s3_root_secret_access_key] networks: [backend] depends_on: db: condition: service_healthy s3: condition: service_healthy migrate: condition: service_completed_successfully restart: "no" secrets: postgres_password: file: ./secrets/postgres_password redis_password: file: ./secrets/redis_password s3_root_access_key_id: file: ./secrets/s3_root_access_key_id s3_root_secret_access_key: file: ./secrets/s3_root_secret_access_key s3_access_key_id: file: ./secrets/s3_access_key_id s3_secret_access_key: file: ./secrets/s3_secret_access_key database_url: file: ./secrets/database_url cache_url: file: ./secrets/cache_url broker_url: file: ./secrets/broker_url broker_password: file: ./secrets/broker_password volumes: postgres_data: redis_data: broker_data: s3_data: networks: backend: internal: true edge: