Files
chatballs/compose.yaml
T

265 lines
11 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Канонический production-манифест CustoCRM (ADR-HUB-0028).
# Один Compose для: box-установки клиента, hub.edevs.tech, staging, smoke.
# Локальная разработка — через override compose.dev.yaml; этот файл не содержит
# dev source mounts, dev-команд и host-портов (кроме public 80/443 у gateway).
#
# Image references берутся из release.env (immutable digest refs, см. ADR §release).
# В dev они не задаются — срабатывают безопасные defaults, а override подменяет
# image на build.
#
# Запуск production/box:
# docker compose --env-file .env --env-file release.env up -d
# Запуск разработки:
# docker compose -f compose.yaml -f compose.dev.yaml --env-file .env.example --env-file .env up
services:
postgres:
image: ${CUSTOCRM_POSTGRES_IMAGE:-pgvector/pgvector:pg16}
restart: unless-stopped
environment:
POSTGRES_DB: ${POSTGRES_DB:?POSTGRES_DB is required}
POSTGRES_USER: ${POSTGRES_USER:?POSTGRES_USER is required}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}
POSTGRES_APP_USER: ${POSTGRES_APP_USER:?POSTGRES_APP_USER is required}
POSTGRES_APP_PASSWORD: ${POSTGRES_APP_PASSWORD:?POSTGRES_APP_PASSWORD is required}
POSTGRES_PLATFORM_USER: ${POSTGRES_PLATFORM_USER:?POSTGRES_PLATFORM_USER is required}
POSTGRES_PLATFORM_PASSWORD: ${POSTGRES_PLATFORM_PASSWORD:?POSTGRES_PLATFORM_PASSWORD is required}
POSTGRES_MIGRATION_USER: ${POSTGRES_MIGRATION_USER:?POSTGRES_MIGRATION_USER is required}
POSTGRES_MIGRATION_PASSWORD: ${POSTGRES_MIGRATION_PASSWORD:?POSTGRES_MIGRATION_PASSWORD is required}
volumes:
- ${CUSTOCRM_INSTANCE_DIR:-.}/data/postgres:/var/lib/postgresql/data
- ./deploy/postgres/init-runtime-roles.sh:/docker-entrypoint-initdb.d/20-custocrm-runtime-roles.sh:ro
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 10s
timeout: 5s
retries: 10
redis:
image: ${CUSTOCRM_REDIS_IMAGE:-redis:7-alpine}
restart: unless-stopped
command: ["redis-server", "--appendonly", "yes"]
volumes:
- ${CUSTOCRM_INSTANCE_DIR:-.}/data/redis:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 5s
retries: 10
start_period: 20s
# One-shot init: миграции (ADR-HUB-0028 §one-shot init). Не запускает Edevs seed,
# не создаёт OWNER, не трогает demo — это отдельные ответственности (этап 2).
# collectstatic испечён в backend-образ, здесь не вызывается.
init:
image: ${CUSTOCRM_BACKEND_IMAGE:-custocrm-backend:dev}
env_file:
- ${CUSTOCRM_INSTANCE_DIR:-.}/.env
command: ["python", "manage.py", "migrate", "--noinput"]
environment:
HUB_DB_ROLE: migration
restart: "no"
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
backend-app:
image: ${CUSTOCRM_BACKEND_IMAGE:-custocrm-backend:dev}
restart: unless-stopped
env_file:
- ${CUSTOCRM_INSTANCE_DIR:-.}/.env
command: >
sh -c "gunicorn hub_backend.asgi_app:application
--worker-class uvicorn.workers.UvicornWorker
--bind 0.0.0.0:8000
--workers $${HUB_GUNICORN_WORKERS:-3}
--timeout $${HUB_GUNICORN_TIMEOUT:-60}"
environment:
HUB_DB_ROLE: app
volumes:
# Legacy source media retained for the separately approved copy/hash
# migration. Production writes use the required S3 backend in C04.
- ${CUSTOCRM_INSTANCE_DIR:-.}/data/media:/app/apps/backend/media
depends_on:
init:
condition: service_completed_successfully
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test:
[
"CMD",
"python",
"-c",
"import os, urllib.request; req = urllib.request.Request('http://127.0.0.1:8000/api/v1/health/live/', headers={'Host': os.environ.get('CUSTOCRM_APP_HEALTHCHECK_HOST', 'app.localhost'), 'X-Forwarded-Proto': 'https'}); urllib.request.urlopen(req, timeout=3)",
]
interval: 10s
timeout: 5s
retries: 10
start_period: 20s
backend-platform:
image: ${CUSTOCRM_BACKEND_IMAGE:-custocrm-backend:dev}
restart: unless-stopped
env_file:
- ${CUSTOCRM_INSTANCE_DIR:-.}/.env
command: >
sh -c "gunicorn hub_backend.asgi_platform:application
--worker-class uvicorn.workers.UvicornWorker
--bind 0.0.0.0:8000
--workers $${HUB_GUNICORN_WORKERS:-3}
--timeout $${HUB_GUNICORN_TIMEOUT:-60}"
environment:
HUB_DB_ROLE: platform
depends_on:
init:
condition: service_completed_successfully
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test:
[
"CMD",
"python",
"-c",
"import os, urllib.request; req = urllib.request.Request('http://127.0.0.1:8000/api/v1/health/live/', headers={'Host': os.environ.get('CUSTOCRM_PLATFORM_HEALTHCHECK_HOST', 'platform.localhost'), 'X-Forwarded-Proto': 'https'}); urllib.request.urlopen(req, timeout=3)",
]
interval: 10s
timeout: 5s
retries: 10
start_period: 20s
# Django admin не подключён к gateway. Единственный host bind — loopback;
# удалённый доступ допускается только через SSH tunnel (ADR-HUB-0031).
backend-admin:
image: ${CUSTOCRM_BACKEND_IMAGE:-custocrm-backend:dev}
restart: unless-stopped
env_file:
- ${CUSTOCRM_INSTANCE_DIR:-.}/.env
command: >
sh -c "gunicorn hub_backend.asgi_admin:application
--worker-class uvicorn.workers.UvicornWorker
--bind 0.0.0.0:8000
--workers $${HUB_GUNICORN_WORKERS:-2}
--timeout $${HUB_GUNICORN_TIMEOUT:-60}"
# Break-glass technical surface only: schema credentials are never used by
# public app/platform runtimes and this service remains loopback-only.
environment:
HUB_DB_ROLE: migration
ports:
- "127.0.0.1:${CUSTOCRM_ADMIN_PORT:-18001}:8000"
depends_on:
init:
condition: service_completed_successfully
postgres:
condition: service_healthy
redis:
condition: service_healthy
worker:
image: ${CUSTOCRM_BACKEND_IMAGE:-custocrm-backend:dev}
restart: unless-stopped
env_file:
- ${CUSTOCRM_INSTANCE_DIR:-.}/.env
command: ["python", "manage.py", "run_worker"]
environment:
HUB_DB_ROLE: app
volumes:
- ${CUSTOCRM_INSTANCE_DIR:-.}/data/media:/app/apps/backend/media
depends_on:
backend-app:
condition: service_healthy
# Frontend: один nginx-образ со static-сборкой internal-ui и web-chat,
# внутренняя маршрутизация (/api/, /ws/, /chat-widget.js,
# /chat/, /calls/) — в deploy/nginx/frontend.production.conf. Не публикует
# host-порт: public boundary — gateway (Caddy).
frontend:
image: ${CUSTOCRM_FRONTEND_IMAGE:-custocrm-frontend:dev}
restart: unless-stopped
depends_on:
backend-app:
condition: service_healthy
# Gateway: единственный HTTP/HTTPS public boundary (ADR-HUB-0028 §gateway).
# Caddy: TLS termination, ACME, HTTP->HTTPS redirect, WebSocket upgrade (native).
# Маршрутизация публичных путей делегируется frontend (internal). Coturn не
# проксируется через Caddy — отдельная network boundary (profile calls).
gateway:
image: ${CUSTOCRM_GATEWAY_IMAGE:-caddy:2.8.4}
restart: unless-stopped
environment:
CUSTOCRM_APP_DOMAIN: ${CUSTOCRM_APP_DOMAIN:?CUSTOCRM_APP_DOMAIN is required}
CUSTOCRM_PLATFORM_DOMAIN: ${CUSTOCRM_PLATFORM_DOMAIN:?CUSTOCRM_PLATFORM_DOMAIN is required}
CUSTOCRM_ACME_EMAIL: ${CUSTOCRM_ACME_EMAIL:?CUSTOCRM_ACME_EMAIL is required}
ports:
- "${CUSTOCRM_WEB_LISTENING_IP:-0.0.0.0}:80:80"
- "${CUSTOCRM_WEB_LISTENING_IP:-0.0.0.0}:443:443"
volumes:
- ${CUSTOCRM_RELEASE_DIR:-.}/Caddyfile:/etc/caddy/Caddyfile:ro
- ${CUSTOCRM_INSTANCE_DIR:-.}/data/caddy:/data
- ${CUSTOCRM_INSTANCE_DIR:-.}/data/caddy-config:/config
depends_on:
frontend:
condition: service_started
backend-app:
condition: service_healthy
backend-platform:
condition: service_healthy
# Coturn — медиа-relay для TURN fallback (SPEC-HUB-0013 §11).
# Опциональный profile `calls` (ADR-HUB-0028): включается через COMPOSE_PROFILES=calls.
# Host networking: relay использует широкий UDP-диапазон и реальный внешний IP,
# публикуется напрямую и не проходит через HTTP reverse proxy. credentials
# выдаёт backend по общему HUB_CALL_TURN_SECRET (static-auth-secret).
coturn:
profiles: ["calls"]
image: ${CUSTOCRM_COTURN_IMAGE:-coturn/coturn:4.6}
restart: unless-stopped
network_mode: host
command:
- -n
- --log-file=stdout
- --no-cli
- --fingerprint
- --use-auth-secret
- --static-auth-secret=${HUB_CALL_TURN_SECRET}
- --realm=${HUB_CALL_TURN_REALM}
# Весь TURN живёт на выделенном публичном IP (отдельный порт/NIC), Caddy — на
# основном IP. Это освобождает 443 под TURN-over-TLS без конфликта с web.
- --listening-ip=${HUB_TURN_LISTENING_IP}
- --relay-ip=${HUB_TURN_EXTERNAL_IP}
- --external-ip=${HUB_TURN_EXTERNAL_IP}
- --listening-port=${HUB_TURN_LISTENING_PORT:-3478}
# TURN-over-TLS на 443: проходит через VPN/строгие сети, где UDP и 3478 режут.
- --tls-listening-port=${HUB_TURN_TLS_PORT:-443}
- --cert=/etc/coturn/certs/fullchain.pem
- --pkey=/etc/coturn/certs/privkey.pem
- --min-port=${HUB_TURN_MIN_PORT:-49160}
- --max-port=${HUB_TURN_MAX_PORT:-49200}
# Запрет анонимного и внутрисетевого relay (SPEC §11: без пересечения с хостом).
- --no-multicast-peers
- --no-tcp-relay
- --denied-peer-ip=10.0.0.0-10.255.255.255
- --denied-peer-ip=172.16.0.0-172.31.255.255
- --denied-peer-ip=192.168.0.0-192.168.255.255
- --no-tlsv1
- --no-tlsv1_1
volumes:
# LE-сертификат TURN-хоста (turns:), скопированный под uid coturn (nobody)
# renewal deploy-hook'ом. См. docs по развёртыванию TURN-over-TLS.
- ${CUSTOCRM_INSTANCE_DIR:-.}/data/coturn-certs:/etc/coturn/certs:ro
healthcheck:
# Allocation smoke: STUN binding к собственному listener на выделенном IP.
test: ["CMD", "turnutils_stunclient", "-p", "${HUB_TURN_LISTENING_PORT:-3478}", "${HUB_TURN_LISTENING_IP}"]
interval: 30s
timeout: 5s
retries: 5
start_period: 15s