nex_animation/docker-compose.yml

98 lines
5.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# =============================================================================
# Nex Animation Studio · 部署编排(单容器整站:后端 + 前端产物 + SQLite + 进程内调度)
#
# 日常命令:
# docker compose up -d --build 首次部署(构建 + 后台启动)
# docker compose logs -f app 看日志(首启会打印「导入部署数据包」那一行)
# docker compose ps 状态(healthy 才算起来)
# docker compose restart app 改了 .env 之后重启生效
# docker compose down 停止并删除容器,数据留在 ./data
# 打开 http://localhost:8000 默认账号见 BOOTSTRAP_USERNAME / BOOTSTRAP_PASSWORD
#
# 为什么只有一个服务:库用 SQLite、任务用 TASK_EXECUTOR=inline(进程内线程池 +
# app/services/daemon.py 的派发守护线程),前端产物由后端一并托管,
# 所以不需要 nginx 容器、不需要 Redis、不需要独立 worker/beat。
# 少三个组件就少三类故障面:没有连不上的 db、没有排队没人消费的 broker、
# 没有「api 起来了 worker 没起来所以任务永远 pending」。
# 需要多机 / 多 GPU 扩容时再叠一层(Postgres + Redis + Celery worker + beat):
# docker compose -f docker-compose.yml -f docker-compose.scale.yml up -d --build
#
# 数据分三处 bind mount(都相对本文件,换镜像不动数据):
# ./data SQLite 库 + media 出片产物 ← 唯一会被写坏的目录,值得单独备份
# ./scripts/seed 模型配置 + 加密主密钥 + 管理员 ← gitignored 的机密,所以不进镜像层
# ./models whisper 权重等(可选)
# 容器首启由 scripts/docker-entrypoint.sh 拿 seed 目录把库灌好(AUTO_SEED 控制)。
#
# 配置来源:同目录 .env(compose 会替变量插值读它,并整份注入容器)。
# 下面 environment 里点名的键是例外——容器里的路径和宿主机不是一回事,必须覆盖。
# 需要 Docker Compose ≥ v2.24(env_file 的 required: false 写法)。
# =============================================================================
name: nex-animation
services:
app:
build:
context: .
args:
# 基础镜像与 pip/npm 源都可以在 .env 里覆盖:直连 docker.io / npmjs 很慢时先探好再构建
BASE_IMAGE: "${BASE_IMAGE:-python:3.12-slim}"
NODE_IMAGE: "${NODE_IMAGE:-node:22-alpine}"
PIP_INDEX_URL: "${PIP_INDEX_URL:-https://pypi.tuna.tsinghua.edu.cn/simple}"
NPM_REGISTRY: "${NPM_REGISTRY:-https://registry.npmmirror.com}"
image: nex-animation:latest
container_name: nex-animation
restart: unless-stopped
env_file:
- path: .env
required: false # 空机器上先起来再配模型,别让缺 .env 变成起不来
environment:
# ---- 容器内路径:宿主 .env 里写的是 ./media、./nex_animation.db,直接透传会漂 ----
DATABASE_URL: "${APP_DATABASE_URL:-sqlite:////app/data/nex_animation.db}"
MEDIA_ROOT: "${APP_MEDIA_ROOT:-/app/data/media}"
# ---- 整站形态的两把开关:后端托管前端 + 进程内执行后端,都必须在容器里成立 ----
SERVE_FRONTEND: "on"
TASK_EXECUTOR: "inline"
INLINE_WORKERS: "${INLINE_WORKERS:-2}"
# ---- 账号:库里没用户时首启播种这个管理员,登录后请立刻改口令 ----
AUTH_ENABLED: "${AUTH_ENABLED:-true}"
BOOTSTRAP_USERNAME: "${BOOTSTRAP_USERNAME:-admin}"
BOOTSTRAP_PASSWORD: "${BOOTSTRAP_PASSWORD:-admin1234}"
AUTO_SEED: "${AUTO_SEED:-only-missing}"
TZ: "${TZ:-Asia/Shanghai}"
# ComfyUI 常跑在宿主机或另一台 GPU 机上;指宿主机就写 http://host.docker.internal:9200
COMFYUI_BASE_URL: "${COMFYUI_BASE_URL:-}"
ports:
# 对外只有这一个端口;容器内固定 8000(与 EXPOSE / HEALTHCHECK 对齐)
- "${HOST_PORT:-8000}:8000"
volumes:
- ./data:/app/data
- ./scripts/seed:/app/scripts/seed:ro
- ./models:/app/models:ro
extra_hosts:
# Linux 上没有内建的 host.docker.internal,靠 host-gateway 指回宿主机
# (自建 ComfyUI 装在宿主机时要用)。macOS/Windows 的 Docker Desktop 本来就认这个名字。
- "host.docker.internal:host-gateway"
# 自建 ComfyUI(可选):docker compose --profile comfy up -d 起一份容器实例。
# 已有外部 GPU 机(例如 http://10.100.53.199:9200)时不用开它,
# .env 里把 COMFYUI_BASE_URL 指过去就行;装在宿主机上的话用 http://host.docker.internal:9200。
comfyui:
profiles: ["comfy"]
image: comfyanonymous/comfyui:latest
ports: ["9200:8188"]
volumes:
- comfy_models:/root/comfy-ui/models
- comfy_input:/root/comfy-ui/user/default
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
restart: unless-stopped
volumes:
comfy_models:
comfy_input: