docs: 更新 AGENTS/README 平台架构说明与月度总结,运行日志视图支持已取消状态

This commit is contained in:
2026-10-31 17:55:25 +08:00
parent e1b4097573
commit b976b80d9d
201 changed files with 11049 additions and 7398 deletions
+113 -119
View File
@@ -1,8 +1,9 @@
# 桌面端发版 SOP(壳子 / 中心机 / 文件服务器)
# 桌面端发版 SOP(壳子 / 环境包 / 文件服务器 / 中心机)
> 对象:37du 桌面端三组件的发版流程。插件发版见 [插件发版规范](../插件/发版规范.md);
> 中心机前后端部署细节见 [控制面前后端部署SOP](../部署/控制面前后端部署SOP.md)。
> 版本源都在中心机控制面(`http://117.72.191.188:8800`)。
> 对象:执行机客户端 `desktop/electron-shell`、便携环境包、文件服务器 `desktop/fileserver`、中心机 `desktop/controlplane-next`。
> 版本源都在**内网中心机控制面**(`http://172.30.30.243:8800`)。发版命令一律显式 `--base http://172.30.30.243:8800`。
> 插件发版见 [插件发版规范](../插件/发版规范.md);中心机部署细节见 [服务端部署 SOP](../部署/服务端前后端部署SOP.md)。
> 最后更新:2026-10-31(旧 Python 底座 `desktop/webhost` 已从仓库移除,其 PyInstaller/Inno 流程归档在附录 A)。
---
@@ -10,160 +11,153 @@
| 组件 | 代码位置 | 交付形态 | 版本单点 | 更新机制 |
|---|---|---|---|---|
| **壳子**(执行机主程序) | `desktop/webhost/` | PyInstaller + Inno 安装包 | `desktop/webhost/tools/shell.version`(当前 1.1.8) | 执行机 `shell_updater.py` 检测 → 用户下载 → 点击重启静默升级 |
| 插件执行壳(runner) | `desktop/webhost/` | onefile exe,随安装包分发 | 随壳子 | 随壳子安装包 |
| **中心机控制面** | `desktop/controlplane/` | 源码部署(宝塔 gunicorn 8800 + 静态站 8090),**不打包 exe** | 无 | 改代码按部署 SOP |
| **文件服务器** | `desktop/fileserver/` | PyInstaller exe,内网部署 `172.30.35.135:8802` | 无 | `build.bat` 打包 + 开机自启 |
| **壳子**(执行机客户端) | `desktop/electron-shell/` | electron-builder NSIS 安装包 | `package.json` 的 `version`(打包时写入 exe 同级 `shell.version`) | 启动/每 30 分钟/手动检查 `/api/shell/version` → 下载 → 用户点"重启更新"静默安装 |
| **环境包**(便携 Python) | 由 `scripts/build-python-env.ps1` 产出 | `python-env-<ver>.zip` | `-EnvVersion` 参数 | 启动/每 30 分钟检查 `/api/file-sources/python-env`,自动下载切换,保留上一版 |
| **插件** | `plugins/XQ0001-0100/<XQ00xx 名称>/` | 插件 zip | 插件 `plugin.json` / `_pack.py` 版本 | 登录后按账号权限自下载(见插件发版规范) |
| **中心机控制面** | `desktop/controlplane-next/` | 源码部署(后端 Node + 前端静态站),不打包 | 无 | 按服务端部署 SOP |
| **文件服务器** | `desktop/fileserver/` | 源码部署 + venv | 无(`VERSION` 常量仅标识) | 改代码后重启进程 |
**版本源**:执行机 `shell_updater` 拉取 `/api/shell/version`,数据来自中心机
`desktop/controlplane/shell/version.json`(`file push` 时自动更新),返回 `version / url / sha256 / notes`;
`url` 直连内网文件服务器下载大包(无鉴权),为空则回退中心机 `/api/shell/pkg`(带 `X-API-Token`)。
**大文件分发链路**:`agent_cli file push` 把包上传到内网文件服务器 (`172.30.30.243:8802`) 并在控制面 `file_sources` 登记直链;
执行机优先用该直链下载(无鉴权、内网直连),`url` 为空时才回退控制面中转接口(带 `X-API-Token`)。
---
## 二、壳子发版流程(主要)
## 二、壳子发版(主要流程)
> 前置:改完 `desktop/webhost/` 后端或前端代码,本地验证通过。
### 1. 改版本号
### 1. 更新版本号(两处保持一致)
- `desktop/webhost/tools/shell.version` → 新版本(如 `1.2.0`)
- `desktop/webhost/tools/install.iss` 的 `MyAppVersion` → 同版本
* 只改 `desktop/electron-shell/package.json` 的 `version`(唯一真源)。
* `scripts/after-pack.js` 会在打包时把该版本写成 exe 同级 `shell.version`——执行机自更新靠它判定本地版本,**缺失即视为源码模式、不参与自更新**。
### 2. 前端构建
### 2. 前端构建(前端有改动时)
```powershell
cd d:\work\code\37duAutomation\desktop\webhost\frontend
npm run build # 产物 dist/ 由 37du-host.spec 的 datas 打进主程序
cd d:\work\code\37duAutomation\desktop\electron-shell
npm run copy-renderer # frontend/ → renderer/dist(前端有改动时必须执行)
```
### 3. PyInstaller 打包(在 `desktop/` 下执行)
### 3. 打包
```powershell
.\.venv\Scripts\python.exe -m PyInstaller webhost\tools\37du-host.spec --distpath webhost\dist-exe --workpath webhost\build-exe --noconfirm
.\.venv\Scripts\python.exe -m PyInstaller webhost\tools\37du-host-runner.spec --distpath webhost\dist-exe --workpath webhost\build-exe --noconfirm
npm install # 首次或依赖变更后
npm run pack # electron-builder --win nsis
# 产物:dist-app\setup-37du-shell-<version>.exe
```
- `37du-host.spec`:onedir 目录模式(主程序,含前端 dist / WebView2 / 插件依赖)
- `37du-host-runner.spec`:onefile 单文件(插件执行子进程壳,与主程序 exe 同级)
- `37du-host-console.spec` 是调试版,**不入安装包,可跳过**
### 4. Inno 打安装包
打包配置要点(`package.json` → `build`):`appId=com.37du.automation`、`productName=37du 自动化工作台`、`asar=true`、
`extraResources` 把 `.env.packaged` 映射为 `resources/.env`、`artifactName=setup-37du-shell-${version}.exe`、
NSIS `oneClick=false`(可选安装目录、perMachine=false)、`afterPack=scripts/after-pack.js`。
### 4. 上传 + 登记
```powershell
"C:\Program Files\Inno Setup 7\ISCC.exe" webhost\tools\install.iss
# 上传到文件服务器并登记为壳子版本(category=shell)
d:\work\code\37duAutomation\.venv\Scripts\python.exe tools\agent_cli.py `
--admin puddy --password 123456 --base http://172.30.30.243:8800 `
file push <安装包绝对路径> --category shell --version <新版本> --notes "更新说明"
```
产物:`desktop/webhost/installer/setup-37du-host-<版本>.exe`
### 5. 上传安装包到内网文件服务器
安装包需放到文件服务器 `172.30.35.135:8802` 的可直连目录(`version` 接口的 `url` 指向它)。
> 上传到文件服务器的具体方式以现场运维为准(SMB 共享 / 管理后台上传),确保执行机能免鉴权直连下载。
* 上传后控制面 `file_sources(category='shell')` 记录 `version/url/sha256/notes`,`/api/shell/version` 即返回该版本。
* **不要用旧的 `shell-release` 子命令**(旧 FastAPI 时代接口,新链路统一 `file push`)。
* 执行机本地缓存的安装包名固定为 `setup-37du-host-<version>.exe`(与打包产物名 `setup-37du-shell-<version>.exe` 不同,仅影响缓存命名,不影响下载与安装)。
### 6. 登记发版(`desktop/` 下 agent CLI)
```powershell
.\.venv\Scripts\python.exe -m controlplane.tools.agent_cli `
--admin puddy --password 123456 `
file push <安装包绝对路径> --category shell --version <新版本> [--notes "更新说明"]
```
作用:登记到中心机 `file_sources(shell)` + 更新 `controlplane/shell/version.json`(`version/url/sha256/notes`)。
> **不要用旧的 `shell-release` 子命令**。
### 5. 验证
### 7. 验证
```bash
curl -s http://127.0.0.1:8800/api/shell/version # 返回新版本 + sha256 + 可下载 url
curl -s -H "X-API-Token: <CONTROLPLANE_TOKEN>" http://172.30.30.243:8800/api/shell/version
# 期望:available/version/url/sha256/notes 均为新版本,url 指向文件服务器直链
```
执行机端「检查更新」应提示新版本 → 下载(进度)→ sha256 校验 → 点击「重启更新」。
### 8. 执行机端升级链路(shell_updater.py 约定)
检查(只比对版本,秒级,每 30 分钟/启动/手动)→ 用户点击下载(流式到 `%LOCALAPPDATA%\37duAutomation\shell\`,`.part` 临时文件 + sha256 校验)→ 校验失败放弃 →
点击「重启更新」→ `/VERYSILENT /SUPPRESSMSGBOXES /NORESTART` 静默覆盖安装 → Inno `CloseApplications` 收尾 → `[Run]` 自动重启新版本。
执行机侧:状态栏「检查更新」提示新版本 → 下载(进度 + sha256 校验)→「重启更新」→ NSIS `/S` 静默安装 → 自动重启新版本。
### 注意
- 版本升级**不覆盖**执行机已有 `.env`(`install.iss` 用 `onlyifdoesntexist`);
- 插件**不随安装包分发**,执行机登录后按账号权限自下载(`plugin_sync.py`);
- 安装包较大(数百 MB),下载走内网文件服务器直链,避免走中心机中转。
### 6. 升级链路约定
* 检查:只比对版本号(秒级),启动一次 + 每 30 分钟 + 手动触发。
* 下载:流式写入 `%LOCALAPPDATA%\37duAutomation\shell\`,`.part` 临时文件,`sha256` 不符删除重下。
* 安装:NSIS 静默 `/S`(不认 Inno 的 `/VERYSILENT`),由 `wscript` 执行 VBS + `mshta` 等待窗口完成收尾后重启。
* 升级**不覆盖**现场数据:`.env`、`plugin_configs/`、`plugins/`、`python-env/` 全部在 `%LOCALAPPDATA%\37duAutomation`,不在安装目录内。
---
## 三、中心机控制面发版
## 三、环境包发版(独立版本化)
改 `desktop/controlplane/` 前后端代码后,按 **[控制面前后端部署SOP](../部署/控制面前后端部署SOP.md)** 执行:
- **前端**:`desktop/controlplane/frontend` 下 `npm run build` → `Compress-Archive` 打包 zip → 上传 → 静态站 8090 解压替换(用 `mv` 备份,勿 `rm -rf`);
- **后端**:逐个上传改动文件 → 覆盖到 `/www/wwwroot/controlplane/controlplane/` → 重启 gunicorn 项目 `controlplane`(8800);
- 控制面为源码部署,不产 exe。
```powershell
cd d:\work\code\37duAutomation\desktop\electron-shell
powershell -NoProfile -ExecutionPolicy Bypass -File scripts\build-python-env.ps1 -EnvVersion 1.1.4
# 产物:dist-env\python-env-1.1.4.zip + .sha256,并本地安装到 python-env\1.1.4\ 供联调
```
```powershell
d:\work\code\37duAutomation\.venv\Scripts\python.exe tools\agent_cli.py `
--admin puddy --password 123456 --base http://172.30.30.243:8800 `
file push <python-env-1.1.4.zip 绝对路径> --category python-env --version 1.1.4 --notes "依赖变更说明"
```
* 内容:embeddable Python 3.11.9 + 全部插件依赖(与 `.venv` 钉死版本)+ `webhost` 运行时子集。
* 客户端:检查 `/api/file-sources/python-env` → 下载 → `sha256` → 解压 `python-env/<ver>/` → 切 `current.json` → 保留上一版,本地 API `GET /api/env/status`、`POST /api/env/sync|rollback`。
* 环境包与壳子**互不依赖升级**;环境包升级后建议对已授权插件做一次回归(依赖可能变化)。
* 插件 `minRuntimeVersion` 校验的是**壳版本**(`shell.version`),不是环境包版本。
验证:
```bash
curl -s -H "X-API-Token: <CONTROLPLANE_TOKEN>" http://172.30.30.243:8800/api/file-sources/python-env
```
---
## 四、文件服务器发版
改 `desktop/fileserver/` 后:
```powershell
# 本地校验(cwd = desktop/)
cd d:\work\code\37duAutomation\desktop
.\tools\..\.venv\Scripts\python.exe # 或直接跑
fileserver\tools\build.bat
```
`build.bat`:PyInstaller 打 `37du-fileserver.spec` → 组装 `desktop/fileserver/dist-exe/fileserver/`(exe + `.env`)。
部署到 `172.30.35.135`:
1. 拷贝 `dist-exe/fileserver/` 整目录到内网机器;
2. 调整 `.env` 的 `FILESERVER_BASE_URL` / `TOKEN`;
3. 运行 `install_autostart.bat` 注册开机自启,`start_server.bat` 启动。
> 壳子安装包也存放在该服务器上,供执行机 `version.url` 直连下载。
---
## 五、Node/Electron 壳与环境包发版(新方向,2026-09 起)
> 对象:`desktop/electron-shell/`(Node/Electron 客户端,替代旧 Python webhost 底座)。
> 发版链路与旧壳一致(版本单点 = 中心机 file_sources),另加**环境包**(便携 Python 运行时)独立版本化。
### 6.1 壳子(Electron 安装包)
```powershell
cd desktop/electron-shell
npm install
npm run copy-renderer # 前端有改动时:frontend/ → renderer/dist
npm run pack # electron-builder → dist-app/setup-37du-shell-<version>.exe
```
- 产物:`desktop/electron-shell/dist-app/setup-37du-shell-<version>.exe`(NSIS,静默升级兼容)
- 壳子版本文件 = exe 同级 `shell.version`(发版登记时生成),与 `package.json` version 一致
- **插件根/环境包默认目录 = exe 同级**:`plugins/` 与 `python-env/`(随安装包可含预置,或首启自下载)
### 6.2 环境包(便携 Python 运行时,独立版本化)
```powershell
powershell -NoProfile -ExecutionPolicy Bypass -File scripts\build-python-env.ps1 [-EnvVersion 1.0.0]
# 产物:dist-env/python-env-<version>.zip + .sha256(默认同时本地安装到 electron-shell/python-env/ 供联调)
```
- 内容:embeddable 3.11.9 + 全部插件依赖(与 .venv 钉死版本)+ webhost 运行时子集
- **客户端启动/每 30 分钟自动检查** `/api/file-sources/python-env`,有新版自动下载安装并保留上一版回滚,无需改壳
### 6.3 上传 + 登记(desktop/ 下 agent CLI)
```powershell
# 1. 安装包与环境包 zip 上传到内网文件服务器(可直连下载的目录)
# 2. 登记壳子(category=shell)
.\.venv\Scripts\python.exe -m controlplane.tools.agent_cli `
--admin puddy --password 123456 `
file push <安装包绝对路径> --category shell --version <新版本> [--notes "..."]
# 3. 登记环境包(category=python-env,客户端零改动消费)
.\.venv\Scripts\python.exe -m controlplane.tools.agent_cli `
--admin puddy --password 123456 `
file push <python-env-<ver>.zip 绝对路径> --category python-env --version <ver> [--notes "..."]
..\.venv\Scripts\python.exe -m fileserver.main
```
### 6.4 验证
服务器侧(`172.30.30.243`):
```bash
curl -s -H "X-API-Token: <CONTROLPLANE_TOKEN>" http://127.0.0.1:8800/api/shell/version # 壳子版本
curl -s -H "X-API-Token: <CONTROLPLANE_TOKEN>" http://127.0.0.1:8800/api/file-sources/python-env # 环境包
# 代码更新到 /opt/37du/fileserver 后
systemctl restart 37du-fileserver
systemctl status 37du-fileserver --no-pager
journalctl -u 37du-fileserver -n 100 --no-pager
```
客户端侧:`GET /api/env/status`(本地 API,需登录会话)应显示 `installed/version/cloud_version`;
新装机器首启后环境包自动下载,插件执行走 `job_guard.py`(Job Object 内存上限 + 整树托管)。
### 6.5 注意
- 环境包与壳子**相互独立升级**;环境包升级后建议对全部已授权插件做一次回归(依赖可能变化)。
- 插件 `minRuntimeVersion` 校验的是**壳子运行时版本**(`shell.version`),不是环境包版本。
- 旧 Python 底座(webhost)发版流程见 §二,回退窗口期内保留。
* `.env` 关键项:`FILESERVER_PORT=8802`、`FILESERVER_BASE_URL=http://172.30.30.243:8802`、`FILESERVER_TOKEN`(与控制面调用方一致)、`CONTROLPLANE_URL` + `CONTROLPLANE_TOKEN`(心跳)。
* 管理台 `http://172.30.30.243:8899/` 可核对在线状态、文件列表、下载次数。
* 心跳 60s 一次;控制面 180s 未收到即标记离线告警。
---
## 六、检查清单(发版后自检)
## 五、中心机控制面发版
- [ ] `shell.version` 与 `install.iss.MyAppVersion` 版本号一致,且高于中心机已登记版本
- [ ] `37du-host.spec`(onedir)与 `37du-host-runner.spec`(onefile)均打包成功
- [ ] 安装包已生成:`desktop/webhost/installer/setup-37du-host-<版本>.exe`
- [ ] 安装包已上传到内网文件服务器,且执行机可直连下载
- [ ] `file push --category shell` 成功,`/api/shell/version` 返回新版本与正确 sha256
- [ ] 执行机「检查更新」提示新版本,下载 → 校验 → 重启升级链路正常
- [ ] 升级后执行机 `.env`、插件配置未被覆盖(`onlyifdoesntexist` 生效)
改 `desktop/controlplane-next/` 后端或前端代码后,按 [服务端部署 SOP](../部署/服务端前后端部署SOP.md):
* 后端:`server` 下 `npm run build` → 上传 → `systemctl restart 37du-controlplane-next.service`;
* 前端:`frontend` 下 `pnpm build` → 上传 `dist/` 到 `/opt/37du/controlplane-web` → 按需 `nginx -s reload`;
* 数据库变更:手工执行 `migrations/*.sql` 后重启后端;
* 控制面为源码部署,不产出 exe。
---
## 六、发版后检查清单
- [ ] `package.json.version` 已提升,且高于中心机已登记版本
- [ ] `npm run copy-renderer` 已执行(前端有改动时)
- [ ] `dist-app/setup-37du-shell-<版本>.exe` 生成,能本地安装启动
- [ ] `file push --category shell` 成功,`/api/shell/version` 返回新版本 + 正确 sha256 + 可下载 url
- [ ] 环境包(如有变更)`file push --category python-env` 成功,`/api/file-sources/python-env` 可查
- [ ] 执行机「检查更新」→ 下载 → 校验 → 重启升级链路正常
- [ ] 升级后 `.env`、插件配置、插件目录、环境包未被覆盖
- [ ] 新版本跑通至少一个已授权插件(含一次取消/超时场景)
---
## 附录 A:旧 Python 底座(`desktop/webhost`,已移除,仅历史参考)
> 该目录已从仓库删除,以下流程不再执行,仅用于理解旧安装包与文档中的历史命名(`setup-37du-host-<版本>.exe`)。
* 打包:PyInstaller `webhost/tools/37du-host.spec`(onedir 主程序)+ `37du-host-runner.spec`(onefile 插件执行壳)→ `webhost/dist-exe/`。
* 安装包:Inno Setup `webhost/tools/install.iss`(`MyAppVersion` 与 `tools/shell.version` 双处一致)→ `webhost/installer/setup-37du-host-<版本>.exe`。
* 升级:`shell_updater.py` 检测 `/api/shell/version` → `/VERYSILENT /SUPPRESSMSGBOXES /NORESTART` → Inno `[Run]` 重启。
* 数据目录与本代一致:`%LOCALAPPDATA%\37duAutomation`(换壳不破坏数据)。