本项目是一个基于 CNB (Cloud Native Build) 平台的 ComfyUI 基础设施项目,提供高性能的 AI 图像生成环境,支持 CUDA 加速和完整的依赖管理。
┌─────────────────────────────────────────────────────────────┐ │ CNB 平台 │ ├─────────────────────────────────────────────────────────────┤ │ ┌─────────────────┐ ┌─────────────────┐ │ │ │ Infra Layer │ → │ App Layer │ │ │ │ (基础环境) │ │ (应用层) │ │ │ └─────────────────┘ └─────────────────┘ │ └─────────────────────────────────────────────────────────────┘
# 构建 Infra 基础镜像
./test_build_infra.sh
# 构建 App 应用镜像
./test_build_app.sh
# 锁定依赖版本
./compile_app_deps.sh
workspace/ ├── .cnb.yml # CNB 配置文件 ├── app/ # 应用层配置 │ ├── Dockerfile # 应用层 Dockerfile │ ├── requirements.in # 依赖定义文件 │ └── requirements.txt # 锁定的依赖版本 ├── infra/ # 基础设施层 │ ├── Dockerfile # 基础层 Dockerfile │ ├── requirements.txt # 基础依赖 │ └── requirements.system.txt # 系统依赖 ├── scripts/ # 工具脚本 │ ├── cnbcache.sh # CNB缓存镜像管理脚本 │ ├── comfyui-start.sh # ComfyUI 启动脚本 │ ├── storage-setup.sh # 存储初始化脚本 │ └── docker_subtree_commands.sh # Git subtree 管理 ├── comfyui_data/ # ComfyUI 数据目录 │ ├── models/ # 模型文件 │ ├── input/ # 输入文件 │ ├── output/ # 输出文件 │ ├── custom_nodes/ # 自定义节点 │ └── user/ # 用户配置 └── build-logs/ # 构建日志 (已 gitignore)
torch, torchaudio, torchvision (cu128)transformers, diffusers, acceleratexformers, bitsandbytessafetensors, onnxruntime-gpuopencv-contrib-python-headlessPillow, albumentationsscikit-image, imageiofastapi, gradiouvicorn, aiohttpcomfyui-frontend-packagecomfyui-workflow-templatescomfyui-embedded-docs项目采用多阶段 Docker 构建的缓存策略:
docker.cnb.cool/ainewstonb/comfyui-infra/comfyui-app:build-cache# 更新依赖定义
vim app/requirements.in
# 重新锁定版本
./compile_app_deps.sh
# 检查变更
git diff app/requirements.txt
# 测试基础层
./test_build_infra.sh
# 测试应用层
./test_build_app.sh
# 查看构建日志
ls -la build-logs/
# 分析构建效果
grep "Using cache" build-logs/*.log
/workspace/comfyui_data/models - 避免重复下载/workspace/comfyui_data/input - 持久化存储/workspace/comfyui_data/output - 防止数据丢失/workspace/comfyui_data/user - 保持设置一致性/workspace/comfyui_data/custom_nodes - 插件持久化运行 scripts/storage-setup.sh 自动创建符号链接映射。
# 现象:缓存未命中
# 原因:首次构建或缓存已清理
# 设置更长超时时间
export UV_HTTP_TIMEOUT=120
export UV_REQUEST_TIMEOUT=120
# 重新锁定依赖
./compile_app_deps.sh
# 检查冲突详情
uv pip check
# 构建日志位置
build-logs/manual-build-*.log
# 查找缓存使用情况
grep "Using cache" build-logs/*.log
# 查找错误信息
grep -i "error\|failed" build-logs/*.log
配置 .cnb.yml
$:
tag_push:
- stages:
- name: docker build
volumes: [...]
触发构建
git push origin main
监控构建
# 启动开发环境
docker run -it --gpus all \
-v $(pwd):/workspace \
comfyui-app:test
# 运行 ComfyUI
cd /workspace
./scripts/comfyui-start.sh
requirements.in 管理依赖# 1. 创建功能分支
git checkout -b feature/new-feature
# 2. 开发和测试
./test_build_app.sh
# 3. 提交变更
git add .
git commit -m "feat: add new feature"
# 4. 推送分支
git push origin feature/new-feature
最后更新: 2025-11-27