deerflow-code/offline-backend-20260512/README.md
2026-09-07 18:24:55 +08:00

71 lines
2.8 KiB
Markdown
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.

# DeerFlow 离线后端部署补充
本目录提供与 `start_backend.sh` 配套的 wheelhouse。启动脚本会在容器启动时检查可选运行时依赖,并在缺包时仅从本地 wheelhouse 安装。
## 文件
- `offline-runtime-requirements.txt`:固定版本的完整依赖闭包。
- `prepare_wheelhouse.sh`:联网机器下载 Linux/Python 3.12 wheel,并验证传递依赖完整性。
- `start_backend.sh`:Docker 启动脚本,包含 `croniter`、`hindsight-client`、aiomysql 兼容组和 Redis 客户端的缺包补装逻辑。
- `wheelhouse/`:26 个 wheel 和 `SHA256SUMS`,需要随发布目录一起复制。
## 联网机器准备
默认目标是后端镜像使用的 CPython 3.12、Linux x86_64:
```bash
cd offline-backend-20260512
bash prepare_wheelhouse.sh
```
直接依赖为:
- `croniter==6.2.2`
- `hindsight-client==0.6.2`
- `redis==5.2.1`
- `aiomysql==0.3.2`
- `SQLAlchemy==2.0.51`
上述依赖在 Python 3.12/Linux x86_64 下的 21 个传递依赖(包括 `PyMySQL==1.2.0` 和 `greenlet==3.2.5`)也已锁定在 `offline-runtime-requirements.txt`。
国内镜像示例:
```bash
PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple bash prepare_wheelhouse.sh
```
ARM64 镜像需要改目标平台:
```bash
TARGET_PLATFORM=manylinux2014_aarch64 bash prepare_wheelhouse.sh
```
## 离线机器启动
保持原脚本要求的发布目录结构,包括 Docker 镜像 tar、`.env`、`config.yaml`、`extensions_config.json`、`skill_evolution.json`、`skills/`、`wheelhouse/`、`backend/uv.lock` 和 `backend/`。
可先校验 wheel:
```bash
cd offline-backend-20260512/wheelhouse
sha256sum -c SHA256SUMS
cd ..
```
然后启动:
```bash
bash start_backend.sh
docker logs -f deerflow-backend
```
脚本会先尝试导入依赖,仅在缺少模块或 SQLAlchemy 的 aiomysql `ping(reconnect)` 适配接口不兼容时从 `/app/wheelhouse` 安装。aiomysql 补装默认开启,并在一次命令中安装兼容组 `aiomysql==0.3.2 PyMySQL==1.2.0 SQLAlchemy==2.0.51`,避免旧版 SQLAlchemy 启动时出现 `ping() missing 1 required positional argument: reconnect`。可通过 `AIOMYSQL_INSTALL_DEPS=0` 禁用,或通过 `AIOMYSQL_PIP_PACKAGES` 覆盖整个兼容组。
MySQL 连接 URL 使用 aiomysql 驱动时应写为 `mysql+aiomysql://user:password@host:3306/database?charset=utf8mb4`。
## Redis 说明
`redis==5.2.1` 只是 Python 客户端,不包含 Redis 服务端。`config.yaml` 中 `concurrency.redis.enabled: false` 时无需部署 Redis;启用后必须另行准备 Redis 服务或离线 Redis Docker 镜像。
如果 Redis 运行在另一个容器,`redis://127.0.0.1:6379/0` 指向后端容器自身,不能直接使用。应将两个容器加入同一个 Docker network,并将 URL 改为类似 `redis://redis:6379/0`,同时为不同环境配置不同的 `namespace`。