Files
37duAutomation/docs/桌面端/桌面端发版SOP.md
T

9.5 KiB
Raw Blame History

桌面端发版 SOP(壳子 / 中心机 / 文件服务器)

对象:37du 桌面端三组件的发版流程。插件发版见 插件发版规范; 中心机前后端部署细节见 控制面前后端部署SOP。 版本源都在中心机控制面(http://117.72.191.188:8800)。


一、组件与版本源

组件 代码位置 交付形态 版本单点 更新机制
壳子(执行机主程序) 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 打包 + 开机自启

版本源:执行机 shell_updater 拉取 /api/shell/version,数据来自中心机 desktop/controlplane/shell/version.json(file push 时自动更新),返回 version / url / sha256 / notes; url 直连内网文件服务器下载大包(无鉴权),为空则回退中心机 /api/shell/pkg(带 X-API-Token)。


二、壳子发版流程(主要)

前置:改完 desktop/webhost/ 后端或前端代码,本地验证通过。

1. 更新版本号(两处保持一致)

  • desktop/webhost/tools/shell.version → 新版本(如 1.2.0)
  • desktop/webhost/tools/install.iss 的 MyAppVersion → 同版本

2. 前端构建(前端有改动时)

cd d:\work\code\37duAutomation\desktop\webhost\frontend
npm run build        # 产物 dist/ 由 37du-host.spec 的 datas 打进主程序

3. PyInstaller 打包(在 desktop/ 下执行)

.\.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
  • 37du-host.spec:onedir 目录模式(主程序,含前端 dist / WebView2 / 插件依赖)
  • 37du-host-runner.spec:onefile 单文件(插件执行子进程壳,与主程序 exe 同级)
  • 37du-host-console.spec 是调试版,不入安装包,可跳过

4. Inno 打安装包

"C:\Program Files\Inno Setup 7\ISCC.exe" webhost\tools\install.iss

产物:desktop/webhost/installer/setup-37du-host-<版本>.exe

5. 上传安装包到内网文件服务器

安装包需放到文件服务器 172.30.35.135:8802 的可直连目录(version 接口的 url 指向它)。

上传到文件服务器的具体方式以现场运维为准(SMB 共享 / 管理后台上传),确保执行机能免鉴权直连下载。

6. 登记发版(desktop/ 下 agent CLI)

.\.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 子命令。

7. 验证

curl -s http://127.0.0.1:8800/api/shell/version     # 返回新版本 + sha256 + 可下载 url

执行机端「检查更新」应提示新版本 → 下载(进度)→ sha256 校验 → 点击「重启更新」。

8. 执行机端升级链路(shell_updater.py 约定)

检查(只比对版本,秒级,每 30 分钟/启动/手动)→ 用户点击下载(流式到 %LOCALAPPDATA%\37duAutomation\shell\,.part 临时文件 + sha256 校验)→ 校验失败放弃 → 点击「重启更新」→ /VERYSILENT /SUPPRESSMSGBOXES /NORESTART 静默覆盖安装 → Inno CloseApplications 收尾 → [Run] 自动重启新版本。

注意

  • 版本升级不覆盖执行机已有 .env(install.iss 用 onlyifdoesntexist);
  • 插件不随安装包分发,执行机登录后按账号权限自下载(plugin_sync.py);
  • 安装包较大(数百 MB),下载走内网文件服务器直链,避免走中心机中转。

三、中心机控制面发版

改 desktop/controlplane/ 前后端代码后,按 控制面前后端部署SOP 执行:

  • 前端:desktop/controlplane/frontend 下 npm run build → Compress-Archive 打包 zip → 上传 → 静态站 8090 解压替换(用 mv 备份,勿 rm -rf);
  • 后端:逐个上传改动文件 → 覆盖到 /www/wwwroot/controlplane/controlplane/ → 重启 gunicorn 项目 controlplane(8800);
  • 控制面为源码部署,不产 exe。

四、文件服务器发版

改 desktop/fileserver/ 后:

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 安装包)

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 -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)

# 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 "..."]

6.4 验证

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  # 环境包

客户端侧:GET /api/env/status(本地 API,需登录会话)应显示 installed/version/cloud_version; 新装机器首启后环境包自动下载,插件执行走 job_guard.py(Job Object 内存上限 + 整树托管)。

6.5 注意

  • 环境包与壳子相互独立升级;环境包升级后建议对全部已授权插件做一次回归(依赖可能变化)。
  • 插件 minRuntimeVersion 校验的是壳子运行时版本(shell.version),不是环境包版本。
  • 旧 Python 底座(webhost)发版流程见 §二,回退窗口期内保留。

六、检查清单(发版后自检)

  • 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 生效)