Skip to content

Commit e9ad33e

Browse files
Feat/v5 web mcp (#745)
* feat(rust): add Web dashboard and MCP services Share configuration, status and synchronization between Web and MCP; add authenticated HTTP, stdio lifecycle support, in-process scheduling and offline regression tests. Exercise native tests on the existing Windows/macOS/Linux CI matrix. Co-authored-by: openhands <openhands@all-hands.dev> * ci(rust): allow manual cross-platform validation Enable workflow_dispatch for feature-branch CI without requiring PR creation. Preserve matrices, permissions, publishing boundaries and trusted-branch cache policy. Co-authored-by: openhands <openhands@all-hands.dev> * ci(rust): validate feature branch pushes Run the existing Rust cross-platform matrix for feat/** pushes while retaining trusted-branch-only cache writes and unchanged release triggers. Co-authored-by: openhands <openhands@all-hands.dev> * ci(rust): remove temporary branch trigger The v5 pull request now exists and runs the complete native matrix, so restore the original trusted push branches while retaining Web/MCP paths and tests. Co-authored-by: openhands <openhands@all-hands.dev> --------- Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 93b79d2 commit e9ad33e

35 files changed

Lines changed: 5956 additions & 153 deletions

‎.github/workflows/publish-rust.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
paths:
1111
- "rust/Cargo.toml"
1212
- "rust/Cargo.lock"
13+
- "web/**"
14+
- "ddns/config/field-model.json"
15+
- "docker/rust.Dockerfile"
1316
- ".github/workflows/publish-rust.yml"
1417
workflow_dispatch:
1518

@@ -107,6 +110,8 @@ jobs:
107110
binary="rust/target/${{ matrix.target }}/release/ddns-rs"
108111
"$binary" --version
109112
"$binary" --help
113+
"$binary" web --help
114+
"$binary" mcp --help
110115
"$binary" --dns debug --no-cache --index4 "shell:echo 192.0.2.44" --ipv4 test.example.com
111116
- name: Smoke test Rust Windows binary
112117
if: runner.os == 'Windows'
@@ -115,6 +120,10 @@ jobs:
115120
$binary = "rust\target\${{ matrix.target }}\release\ddns-rs.exe"
116121
& $binary --version
117122
& $binary --help
123+
& $binary web --help
124+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
125+
& $binary mcp --help
126+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
118127
& $binary --dns debug --no-cache --index4 "shell:echo 192.0.2.44" --ipv4 test.example.com
119128
- name: Package Unix artifact and checksum
120129
if: runner.os != 'Windows'

‎.github/workflows/rust-python-checks.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches: ["master", "main", "v5"]
66
paths:
77
- "rust/**"
8+
- "web/**"
9+
- "ddns/config/field-model.json"
810
- ".github/workflows/rust.yml"
911
- ".github/workflows/rust-python-checks.yml"
1012
- ".github/workflows/publish-rust.yml"
@@ -24,6 +26,8 @@ on:
2426
branches: ["master", "main", "abc", "v5"]
2527
paths:
2628
- "rust/**"
29+
- "web/**"
30+
- "ddns/config/field-model.json"
2731
- ".github/workflows/rust.yml"
2832
- ".github/workflows/rust-python-checks.yml"
2933
- ".github/workflows/publish-rust.yml"

‎.github/workflows/rust.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
branches: ["master", "main", "v5"]
66
paths:
77
- "rust/**"
8+
- "web/**"
9+
- "ddns/config/field-model.json"
810
- ".github/workflows/rust.yml"
911
- ".github/workflows/rust-python-checks.yml"
1012
- ".github/workflows/publish-rust.yml"
@@ -24,6 +26,8 @@ on:
2426
branches: ["master", "main", "abc", "v5"]
2527
paths:
2628
- "rust/**"
29+
- "web/**"
30+
- "ddns/config/field-model.json"
2731
- ".github/workflows/rust.yml"
2832
- ".github/workflows/rust-python-checks.yml"
2933
- ".github/workflows/publish-rust.yml"
@@ -97,6 +101,8 @@ jobs:
97101
with:
98102
workspaces: rust
99103
save-if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/v5') }}
104+
- name: Run native unit and process tests
105+
run: cargo test --manifest-path rust/Cargo.toml --locked
100106
- name: Install musl toolchain
101107
if: runner.os == 'Linux'
102108
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends musl-tools
@@ -114,6 +120,8 @@ jobs:
114120
binary="rust/target/${{ matrix.target }}/release/ddns-rs"
115121
"$binary" --version
116122
"$binary" --help
123+
"$binary" web --help
124+
"$binary" mcp --help
117125
"$binary" --dns debug --no-cache \
118126
--index4 "shell:echo 192.0.2.44" --ipv4 v4.example.com \
119127
--index6 "shell:echo 2001:db8::44" --ipv6 v6.example.com
@@ -124,6 +132,10 @@ jobs:
124132
$binary = "rust\target\${{ matrix.target }}\release\ddns-rs.exe"
125133
& $binary --version
126134
& $binary --help
135+
& $binary web --help
136+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
137+
& $binary mcp --help
138+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
127139
& $binary --dns debug --no-cache `
128140
--index4 "shell:echo 192.0.2.44" --ipv4 v4.example.com `
129141
--index6 "shell:echo 2001:db8::44" --ipv6 v6.example.com
@@ -161,6 +173,8 @@ jobs:
161173
run: |
162174
docker run --rm --platform ${{ matrix.platform }} ddns-rs:test --version
163175
docker run --rm --platform ${{ matrix.platform }} ddns-rs:test --help
176+
docker run --rm --platform ${{ matrix.platform }} ddns-rs:test web --help
177+
docker run --rm --platform ${{ matrix.platform }} ddns-rs:test mcp --help
164178
docker run --rm --platform ${{ matrix.platform }} ddns-rs:test --dns debug --no-cache \
165179
--index4 "shell:echo 192.0.2.44" --ipv4 v4.example.com \
166180
--index6 "shell:echo 2001:db8::44" --ipv6 v6.example.com

‎README.en.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ cargo build --manifest-path rust/Cargo.toml --release --locked
7777
rust/target/release/ddns-rs -c config.json
7878
```
7979

80-
V5 currently performs one update run, without `task`, Web, MCP, or a scheduler.
80+
V5 supports one-shot updates, the `web` dashboard with an in-process scheduler,
81+
and `mcp` over stdio/HTTP; Web also serves `/mcp`. Web/MCP manage one local
82+
configuration only; non-loopback HTTP listeners require a token.
83+
The `task` command and OS task detection/takeover are not ported: manually
84+
disable old Python/host tasks before enabling Rust scheduled updates.
8185
See the [Rust development guide](docs/en/dev/rust.md) for architecture, validation, support status, and the parity roadmap.
8286

8387
## Why it works for long-running deployments

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ cargo build --manifest-path rust/Cargo.toml --release --locked
7373
rust/target/release/ddns-rs -c config.json
7474
```
7575

76-
V5 目前只执行单次同步,不包含 `task`、Web、MCP 或内置调度。
76+
V5 支持单次同步、`web` 控制台与进程内定时同步,以及 `mcp` stdio/HTTP 服务;
77+
Web 同时提供 `/mcp`。Web/MCP 仅管理单个本地配置,非回环 HTTP 监听必须设置 token。
78+
尚未迁移 `task` 或系统任务检测/接管;启用 Rust 定时同步前必须手动停用旧 Python/主机任务。
7779
架构、验证命令、支持矩阵和迁移路线见 [Rust 开发文档](docs/dev/rust.md)。
7880

7981
## 为什么适合长期运行

‎docker/rust.Dockerfile‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
FROM rust:alpine AS builder
22

3-
WORKDIR /build
3+
WORKDIR /build/rust
44
COPY rust/Cargo.toml rust/Cargo.lock ./
55
COPY rust/src ./src
6+
COPY web/index.html web/dashboard.js web/dashboard.css web/ddns.svg /build/web/
7+
COPY ddns/config/field-model.json /build/ddns/config/field-model.json
68
RUN --mount=type=cache,target=/usr/local/cargo/registry \
7-
--mount=type=cache,target=/build/target \
9+
--mount=type=cache,target=/build/rust/target \
810
cargo build --release --locked \
911
&& cp target/release/ddns-rs /tmp/ddns-rs
1012

‎docs/dev/rust.md‎

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
`ddns-rs` 是 DDNS 下一主版本 V5 的 Rust 实现,集成分支为 `v5`。
44
Python 版本继续在 `master` / `v4` 维护;Rust 功能 PR 应以 `v5` 为目标。
5-
当前开发版本为 `5.0.0-alpha1`,只负责单次同步,尚未发布,也不替换稳定的
5+
当前开发版本为 `5.0.0-alpha1`,支持单次同步及 Web/MCP 服务,尚未发布,也不替换稳定的
66
Python `ddns` 命令或默认安装方式。
77

88
## 当前支持
@@ -14,15 +14,18 @@ Python `ddns` 命令或默认安装方式。
1414
| CLI、`DDNS_*`、本地/远程/多配置、v4.1 `providers` | 已支持 |
1515
| JSON 注释与受限 Python 数据字面量 | 已支持 |
1616
| 缓存、代理回退、重试、TLS 与自定义 CA | 已支持 |
17-
| Linux amd64/arm64 Docker 镜像 | 构建和离线冒烟测试;准备流程保存 OCI 工件,不推送公共镜像,无内置调度 |
17+
| Linux amd64/arm64 Docker 镜像 | 构建和离线冒烟测试;准备流程保存 OCI 工件,不推送公共镜像;`web` 提供进程内调度 |
1818
| Linux x64/arm64、macOS x64/arm64、Windows x64 二进制 | 准备流程保存 `ddns-rs-*` 与 `.sha256` Actions 工件;Linux 使用静态 musl 目标 |
19-
| `task`、Web、MCP | 计划中 |
19+
| Web 控制台、配置管理与进程内调度 | 已支持;单个本地配置,间隔 1..1440 分钟 |
20+
| MCP stdio、独立 HTTP、Web `/mcp` | 已支持;现代协议及旧版 stdio 兼容 |
21+
| `task` 与系统任务检测/接管 | 尚未迁移;必须手动停用旧 Python/主机任务 |
2022

2123
## V5 分支与发布准备
2224

2325
保留 `rust/` 布局、`ddns-rs` 命令及现有配置兼容边界,暂不删除 Python 实现。
2426
`rust/Cargo.toml` 与 `rust/Cargo.lock` 的版本必须一致。`v5` 上的版本文件或
25-
准备工作流发生变更时,`Prepare Rust V5` 自动构建,无需创建标签。它也接受
27+
准备工作流、内嵌 Web 资源/字段模型或 Rust Dockerfile 发生变更时,
28+
`Prepare Rust V5` 自动构建,无需创建标签。它也接受
2629
`v5` 分支上的手动准备,或与 Cargo 版本一致的规范 `v5.*` 标签,并生成经过
2730
校验的原生工件和双架构 OCI 工件;不会创建 Release、上传发布资产或推送镜像。
2831
准备流程仅接受带 `alpha`、`beta` 或 `rc` 后缀的 V5 预发布版本,不接受稳定版本。
@@ -48,6 +51,47 @@ Windows 产物为 `rust\target\release\ddns-rs.exe`。
4851
实验性 `install-rust.sh` 在移动临时二进制到安装目录前执行 `--version`;
4952
新程序无法运行时,即使使用 `--force` 也不会覆盖已有的 `ddns-rs`。
5053

54+
## Web 与 MCP
55+
56+
```bash
57+
ddns-rs web -c config.json --host 127.0.0.1 --port 8000 --interval 5 --open
58+
ddns-rs mcp -c config.json
59+
ddns-rs mcp -c config.json --transport http --host 127.0.0.1 --port 8001
60+
```
61+
62+
`web` 接受 `-c FILE`、`--host HOST`、`--port PORT`、`--http-token TOKEN`、
63+
可重复的 `--http-origin ORIGIN`、`--interval MINUTES` 和 `--open`(打开浏览器)。
64+
未指定子命令时,顶层 `--interval` 或配置根级 `interval` 会选择 Web 模式。
65+
进程内调度间隔为 1..1440 分钟,仅在进程存活期间运行。
66+
67+
控制台支持读取、校验和保存完整配置,管理备份/恢复、查看状态并触发同步。
68+
Web 与 MCP 复用同一个服务,仅接受单个本地配置文件,不接受远程或多配置来源。
69+
Web 使用现有兼容的 Rust 运行时校验配置,不代表与 Python 运行时完全等价。
70+
71+
`mcp` 默认使用按行分隔的 stdio。`--transport http` 在 `/mcp` 提供独立的
72+
Streamable HTTP;Web 监听器也提供相同端点。现代 MCP 协议版本为
73+
`2026-07-28`;旧版 `2025-11-25` 仅通过 stdio 兼容。两种服务均提供与 Python
74+
相同的 `get_ddns_status`、`update_dns_records` 工具。
75+
76+
HTTP 默认监听回环地址。非回环监听必须设置 `--http-token TOKEN`,客户端使用
77+
`Authorization: Bearer TOKEN` 鉴权。可重复传入 `--http-origin ORIGIN` 添加允许的
78+
浏览器来源。Web 和 MCP HTTP 均执行来源检查与鉴权。不要将明文 HTTP 暴露于
79+
不可信网络,应使用可信的 TLS 反向代理或隧道。状态响应不包含凭据,但受监听器
80+
鉴权保护的配置 API 会按设计返回完整配置,包括 Provider 凭据。监听 token、配置和
81+
备份均应视为机密;即使不设置回环监听 token,本机访问仍是信任边界。
82+
监听 token 授予敏感配置访问与 DNS 更新权限,不是只读监控凭据。Web 同步会以
83+
进程用户权限执行经鉴权管理的本地配置中的 `cmd:`/`shell:` 规则,因此只应向可信
84+
管理员授予访问权限。
85+
86+
二进制在编译时内嵌现有 `web/` 控制台资源和 `ddns/config/field-model.json`,
87+
提供页面无需前端服务器或 Python 运行时。修改这些输入后须重新构建;源码构建需
88+
保留仓库布局,不能只复制孤立的 `rust/` 目录。
89+
90+
**迁移限制:** 尚未实现 `task`、系统任务检测及自动接管。启用 Rust 定时同步前,
91+
必须手动停用旧 Python/主机的 systemd、cron、launchd 或 schtasks 任务,避免重复运行。
92+
Web 调度器不会安装或替代主机服务。已有 Rust `regex:` 与独立缓存限制仍然适用;
93+
`log_format`、`log_datefmt` 仅为配置兼容而接受,不保证 Python 日志格式等价。
94+
5195
## 架构
5296

5397
- `cli.rs`:兼容参数、别名和列表规则,不依赖 CLI 框架。
@@ -117,5 +161,5 @@ CI 还会在 Linux x64/arm64、Windows x64、macOS x64/arm64 构建、测试并
117161
## 后续顺序
118162

119163
1. 迁移 systemd、cron、launchd、schtasks。
120-
2. 迁移 Web 控制台与 MCP。
164+
2. 验证 Web/MCP 在长期运行与平台迁移中的兼容性。
121165
3. 达到完整等价并稳定运行后再讨论改名为 `ddns`。

‎docs/docker.md‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
稳定默认镜像仍是 `newfuture/ddns` / `ghcr.io/newfuture/ddns`,不会被 Rust
1818
镜像替换。Rust V5 在 `v5` 分支开发,目前只构建 Linux amd64/arm64
19-
OCI 工件,不推送公共镜像。它直接运行 `ddns-rs`,不包含 Python 镜像的
20-
内置定时任务。可从分支源码本地构建:
19+
OCI 工件,不推送公共镜像。它直接运行 `ddns-rs`,不包含 Python 镜像的 cron
20+
入口;默认单次同步,`web` 模式提供进程内定时同步。可从分支源码本地构建:
2121

2222
```bash
2323
docker build -f docker/rust.Dockerfile -t ddns-rs:v5-dev .
@@ -26,6 +26,33 @@ docker run --rm ddns-rs:v5-dev --help
2626

2727
V5 尚未发布,暂不提供公共 `latest` / `next` Rust 镜像入口。
2828

29+
Web 示例(先准备含 `config.json` 的本地 `config/` 目录,并在 shell 中设置私密的
30+
`DDNS_HTTP_TOKEN`):
31+
32+
```bash
33+
docker run --rm -p 127.0.0.1:8000:8000 \
34+
-v "$PWD/config:/ddns" ddns-rs:v5-dev \
35+
web -c /ddns/config.json --host 0.0.0.0 --port 8000 \
36+
--http-token "$DDNS_HTTP_TOKEN" --http-origin http://127.0.0.1:8000 --interval 5
37+
```
38+
39+
容器内的非回环监听也必须设置 token;仅将发布端口绑定主机回环地址,客户端使用
40+
Bearer token 鉴权。若需远程访问,应使用可信 TLS 反向代理或隧道,并按需重复
41+
`--http-origin ORIGIN`。控制台与 `/mcp` 共用监听器和服务;独立 MCP HTTP 可改用
42+
`mcp -c /ddns/config.json --transport http` 并保留相同监听/鉴权选项。
43+
stdio MCP 使用 `docker run --rm -i`(不要分配 TTY),挂载配置后运行 `mcp -c /ddns/config.json`。
44+
45+
Web/MCP 仅接受单个本地配置。保存及备份/恢复需要容器非 root 用户 `ddns` 对挂载目录
46+
有写权限;请按部署环境配置权限,不要将其设为全局可写。配置 API 会返回完整配置,
47+
包括凭据;配置、备份和监听 token 都应保密。镜像只内嵌明确列出的公共 Web 资源与
48+
字段模型,不复制用户配置。构建必须从仓库根目录提供上下文。
49+
监听 token 授予敏感配置访问与 DNS 更新权限。Web 同步会以容器用户身份执行
50+
本地配置中的 `cmd:`/`shell:` 规则,只应向可信管理员授予访问权限。
51+
52+
进程内调度间隔为 1..1440 分钟;退出容器即停止。尚未实现 `task` 或系统任务
53+
检测/接管,启用前必须手动停用旧 Python/主机任务。兼容限制和详细选项见
54+
[Rust V5 开发文档](dev/rust.md)。以下镜像版本和默认 cron 行为仅适用于稳定 Python 镜像。
55+
2956
### 镜像版本
3057

3158
DDNS 镜像版本(Docker Tag):

0 commit comments

Comments
 (0)