Skip to content

Commit 3523dee

Browse files
committed
feat(runtime): add cloud image build support
Signed-off-by: 117503445 <t117503445@gmail.com>
1 parent 67289c9 commit 3523dee

16 files changed

Lines changed: 1544 additions & 21 deletions

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ agents that you configure declaratively without writing or deploying any runtime
1313

1414
- **One-command super agent**`ar super-agent run` creates a hosted agent and drops you into a chat REPL in seconds.
1515
- **Declarative deployment** — Kubernetes-style YAML (`ar sa apply -f superagent.yaml`) for reproducible, version-controlled agents.
16-
- **Runtime declarative deploy**`ar runtime apply -f runtime.yaml` builds an Agent Runtime from a container image and waits for it to reach `READY`.
16+
- **Runtime declarative deploy**`ar runtime apply -f runtime.yaml` deploys an Agent Runtime from an image, or cloud-builds that image first when the YAML defines `cloudBuild` and the tag is missing.
1717
- **Seven resource groups**`config`, `model`, `sandbox`, `tool`, `skill`, `super-agent`, `runtime`, all following the same `ar <group> <action>` pattern.
1818
- **Multi-profile config** — store multiple sets of credentials in `~/.agentrun/config.json` and switch with `--profile`.
1919
- **Multiple output formats**`json` (default), `table`, `yaml`, and `quiet` for shell piping.
@@ -191,6 +191,25 @@ EOF
191191
ar runtime apply -f runtime.yaml
192192
```
193193
194+
To cloud-build the image only when the target tag is missing, add `cloudBuild`:
195+
196+
```bash
197+
cat > runtime-build.yaml <<EOF
198+
apiVersion: agentrun/v1
199+
kind: AgentRuntime
200+
metadata: {name: my-agent}
201+
spec:
202+
container:
203+
image: registry.cn-hangzhou.aliyuncs.com/my-ns/my-agent:v1
204+
cloudBuild:
205+
dir: .
206+
setupScript: scripts/setup.sh
207+
EOF
208+
ar runtime apply -f runtime-build.yaml
209+
# or build without deploying:
210+
# ar runtime cloud-build -f runtime-build.yaml
211+
```
212+
194213
## Command groups
195214
196215
| Group | Alias | Purpose | Docs |
@@ -201,7 +220,7 @@ ar runtime apply -f runtime.yaml
201220
| `tool` | | MCP and FunctionCall tools | [en](./docs/en/tool.md) · [zh](./docs/zh/tool.md) |
202221
| `skill` | | Platform skill packages + local execution | [en](./docs/en/skill.md) · [zh](./docs/zh/skill.md) |
203222
| `super-agent` | `sa` | Quickstart / CRUD / declarative / conversation | [en](./docs/en/super-agent.md) · [zh](./docs/zh/super-agent.md) |
204-
| `runtime` | `rt` | Declarative Agent Runtime deploy (container mode) | [en](./docs/en/runtime.md) · [zh](./docs/zh/runtime.md) |
223+
| `runtime` | `rt` | Declarative Agent Runtime deploy and optional cloud image build | [en](./docs/en/runtime.md) · [zh](./docs/zh/runtime.md) |
205224
206225
## Documentation
207226

README_zh.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Agent)**:一种由平台托管、用户只需声明配置、无需编写或
1212

1313
- **一键拉起超级 Agent**`ar super-agent run` 一条命令创建托管 Agent 并进入 REPL 对话。
1414
- **声明式部署** — Kubernetes 风格 YAML(`ar sa apply -f superagent.yaml`),可版本化、可重复部署。
15-
- **Runtime 声明式部署**`ar runtime apply -f runtime.yaml` 从容器镜像创建 Agent Runtime 并等待 `READY`
15+
- **Runtime 声明式部署**`ar runtime apply -f runtime.yaml` 从镜像部署 Agent Runtime;YAML 写了 `cloudBuild` 且目标 tag 不存在时,会先云上构建该镜像
1616
- **七大资源组**`config``model``sandbox``tool``skill``super-agent``runtime`,统一 `ar <group> <action>` 模式。
1717
- **多 Profile 配置**`~/.agentrun/config.json` 支持多套凭证,通过 `--profile` 切换。
1818
- **多种输出格式** — 默认 `json`,支持 `table` / `yaml` / `quiet`(适合 shell 管道)。
@@ -187,6 +187,25 @@ EOF
187187
ar runtime apply -f runtime.yaml
188188
```
189189
190+
如果目标镜像 tag 不存在时需要先云上构建,可增加 `cloudBuild`
191+
192+
```bash
193+
cat > runtime-build.yaml <<EOF
194+
apiVersion: agentrun/v1
195+
kind: AgentRuntime
196+
metadata: {name: my-agent}
197+
spec:
198+
container:
199+
image: registry.cn-hangzhou.aliyuncs.com/my-ns/my-agent:v1
200+
cloudBuild:
201+
dir: .
202+
setupScript: scripts/setup.sh
203+
EOF
204+
ar runtime apply -f runtime-build.yaml
205+
# 或者只构建不部署:
206+
# ar runtime cloud-build -f runtime-build.yaml
207+
```
208+
190209
## 命令组总览
191210
192211
| 命令组 | 别名 | 用途 | 文档 |
@@ -197,7 +216,7 @@ ar runtime apply -f runtime.yaml
197216
| `tool` | | MCP 与 FunctionCall 工具 | [en](./docs/en/tool.md) · [zh](./docs/zh/tool.md) |
198217
| `skill` | | 平台技能包 + 本地执行 | [en](./docs/en/skill.md) · [zh](./docs/zh/skill.md) |
199218
| `super-agent` | `sa` | 一键拉起 / CRUD / 声明式 / 会话管理 | [en](./docs/en/super-agent.md) · [zh](./docs/zh/super-agent.md) |
200-
| `runtime` | `rt` | 声明式 Agent Runtime 部署(容器模式) | [en](./docs/en/runtime.md) · [zh](./docs/zh/runtime.md) |
219+
| `runtime` | `rt` | 声明式 Agent Runtime 部署,可选云上镜像构建 | [en](./docs/en/runtime.md) · [zh](./docs/zh/runtime.md) |
201220
202221
## 文档
203222

agentruntime.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ metadata:
2020
spec:
2121
container:
2222
image: registry.cn-hangzhou.aliyuncs.com/my-ns/my-agent:v1
23+
# cloudBuild: # optional; build only if image tag is missing
24+
# dir: . # source directory uploaded to builder
25+
# setupScript: scripts/setup.sh # empty string skips setup
2326
# command: ["python", "app.py"] # optional, overrides image CMD/ENTRYPOINT
2427
# port: 9000 # optional; spec.port below also works
2528

docs/en/runtime-yaml.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rejected (see [Validation rules](#validation-rules)).
1515
- [CLI auto-injection](#cli-auto-injection)
1616
- [`metadata`](#metadata)
1717
- [`spec.container`](#speccontainer)
18+
- [`spec.container.cloudBuild`](#speccontainercloudbuild)
1819
- [`spec` resource & runtime knobs](#spec-resource--runtime-knobs)
1920
- [`spec.protocol`](#specprotocol)
2021
- [`spec.network`](#specnetwork)
@@ -77,7 +78,8 @@ Required block. Defines the container image and registry credentials.
7778

7879
| Key | Type | Required | Notes |
7980
|---|---|---|---|
80-
| `image` | string | ✓ | OCI image reference. |
81+
| `image` | string | ✓ | OCI image reference. When `cloudBuild` is set, this is also the target image pushed by the builder and must include an explicit tag. |
82+
| `cloudBuild` | mapping | | Build the image in the cloud when `image` is missing from the registry. Existing tags are never rebuilt or overwritten. |
8183
| `command` | list&lt;string&gt; | | Overrides image `ENTRYPOINT`/`CMD`. |
8284
| `port` | int | | Container listen port. If set, wins over `spec.port`. |
8385
| `imageRegistryType` | enum | | One of `ACR`, `ACREE`, `CUSTOM`. |
@@ -103,6 +105,44 @@ registryConfig:
103105
All three sub-blocks (`auth`, `cert`, `network`) are individually optional, but
104106
`registryConfig` itself is mandatory under `CUSTOM`.
105107

108+
109+
## `spec.container.cloudBuild`
110+
111+
Optional block. It asks `ar runtime apply` or `ar runtime cloud-build` to build
112+
`spec.container.image` with docker-image-builder **only when that image tag does
113+
not already exist**. The target image is always `spec.container.image`.
114+
115+
| Key | Type | Default | Notes |
116+
|---|---|---|---|
117+
| `dir` | string | `.` | Local source directory to upload. Relative paths are resolved from the current working directory. |
118+
| `setupScript` | string | `scripts/setup.sh` | Script executed in the builder before packaging. Empty string skips setup. |
119+
| `timeoutMinutes` | string/number | `20` | Setup script timeout in minutes. Worker creation, upload and push are not counted. |
120+
| `cpu` | string/number | `4` | Builder worker CPU, for example `4` or `4c`. |
121+
| `memory` | string/number | `8192` | Builder worker memory in MB. |
122+
| `region` | string | AgentRun region / `cn-hangzhou` | FC region for the builder worker. |
123+
| `registry` | mapping | env vars | Optional target registry auth; see below. |
124+
125+
Only standard OCI registry mode is supported. Do not write `registryMode`,
126+
`baseImage`, `baseAcrInstanceId`, or `baseRegistry` in this block.
127+
128+
```yaml
129+
cloudBuild:
130+
dir: .
131+
setupScript: scripts/setup.sh
132+
timeoutMinutes: 20
133+
cpu: 4
134+
memory: 8192
135+
registry:
136+
username: deploy-bot
137+
password: ${DOCKER_IMAGE_BUILDER_PASSWORD}
138+
```
139+
140+
`registry.username` and `registry.password` are optional. If omitted, the CLI
141+
reads `DOCKER_IMAGE_BUILDER_USERNAME` and `DOCKER_IMAGE_BUILDER_PASSWORD` from
142+
the environment or `.env`. Aliyun UID/AK/SK are resolved from the active
143+
AgentRun profile and passed to docker-image-builder through environment
144+
variables.
145+
106146
## `spec` resource & runtime knobs
107147

108148
| Key | Type | Default | Notes |
@@ -274,6 +314,8 @@ for the parser (`src/agentrun_cli/_utils/agentruntime_yaml.py`).
274314
| `metadata.name` missing or fails `[a-z0-9-]{1,63}` | |
275315
| `spec.container` missing or not a mapping | |
276316
| `spec.container.image` missing or empty | |
317+
| `spec.container.cloudBuild` is set but `image` is not `registry/repository:tag` | The builder target must be deterministic. |
318+
| `spec.container.cloudBuild` has unsupported fields | Only OCI mode is supported; ACREE/base-registry builder fields are rejected. |
277319
| `spec.container.imageRegistryType` not in `ACR|ACREE|CUSTOM` | |
278320
| `imageRegistryType=CUSTOM` but `registryConfig` missing | |
279321
| `metadata.tags` present | SDK 0.0.200 removed the field. |
@@ -320,6 +362,28 @@ spec:
320362
# system_tags=["x-agentrun-cli"], artifact_type=Container
321363
```
322364

365+
366+
### Cloud build when image is missing
367+
368+
```yaml
369+
apiVersion: agentrun/v1
370+
kind: AgentRuntime
371+
metadata:
372+
name: my-agent
373+
spec:
374+
container:
375+
image: registry.cn-hangzhou.aliyuncs.com/my-ns/my-agent:v1
376+
cloudBuild:
377+
dir: .
378+
setupScript: scripts/setup.sh
379+
env:
380+
LOG_LEVEL: info
381+
```
382+
383+
`ar runtime apply -f runtime.yaml` checks the image tag first. If it exists, the
384+
build step is skipped. If it does not exist, the CLI invokes docker-image-builder
385+
and then deploys the same `image` value.
386+
323387
### Production — ACREE + private network + NAS + canary endpoint
324388

325389
```yaml
@@ -406,6 +470,7 @@ For users who need to cross-reference the SDK
406470
| `spec.container.imageRegistryType` | `container_configuration.image_registry_type` |
407471
| `spec.container.acrInstanceId` | `container_configuration.acr_instance_id` |
408472
| `spec.container.registryConfig.*` | `container_configuration.registry_config.*` |
473+
| `spec.container.cloudBuild.*` | CLI-only build plan; not sent to AgentRun SDK. |
409474
| `spec.cpu / memory / port / diskSize` | `cpu / memory / port / disk_size` |
410475
| `spec.enableSessionIsolation` | `enable_session_isolation` |
411476
| `spec.protocol.type` | `protocol_configuration.type` |

docs/en/runtime.md

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
# ar runtime
44

5-
Manage **Agent Runtimes** declaratively from a YAML file. The CLI only supports
6-
container-mode runtimes (you supply an OCI image; building the image is out of
7-
scope for this command group). Endpoints are embedded in the same YAML; the
8-
default behaviour is to inject one named `default` (`targetVersion=LATEST`).
5+
Manage **Agent Runtimes** declaratively from a YAML file. The CLI supports
6+
container-mode runtimes from an existing OCI image, and can optionally build a
7+
missing image in the cloud before deployment through `spec.container.cloudBuild`.
8+
Endpoints are embedded in the same YAML; the default behaviour is to inject one
9+
named `default` (`targetVersion=LATEST`).
910

1011
Also available as the alias `ar rt`.
1112

@@ -15,7 +16,8 @@ Also available as the alias `ar rt`.
1516
1617
## Commands
1718

18-
- [apply](#apply) — create-or-update from YAML, with status polling.
19+
- [apply](#apply) — build a missing image if needed, then create-or-update from YAML.
20+
- [cloud-build](#cloud-build) — build missing images from YAML without deploying.
1921
- [render](#render) — dry-run validate + render to SDK input.
2022
- [get](#get) — fetch one runtime by name.
2123
- [list](#list) — list runtimes; filter by `--created-by-cli` or `--workspace`.
@@ -49,7 +51,10 @@ ar runtime apply -f FILE [--wait/--no-wait] [--timeout DURATION]
4951

5052
The CLI injects sensible defaults for `cpu` (2 cores), `memory` (4096 MB) and
5153
`port` (9000) when the YAML omits them — the backend rejects null values for
52-
these three fields with HTTP 400.
54+
these three fields with HTTP 400. If `spec.container.cloudBuild` is present,
55+
`apply` first checks whether `spec.container.image` exists in the registry. It
56+
only runs the cloud build when that image tag is missing, then deploys the same
57+
image reference. Existing images are never rebuilt or overwritten.
5358

5459
### Examples
5560

@@ -65,6 +70,20 @@ spec:
6570
EOF
6671
ar runtime apply -f runtime.yaml
6772

73+
# Build in the cloud only if the target image tag is missing, then deploy.
74+
cat > runtime-build.yaml <<EOF
75+
apiVersion: agentrun/v1
76+
kind: AgentRuntime
77+
metadata: {name: my-agent}
78+
spec:
79+
container:
80+
image: registry.cn-hangzhou.aliyuncs.com/my-ns/my-agent:v1
81+
cloudBuild:
82+
dir: .
83+
setupScript: scripts/setup.sh
84+
EOF
85+
ar runtime apply -f runtime-build.yaml
86+
6887
# Non-blocking submit (CI-friendly):
6988
ar runtime apply -f runtime.yaml --no-wait
7089

@@ -75,6 +94,38 @@ ar runtime apply -f runtime.yaml --timeout 20m
7594
ar runtime apply -f runtime.yaml --no-prune-endpoints
7695
```
7796

97+
98+
---
99+
100+
## cloud-build
101+
102+
```
103+
ar runtime cloud-build -f FILE
104+
```
105+
106+
### Options
107+
108+
| Flag | Type | Required | Default | Description |
109+
|------|------|----------|---------|-------------|
110+
| `-f`, `--file` | path | yes | | YAML file path (supports multi-document). |
111+
112+
Runs only the `spec.container.cloudBuild` step and does not create or update the
113+
runtime. For each document, the command checks `spec.container.image` first; if
114+
the tag already exists, it reports `skippedExisting`, otherwise it invokes
115+
`docker-image-builder` and reports `built`.
116+
117+
`cloud-build` uses the same credentials as `apply`: AgentRun profile values for
118+
Aliyun UID/AK/SK, and `DOCKER_IMAGE_BUILDER_USERNAME` /
119+
`DOCKER_IMAGE_BUILDER_PASSWORD` for registry auth unless the YAML overrides them
120+
under `cloudBuild.registry`.
121+
122+
### Examples
123+
124+
```bash
125+
# Build only; do not deploy the runtime.
126+
ar runtime cloud-build -f runtime-build.yaml
127+
```
128+
78129
---
79130

80131
## render
@@ -91,8 +142,10 @@ ar runtime render -f FILE
91142

92143
Validates the YAML, applies CLI auto-injection (`system_tags=["x-agentrun-cli"]`,
93144
`artifact_type=Container`, default endpoint when `spec.endpoints` is omitted),
94-
and prints the SDK create-input as JSON without calling the server. Use this to
95-
preview changes before `apply`.
145+
and prints the SDK create-input as JSON without calling the server. When the
146+
YAML includes `cloudBuild`, `render` also prints a `cloudBuildPlan` preview but
147+
does not check the registry or build anything. Use this to preview changes
148+
before `apply`.
96149

97150
---
98151

0 commit comments

Comments
 (0)