refactor(auto-deploy): YAML config + post_deploy list + deploy failure mail
- New config/deploy-targets.yaml: centralized deploy target config - Rewrite auto-deploy in _handle_pr_closed to use YAML config - Add _send_deploy_failure_mail helper (reuses deploy_failure template) - Support post_deploy command list (not just pm2 restart) - Docs-only changes skip post_deploy - Add pyyaml to pyproject.toml dependencies - Update design doc §23 with new architecture
This commit is contained in:
@@ -141,21 +141,35 @@ async def _handle_pull_request(payload: Dict[str, Any]) -> None:
|
||||
**触发**:`_handle_pr_closed` 合并事件处理完成后
|
||||
|
||||
**逻辑**:
|
||||
1. 仓库白名单检查(仅 `sanguo/sanguo_moziplus_v2`)
|
||||
2. `git pull origin main`(开发目录 `~/.openclaw/sanguo_projects/sanguo_moziplus_v2/`)
|
||||
3. `rsync` 同步到安装目录(排除 `.git`/`node_modules`/`__pycache__`)
|
||||
4. 获取 PR 变更文件列表(复用 `_fetch_pr_files`)
|
||||
5. 判断是否需要重启:文件路径包含 `src/`、`templates/`、`frontend/` 或 `*.py` 后缀 → 重启
|
||||
6. 纯 `docs/` 变更 → 只 pull + rsync 不重启
|
||||
7. rsync 或 pm2 restart 失败 → 通知 `jiangwei-infra`
|
||||
8. 部署失败仅 log + Mail 通知,不影响合并通知
|
||||
1. 读取 `config/deploy-targets.yaml`,查找 `repo` 对应的部署目标
|
||||
2. 不在配置中 → 跳过(未来新项目加一条配置即可)
|
||||
3. `git pull origin main`(开发目录)
|
||||
4. `rsync` 同步到安装目录(排除项由配置指定)
|
||||
5. 判断是否需要执行 post_deploy:文件路径包含 `src/`、`templates/`、`frontend/` 或 `*.py` 后缀
|
||||
6. 纯 `docs/` 变更 → 只 pull + rsync,不执行 post_deploy
|
||||
7. 部署失败复用 `deploy_failure.md` 模板通知 `jiangwei-infra` + `pangtong-fujunshi`
|
||||
|
||||
**配置文件**:`config/deploy-targets.yaml`(集中管理所有仓库的部署目标)
|
||||
|
||||
```yaml
|
||||
targets:
|
||||
sanguo/sanguo_moziplus_v2:
|
||||
dev_dir: ~/.openclaw/sanguo_projects/sanguo_moziplus_v2
|
||||
install_dir: ~/.sanguo_projects/sanguo_moziplus_v2
|
||||
pm2_name: sanguo-moziplus-v2
|
||||
rsync_exclude: [.git/, node_modules/, __pycache__/, data/]
|
||||
health_check: http://localhost:8083/health
|
||||
post_deploy: [pm2 restart sanguo-moziplus-v2]
|
||||
```
|
||||
|
||||
**设计决策**:
|
||||
- **git pull 在开发目录**(有 `.git`),rsync 到安装目录:安装目录无 `.git`,直接 git pull 必然失败
|
||||
- **全异步**:所有子进程调用使用 `asyncio.create_subprocess_exec`,不阻塞 event loop
|
||||
- **仓库白名单**:只对 `sanguo/sanguo_moziplus_v2` 触发自动部署,其他仓库忽略
|
||||
- **部署失败通知**:rsync 或 pm2 restart 失败时发 Mail 给 `jiangwei-infra`(S1)
|
||||
- 不做优雅等待(sentinel file 方案):daemon 正在执行任务时重启,已 spawn 的子进程独立运行不受影响,最坏情况是当前 tick 中断、下一轮 PM2 拉起后继续
|
||||
- **集中式 YAML 配置**(姜维建议):部署是平台级能力,非仓库级。一个文件管所有仓库,新增项目零代码改动
|
||||
- **YAML 而非 JSON**:支持注释,方便临时禁用某个仓库或排除项
|
||||
- **post_deploy 列表**:支持任意 shell 命令,不只是 pm2 restart。未来可扩展(如 pip install -e .)
|
||||
- **health_check 字段**:预留,后续可用于部署后健康检查
|
||||
- **失败通知复用**:CD 失败和 CI 失败用同一套通知机制(deploy_failure.md 模板 + _send_mail)
|
||||
- git pull 在开发目录(有 `.git`),rsync 到安装目录
|
||||
- 全异步调用(asyncio.create_subprocess_exec)
|
||||
|
||||
### 不做的事
|
||||
|
||||
|
||||
Reference in New Issue
Block a user