x-logging: &logging driver: json-file options: max-size: "10m" max-file: "3" x-app: &app build: . image: ${APP_IMAGE:-mtusi-messenger:lab6} 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:lab6}-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:lab6}-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: "" OTEL_ENABLED: ${OTEL_ENABLED:-true} OTEL_SERVICE_NAME: messenger-api OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318 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:lab6}-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:lab6}-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} OTEL_ENABLED: ${OTEL_ENABLED:-true} OTEL_EXPORTER_OTLP_ENDPOINT: http://otel-collector:4318 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:lab6}-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 otel-collector: image: otel/opentelemetry-collector-contrib:0.123.0 command: ["--config=/etc/otelcol/config.yaml"] mem_limit: 256m cpus: 0.5 volumes: - ./infra/observability/collector.yaml:/etc/otelcol/config.yaml:ro ports: - "127.0.0.1:${COLLECTOR_METRICS_PORT:-8889}:8888" prometheus: image: prom/prometheus:v3.2.1 mem_limit: 512m cpus: 0.5 command: ["--config.file=/etc/prometheus/prometheus.yaml", "--storage.tsdb.retention.time=7d"] volumes: - ./infra/observability/prometheus.yaml:/etc/prometheus/prometheus.yaml:ro - ./infra/observability/alerts.yaml:/etc/prometheus/alerts.yaml:ro - prometheus_data:/prometheus ports: ["127.0.0.1:${PROMETHEUS_PORT:-9090}:9090"] loki: image: grafana/loki:3.4.2 mem_limit: 384m cpus: 0.5 command: ["-config.file=/etc/loki/config.yaml"] volumes: - ./infra/observability/loki.yaml:/etc/loki/config.yaml:ro - loki_data:/loki ports: ["127.0.0.1:${LOKI_PORT:-3100}:3100"] tempo: image: grafana/tempo:2.7.2 user: "0:0" mem_limit: 384m cpus: 0.5 command: ["-config.file=/etc/tempo/config.yaml"] volumes: - ./infra/observability/tempo.yaml:/etc/tempo/config.yaml:ro - tempo_data:/var/tempo ports: ["127.0.0.1:${TEMPO_PORT:-3200}:3200"] grafana: image: grafana/grafana:11.6.0 mem_limit: 384m cpus: 0.5 environment: GF_AUTH_ANONYMOUS_ENABLED: "true" GF_AUTH_ANONYMOUS_ORG_ROLE: Viewer GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:?Set GRAFANA_ADMIN_PASSWORD in .env} GF_USERS_ALLOW_SIGN_UP: "false" GF_ANALYTICS_REPORTING_ENABLED: "false" GF_ANALYTICS_CHECK_FOR_UPDATES: "false" GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH: /var/lib/grafana/dashboards/messenger.json volumes: - grafana_data:/var/lib/grafana - ./infra/observability/grafana/provisioning:/etc/grafana/provisioning:ro - ./infra/observability/grafana/dashboards:/var/lib/grafana/dashboards:ro ports: ["127.0.0.1:${GRAFANA_PORT:-3000}:3000"] 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: prometheus_data: loki_data: tempo_data: grafana_data: