Skip to content

Commit 1a03267

Browse files
congxiao-wxxSodawyx
authored andcommitted
Enable runtime YAML export for copy workflows
Add a read-only runtime export command that emits apply-compatible YAML for existing container runtimes and endpoints, plus docs and integration coverage. Keep the implementation bounded to fields already accepted by the runtime YAML parser. Constraint: Export output must round-trip through ar runtime apply without carrying server-owned IDs or status fields. Rejected: Reconstructing cloudBuild from remote runtime state | cloudBuild depends on local source and build settings that are not recoverable from the service. Confidence: high Scope-risk: narrow Directive: Treat exported registry auth as sensitive if returned by the service; review YAML before sharing. Tested: ruff check src/ tests/; ruff format --check src/ tests/; mypy src/agentrun_cli; pytest tests/integration/test_runtime_cmd.py -v; pytest tests/unit tests/integration --cov=agentrun_cli --cov-fail-under=95; live cn-hangzhou export/apply/status smoke for cli-export-verify-20260609213323. Change-Id: Ib7d4b629bbb2e377213b3aa302d7d78d13c7f066 Co-developed-by: Codex <noreply@openai.com> Not-tested: cleanup/delete of live verification runtime was intentionally not performed without explicit deletion confirmation. Signed-off-by: congxiao.wxx <congxiao.wxx@alibaba-inc.com>
1 parent 5fea257 commit 1a03267

6 files changed

Lines changed: 796 additions & 4 deletions

File tree

docs/en/runtime.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Also available as the alias `ar rt`.
1919
- [apply](#apply) — cloud-build when configured, then create-or-update from YAML.
2020
- [cloud-build](#cloud-build) — build images from YAML without deploying.
2121
- [render](#render) — dry-run validate + render to SDK input.
22+
- [export](#export) — export one existing runtime as apply-ready YAML.
2223
- [get](#get) — fetch one runtime by name.
2324
- [list](#list) — list runtimes; filter by `--created-by-cli` or `--workspace`.
2425
- [delete](#delete) — delete a runtime (waits by default).
@@ -157,6 +158,41 @@ before `apply`.
157158

158159
---
159160

161+
## export
162+
163+
```
164+
ar runtime export NAME [-f FILE]
165+
```
166+
167+
Export an existing Agent Runtime and its endpoints as `ar runtime apply` YAML.
168+
The command writes YAML to stdout by default, or to `--file` when provided. It
169+
exports only fields supported by the CLI YAML schema and intentionally omits
170+
server-owned state such as IDs, ARNs, versions, status, and timestamps.
171+
`cloudBuild` cannot be reconstructed from a remote runtime because it depends on
172+
local source/build settings.
173+
If the service returns registry authentication details, the exported YAML may
174+
contain sensitive values; review it before committing or sharing.
175+
176+
### Options
177+
178+
| Flag | Type | Required | Default | Description |
179+
|------|------|----------|---------|-------------|
180+
| `-f`, `--file` | path | no | | Write YAML to a file instead of stdout. |
181+
182+
### Examples
183+
184+
```bash
185+
# Export to stdout.
186+
ar runtime export my-agent
187+
188+
# Export, edit metadata.name, then create a copy.
189+
ar runtime export my-agent -f copied-runtime.yaml
190+
# edit copied-runtime.yaml: metadata.name: my-agent-copy
191+
ar runtime apply -f copied-runtime.yaml
192+
```
193+
194+
---
195+
160196
## get
161197

162198
```

docs/zh/runtime.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ YAML;用户不写时 CLI 会自动注入一个名为 `default` 的 endpoint(
1616
- [apply](#apply) — 配置后先云上构建,再从 YAML create-or-update。
1717
- [cloud-build](#cloud-build) — 只按 YAML 构建镜像,不部署 runtime。
1818
- [render](#render) — 校验 + 渲染为 SDK 输入(不调用服务端)。
19+
- [export](#export) — 将存量 runtime 导出为可 apply 的 YAML。
1920
- [get](#get) — 按名字获取单个 runtime。
2021
- [list](#list) — 列出 runtime;可用 `--created-by-cli``--workspace` 过滤。
2122
- [delete](#delete) — 删除 runtime(默认等待)。
@@ -148,6 +149,38 @@ ar runtime render -f FILE
148149

149150
---
150151

152+
## export
153+
154+
```
155+
ar runtime export NAME [-f FILE]
156+
```
157+
158+
读取一个存量 Agent Runtime 及其 endpoints,并导出为 `ar runtime apply` 可消费的
159+
YAML。默认输出到 stdout;传入 `--file` 时写入文件。命令只导出当前 CLI YAML
160+
schema 支持的字段,会刻意省略 ID、ARN、version、status、时间戳等服务端状态字段。
161+
`cloudBuild` 依赖本地源码目录和构建参数,无法从远端 runtime 反推,因此不会导出。
162+
如果服务端返回镜像仓库认证信息,导出的 YAML 可能包含敏感值;提交或共享前请先检查。
163+
164+
### Options
165+
166+
| Flag | Type | Required | Default | Description |
167+
|------|------|----------|---------|-------------|
168+
| `-f`, `--file` | path | no | | 将 YAML 写入文件,而不是 stdout。 |
169+
170+
### Examples
171+
172+
```bash
173+
# 导出到 stdout
174+
ar runtime export my-agent
175+
176+
# 导出后修改 metadata.name,再创建一份副本
177+
ar runtime export my-agent -f copied-runtime.yaml
178+
# 编辑 copied-runtime.yaml:metadata.name: my-agent-copy
179+
ar runtime apply -f copied-runtime.yaml
180+
```
181+
182+
---
183+
151184
## get
152185

153186
```

src/agentrun_cli/_utils/cloud_build.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,14 @@ def _artifact_name() -> str:
323323

324324
def _go_platform() -> str:
325325
"""Convert a Python platform name to a Go release platform name."""
326-
if sys.platform == "win32":
326+
platform_name = str(sys.platform)
327+
if platform_name == "win32":
327328
return "windows"
328-
if sys.platform == "darwin":
329+
if platform_name == "darwin":
329330
return "darwin"
330-
if sys.platform.startswith("linux"):
331+
if platform_name.startswith("linux"):
331332
return "linux"
332-
raise CloudBuildError(f"unsupported platform: {sys.platform}")
333+
raise CloudBuildError(f"unsupported platform: {platform_name}")
333334

334335

335336
def _go_arch() -> str:

src/agentrun_cli/commands/runtime/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121
from agentrun_cli.commands.runtime import crud_cmd as _crud_mod # noqa: E402
2222
from agentrun_cli.commands.runtime import delete_cmd as _delete_mod # noqa: E402
23+
from agentrun_cli.commands.runtime import export_cmd as _export_mod # noqa: E402
2324
from agentrun_cli.commands.runtime import render_cmd as _render_mod # noqa: E402
2425
from agentrun_cli.commands.runtime import status_cmd as _status_mod # noqa: E402
2526

@@ -35,6 +36,7 @@ def runtime_group():
3536
runtime_group.add_command(_apply_mod.apply_cmd)
3637
runtime_group.add_command(_cloud_build_mod.cloud_build_cmd)
3738
runtime_group.add_command(_render_mod.render_cmd)
39+
runtime_group.add_command(_export_mod.export_cmd)
3840
runtime_group.add_command(_crud_mod.get_cmd)
3941
runtime_group.add_command(_crud_mod.list_cmd)
4042
runtime_group.add_command(_delete_mod.delete_cmd)

0 commit comments

Comments
 (0)