Files
2026-11-17 17:53:23 +03:00

299 lines
9.4 KiB
YAML

x-logging: &logging
driver: json-file
options:
max-size: "10m"
max-file: "3"
x-app: &app
build: .
image: ${APP_IMAGE:-mtusi-messenger:lab5}
env_file: ${ENV_FILE:-.env}
logging: *logging
services:
minio:
build: ./infra/minio
image: ${MINIO_IMAGE:-mtusi-minio:RELEASE.2025-10-15T17-29-55Z}
logging: *logging
mem_limit: 512m
cpus: 1.0
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-messenger}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-local-messenger-s3-password}
MINIO_BROWSER: "off"
MINIO_API_STALE_UPLOADS_EXPIRY: "24h"
MINIO_API_STALE_UPLOADS_CLEANUP_INTERVAL: "1h"
volumes:
- minio_data:/data
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:9000/minio/health/live"]
interval: 2s
timeout: 3s
retries: 60
start_period: 10s
s3-bootstrap:
<<: *app
image: ${APP_IMAGE:-mtusi-messenger:lab5}-s3-bootstrap
command: ["python", "-m", "src.core.storage_bootstrap"]
environment:
MINIO_ROOT_USER: ${MINIO_ROOT_USER:-messenger}
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD:-local-messenger-s3-password}
S3_WORKER_ACCESS_KEY_ID: ${S3_WORKER_ACCESS_KEY_ID:-messenger-worker}
S3_WORKER_SECRET_ACCESS_KEY: ${S3_WORKER_SECRET_ACCESS_KEY:-local-messenger-worker-password}
S3_RECONCILE_ACCESS_KEY_ID: ${S3_RECONCILE_ACCESS_KEY_ID:-messenger-reconciler}
S3_RECONCILE_SECRET_ACCESS_KEY: ${S3_RECONCILE_SECRET_ACCESS_KEY:-local-messenger-reconciler-password}
DATABASE_URL: postgresql://unused:unused@postgres/unused
REDIS_URL: redis://redis:6379/0
S3_ENDPOINT: http://minio:9000
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-messenger-api}
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-local-messenger-api-password}
depends_on:
minio:
condition: service_healthy
healthcheck:
disable: true
postgres:
logging: *logging
image: postgres:16.6-bookworm
cpus: ${POSTGRES_CPUS:-1.0}
mem_limit: 512m
environment:
POSTGRES_DB: ${POSTGRES_DB:-messenger}
POSTGRES_USER: ${POSTGRES_USER:-messenger}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Задай POSTGRES_PASSWORD в .env}
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
interval: 2s
timeout: 3s
retries: 30
redis:
logging: *logging
image: redis:7.4.2-bookworm
cpus: 0.25
mem_limit: 128m
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always", "--maxmemory", "64mb", "--maxmemory-policy", "noeviction"]
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 2s
timeout: 3s
retries: 30
migration:
<<: *app
image: ${APP_IMAGE:-mtusi-messenger:lab5}-migration
command: ["alembic", "upgrade", "head"]
cpus: 0.5
mem_limit: 256m
environment:
REDIS_URL: &redis_url redis://redis:6379/0
DATABASE_URL: &database_url postgresql://${POSTGRES_USER:-messenger}:${POSTGRES_PASSWORD:?Задай POSTGRES_PASSWORD в .env}@postgres:5432/${POSTGRES_DB:-messenger}
depends_on:
postgres:
condition: service_healthy
healthcheck:
disable: true
api:
<<: *app
cpus: ${API_CPUS:-0.5}
mem_limit: ${API_MEMORY:-512m}
stop_grace_period: 15s
deploy:
replicas: ${API_REPLICAS:-2}
read_only: true
tmpfs:
- /tmp:rw,noexec,nosuid,size=64m
cap_drop: [ALL]
security_opt: ["no-new-privileges:true"]
environment:
S3_ENDPOINT: http://minio:9000
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_ACCESS_KEY_ID: ${S3_ACCESS_KEY_ID:-messenger-api}
S3_SECRET_ACCESS_KEY: ${S3_SECRET_ACCESS_KEY:-local-messenger-api-password}
S3_WORKER_ACCESS_KEY_ID: ""
S3_WORKER_SECRET_ACCESS_KEY: ""
# Do not inherit privileged S3 credentials from env_file into API containers.
MINIO_ROOT_USER: ""
MINIO_ROOT_PASSWORD: ""
S3_RECONCILE_ACCESS_KEY_ID: ""
S3_RECONCILE_SECRET_ACCESS_KEY: ""
UPLOAD_CONCURRENCY: ${UPLOAD_CONCURRENCY:-1}
APP_HOST: 0.0.0.0
APP_PORT: 8080
DATABASE_URL: *database_url
REDIS_URL: *redis_url
SESSION_TTL_SECONDS: ${SESSION_TTL_SECONDS:-3600}
LOG_LEVEL: ${LOG_LEVEL:-INFO}
APP_WORKERS: 1
DATABASE_POOL_SIZE: ${DATABASE_POOL_SIZE:-10}
DATABASE_POOL_TIMEOUT_SECONDS: 2
DATABASE_CONNECT_TIMEOUT_SECONDS: 1
DATABASE_COMMAND_TIMEOUT_SECONDS: 3
DATABASE_STATEMENT_TIMEOUT_MS: 2500
SHUTDOWN_TIMEOUT_SECONDS: 10
HTTP_REQUEST_TIMEOUT_SECONDS: ${HTTP_REQUEST_TIMEOUT_SECONDS:-5}
expose: ["8080"]
depends_on:
s3-bootstrap:
condition: service_completed_successfully
migration:
condition: service_completed_successfully
redis:
condition: service_healthy
healthcheck:
interval: 2s
timeout: 3s
retries: 30
start_period: 10s
reconciler:
<<: *app
image: ${APP_IMAGE:-mtusi-messenger:lab5}-reconciler
command: ["python", "-m", "src.maintenance.reconcile", "--apply", "--interval", "300"]
mem_limit: 256m
cpus: 0.5
read_only: true
cap_drop: [ALL]
security_opt: ["no-new-privileges:true"]
environment:
DATABASE_URL: *database_url
REDIS_URL: *redis_url
S3_ENDPOINT: http://minio:9000
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_RECONCILE_ACCESS_KEY_ID: ${S3_RECONCILE_ACCESS_KEY_ID:-messenger-reconciler}
S3_RECONCILE_SECRET_ACCESS_KEY: ${S3_RECONCILE_SECRET_ACCESS_KEY:-local-messenger-reconciler-password}
RECONCILE_GRACE_SECONDS: ${RECONCILE_GRACE_SECONDS:-300}
MINIO_ROOT_USER: ""
MINIO_ROOT_PASSWORD: ""
S3_ACCESS_KEY_ID: ""
S3_SECRET_ACCESS_KEY: ""
depends_on:
migration:
condition: service_completed_successfully
s3-bootstrap:
condition: service_completed_successfully
healthcheck:
test: ["CMD", "python", "-c", "import os; os.kill(1, 0)"]
interval: 10s
timeout: 3s
retries: 3
start_period: 2s
broker:
image: redis:7.4.2-bookworm
logging: *logging
mem_limit: 256m
cpus: 0.25
command: ["redis-server", "--appendonly", "yes", "--appendfsync", "always", "--maxmemory", "192mb", "--maxmemory-policy", "noeviction"]
volumes:
- broker_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 2s
timeout: 3s
retries: 30
worker:
<<: *app
image: ${APP_IMAGE:-mtusi-messenger:lab5}-worker
command: ["python", "-m", "src.pipeline.worker"]
init: true
mem_limit: ${WORKER_MEMORY:-1g}
cpus: ${WORKER_CPUS:-1.0}
stop_grace_period: 45s
read_only: true
tmpfs: ["/tmp:rw,noexec,nosuid,size=128m"]
cap_drop: [ALL]
security_opt: ["no-new-privileges:true"]
environment: &pipeline_env
DATABASE_URL: *database_url
REDIS_URL: *redis_url
BROKER_URL: redis://broker:6379/0
S3_ENDPOINT: http://minio:9000
S3_BUCKET: ${S3_BUCKET:-messenger-attachments}
S3_WORKER_ACCESS_KEY_ID: ${S3_WORKER_ACCESS_KEY_ID:-messenger-worker}
S3_WORKER_SECRET_ACCESS_KEY: ${S3_WORKER_SECRET_ACCESS_KEY:-local-messenger-worker-password}
MINIO_ROOT_USER: ""
MINIO_ROOT_PASSWORD: ""
S3_RECONCILE_ACCESS_KEY_ID: ""
S3_RECONCILE_SECRET_ACCESS_KEY: ""
S3_ACCESS_KEY_ID: ""
S3_SECRET_ACCESS_KEY: ""
WORKER_CONCURRENCY: ${WORKER_CONCURRENCY:-1}
WORKER_MEMORY_MB: ${WORKER_MEMORY_MB:-768}
JOB_MAX_ATTEMPTS: ${JOB_MAX_ATTEMPTS:-5}
JOB_TIMEOUT_SECONDS: ${JOB_TIMEOUT_SECONDS:-30}
JOB_LEASE_SECONDS: ${JOB_LEASE_SECONDS:-120}
JOB_RETRY_BASE_SECONDS: ${JOB_RETRY_BASE_SECONDS:-2}
JOB_RETRY_CAP_SECONDS: ${JOB_RETRY_CAP_SECONDS:-60}
STAGING_RETENTION_SECONDS: ${STAGING_RETENTION_SECONDS:-604800}
PIPELINE_FAULT_INJECTION: ${PIPELINE_FAULT_INJECTION:-false}
depends_on:
migration:
condition: service_completed_successfully
s3-bootstrap:
condition: service_completed_successfully
broker:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "import os; os.kill(1, 0)"]
interval: 5s
timeout: 3s
retries: 3
dispatcher:
<<: *app
image: ${APP_IMAGE:-mtusi-messenger:lab5}-dispatcher
command: ["python", "-m", "src.pipeline.dispatcher"]
init: true
mem_limit: 256m
cpus: 0.25
read_only: true
cap_drop: [ALL]
security_opt: ["no-new-privileges:true"]
environment: *pipeline_env
depends_on:
migration:
condition: service_completed_successfully
s3-bootstrap:
condition: service_completed_successfully
broker:
condition: service_healthy
healthcheck:
test: ["CMD", "python", "-c", "import os; os.kill(1, 0)"]
interval: 5s
timeout: 3s
retries: 3
lb:
image: haproxy:3.0.12-alpine
logging: *logging
cpus: 0.5
mem_limit: 128m
read_only: true
tmpfs: ["/tmp:rw,noexec,nosuid,size=4m"]
security_opt: ["no-new-privileges:true"]
ports:
- "127.0.0.1:${APP_PORT:-8080}:8080"
volumes:
- ./infra/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on:
api:
condition: service_healthy
stop_signal: SIGUSR1
stop_grace_period: 15s
volumes:
redis_data:
postgres_data:
minio_data:
broker_data: