101 lines
4.1 KiB
YAML
101 lines
4.1 KiB
YAML
# =============================================================================
|
||
# 扩容层:Postgres + Redis + Celery worker/beat,叠在 docker-compose.yml 之上用
|
||
#
|
||
# docker compose -f docker-compose.yml -f docker-compose.scale.yml up -d --build
|
||
# (嫌长可以在 .env 里不管它,或者建一个 shell 别名;compose 不会自动读这份文件)
|
||
#
|
||
# 什么时候才需要它:一台机器跑不过来。多 GPU、多人同时出片、要把 worker 放到
|
||
# 别的机器上——那时候才值得为它多养一个 Postgres、一个 Redis 和两类会「起了但没消费」的进程。
|
||
# 单容器(TASK_EXECUTOR=inline + SQLite)在「单机 + 一两张 ComfyUI 卡」这个量级是够的:
|
||
# 出片本身是 ffmpeg 子进程,不受 Python GIL 拖累,INLINE_WORKERS 就是并发闸。
|
||
#
|
||
# 机制:compose 的 environment 是**按键合并、后面的文件赢**,所以叠加之后
|
||
# app 容器的 DATABASE_URL / TASK_EXECUTOR 被这里覆盖成 Postgres + celery,
|
||
# 页面依然由 app 这一个容器提供(SERVE_FRONTEND=on 没被动过),
|
||
# 重活交给 worker,周期派发从 app 内的守护线程交回 beat。
|
||
# 想彻底回到「前后端分离 + nginx」的老形态:frontend/Dockerfile 与 nginx.conf 还在。
|
||
# =============================================================================
|
||
services:
|
||
app:
|
||
environment:
|
||
DATABASE_URL: postgresql+psycopg://${POSTGRES_USER:-nex}:${POSTGRES_PASSWORD:-change_this_password}@db:5432/${POSTGRES_DB:-nexanimation}
|
||
REDIS_URL: redis://redis:6379/0
|
||
TASK_EXECUTOR: celery
|
||
depends_on:
|
||
db: { condition: service_healthy }
|
||
redis: { condition: service_healthy }
|
||
|
||
db:
|
||
image: postgres:17
|
||
environment:
|
||
POSTGRES_DB: ${POSTGRES_DB:-nexanimation}
|
||
POSTGRES_USER: ${POSTGRES_USER:-nex}
|
||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-change_this_password}
|
||
volumes: [postgres_data:/var/lib/postgresql/data]
|
||
healthcheck:
|
||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-nex} -d ${POSTGRES_DB:-nexanimation}"]
|
||
interval: 5s
|
||
timeout: 5s
|
||
retries: 20
|
||
restart: unless-stopped
|
||
|
||
redis:
|
||
image: redis:7-alpine
|
||
command: ["redis-server", "--appendonly", "yes"]
|
||
volumes: [redis_data:/data]
|
||
healthcheck:
|
||
test: ["CMD", "redis-cli", "ping"]
|
||
interval: 5s
|
||
timeout: 3s
|
||
retries: 20
|
||
restart: unless-stopped
|
||
|
||
worker:
|
||
image: nex-animation:latest
|
||
# 入口脚本只在第一个参数是 uvicorn 时灌数据集,celery 直接 exec 透传(见 docker-entrypoint.sh)
|
||
command: celery -A app.worker.celery_app worker -Q generate,audio,qc,compose,io,default --loglevel=INFO --concurrency=${CELERY_CONCURRENCY:-2}
|
||
env_file:
|
||
- path: .env
|
||
required: false # 任务的真正配置在这里:COMFYUI_BASE_URL、TTS_*、VIDEO_*
|
||
environment:
|
||
DATABASE_URL: postgresql+psycopg://${POSTGRES_USER:-nex}:${POSTGRES_PASSWORD:-change_this_password}@db:5432/${POSTGRES_DB:-nexanimation}
|
||
REDIS_URL: redis://redis:6379/0
|
||
MEDIA_ROOT: /app/data/media
|
||
TASK_EXECUTOR: celery
|
||
TZ: ${TZ:-Asia/Shanghai}
|
||
volumes:
|
||
# 必须和 app 挂同一个目录:worker 写出的媒体要能被 app 的 /media 路由读到
|
||
- ./data:/app/data
|
||
- ./models:/app/models:ro
|
||
extra_hosts:
|
||
- "host.docker.internal:host-gateway"
|
||
depends_on:
|
||
db: { condition: service_healthy }
|
||
redis: { condition: service_healthy }
|
||
restart: unless-stopped
|
||
|
||
beat:
|
||
image: nex-animation:latest
|
||
command: celery -A app.worker.celery_app beat --loglevel=INFO
|
||
env_file:
|
||
- path: .env
|
||
required: false
|
||
environment:
|
||
DATABASE_URL: postgresql+psycopg://${POSTGRES_USER:-nex}:${POSTGRES_PASSWORD:-change_this_password}@db:5432/${POSTGRES_DB:-nexanimation}
|
||
REDIS_URL: redis://redis:6379/0
|
||
MEDIA_ROOT: /app/data/media
|
||
TASK_EXECUTOR: celery
|
||
TZ: ${TZ:-Asia/Shanghai}
|
||
volumes:
|
||
- ./data:/app/data
|
||
extra_hosts:
|
||
- "host.docker.internal:host-gateway"
|
||
depends_on:
|
||
db: { condition: service_healthy }
|
||
redis: { condition: service_healthy }
|
||
restart: unless-stopped
|
||
|
||
volumes:
|
||
postgres_data:
|
||
redis_data:
|