Skip to content

Commit 3a67ccc

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

16 files changed

Lines changed: 1442 additions & 21 deletions

README.md

Lines changed: 25 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 invokes a cloud build first when the YAML defines `cloudBuild`.
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,29 @@ EOF
191191
ar runtime apply -f runtime.yaml
192192
```
193193
194+
To cloud-build the image before deploy, add `cloudBuild`. The target image is
195+
the same `spec.container.image`; docker-image-builder skips existing tags by
196+
default.
197+
198+
```bash
199+
cat > runtime-build.yaml <<EOF
200+
apiVersion: agentrun/v1
201+
kind: AgentRuntime
202+
metadata: {name: my-agent}
203+
spec:
204+
container:
205+
image: registry.cn-hangzhou.aliyuncs.com/my-ns/my-agent:v1
206+
cloudBuild:
207+
dir: .
208+
setupScript: scripts/setup.sh
209+
baseContainerConfig:
210+
image: serverless-registry.cn-hangzhou.cr.aliyuncs.com/functionai/docker-image-builder-worker:20260514-111141-2d80effe
211+
EOF
212+
ar runtime apply -f runtime-build.yaml
213+
# or build without deploying:
214+
# ar runtime cloud-build -f runtime-build.yaml
215+
```
216+
194217
## Command groups
195218
196219
| Group | Alias | Purpose | Docs |
@@ -201,7 +224,7 @@ ar runtime apply -f runtime.yaml
201224
| `tool` | | MCP and FunctionCall tools | [en](./docs/en/tool.md) · [zh](./docs/zh/tool.md) |
202225
| `skill` | | Platform skill packages + local execution | [en](./docs/en/skill.md) · [zh](./docs/zh/skill.md) |
203226
| `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) |
227+
| `runtime` | `rt` | Declarative Agent Runtime deploy and optional cloud image build | [en](./docs/en/runtime.md) · [zh](./docs/zh/runtime.md) |
205228
206229
## Documentation
207230

README_zh.md

Lines changed: 24 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` 时,会先调用云上构建
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,28 @@ EOF
187187
ar runtime apply -f runtime.yaml
188188
```
189189
190+
如需部署前云上构建镜像,可增加 `cloudBuild`。目标镜像就是同一个
191+
`spec.container.image`;docker-image-builder 默认会跳过已存在 tag。
192+
193+
```bash
194+
cat > runtime-build.yaml <<EOF
195+
apiVersion: agentrun/v1
196+
kind: AgentRuntime
197+
metadata: {name: my-agent}
198+
spec:
199+
container:
200+
image: registry.cn-hangzhou.aliyuncs.com/my-ns/my-agent:v1
201+
cloudBuild:
202+
dir: .
203+
setupScript: scripts/setup.sh
204+
baseContainerConfig:
205+
image: serverless-registry.cn-hangzhou.cr.aliyuncs.com/functionai/docker-image-builder-worker:20260514-111141-2d80effe
206+
EOF
207+
ar runtime apply -f runtime-build.yaml
208+
# 或者只构建不部署:
209+
# ar runtime cloud-build -f runtime-build.yaml
210+
```
211+
190212
## 命令组总览
191213
192214
| 命令组 | 别名 | 用途 | 文档 |
@@ -197,7 +219,7 @@ ar runtime apply -f runtime.yaml
197219
| `tool` | | MCP 与 FunctionCall 工具 | [en](./docs/en/tool.md) · [zh](./docs/zh/tool.md) |
198220
| `skill` | | 平台技能包 + 本地执行 | [en](./docs/en/skill.md) · [zh](./docs/zh/skill.md) |
199221
| `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) |
222+
| `runtime` | `rt` | 声明式 Agent Runtime 部署,可选云上镜像构建 | [en](./docs/en/runtime.md) · [zh](./docs/zh/runtime.md) |
201223
202224
## 文档
203225

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 passed to the builder. |
82+
| `cloudBuild` | mapping | | Build the image in the cloud. docker-image-builder skips existing target tags by default. |
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,45 @@ 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. The target image is always
113+
`spec.container.image`; existing-tag checks are delegated to docker-image-builder.
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+
| `baseContainerConfig.image` | string | docker-image-builder default | Build environment image used by the cloud worker. |
125+
126+
Only standard OCI registry mode is supported. Do not write `registryMode`,
127+
`baseImage`, `baseAcrInstanceId`, or `baseRegistry` in this block.
128+
129+
```yaml
130+
cloudBuild:
131+
dir: .
132+
setupScript: scripts/setup.sh
133+
timeoutMinutes: 20
134+
cpu: 4
135+
memory: 8192
136+
baseContainerConfig:
137+
image: serverless-registry.cn-hangzhou.cr.aliyuncs.com/functionai/docker-image-builder-worker:20260514-111141-2d80effe
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. The CLI does not interpolate `${...}` in YAML values; use environment
145+
variables by omitting `registry`, or put literal values in YAML.
146+
106147
## `spec` resource & runtime knobs
107148

108149
| Key | Type | Default | Notes |
@@ -274,6 +315,7 @@ for the parser (`src/agentrun_cli/_utils/agentruntime_yaml.py`).
274315
| `metadata.name` missing or fails `[a-z0-9-]{1,63}` | |
275316
| `spec.container` missing or not a mapping | |
276317
| `spec.container.image` missing or empty | |
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 before deploy
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` invokes docker-image-builder and then deploys
384+
the same `image` value. docker-image-builder skips existing target tags by
385+
default.
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: 63 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 invoke a
7+
cloud image build 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) — cloud-build when configured, then create-or-update from YAML.
20+
- [cloud-build](#cloud-build) — build 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` invokes docker-image-builder before submitting the runtime, then deploys
56+
the same image reference. docker-image-builder skips existing target tags by
57+
default.
5358

5459
### Examples
5560

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

73+
# Build in the cloud, 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+
baseContainerConfig:
85+
image: serverless-registry.cn-hangzhou.cr.aliyuncs.com/functionai/docker-image-builder-worker:20260514-111141-2d80effe
86+
EOF
87+
ar runtime apply -f runtime-build.yaml
88+
6889
# Non-blocking submit (CI-friendly):
6990
ar runtime apply -f runtime.yaml --no-wait
7091

@@ -75,6 +96,38 @@ ar runtime apply -f runtime.yaml --timeout 20m
7596
ar runtime apply -f runtime.yaml --no-prune-endpoints
7697
```
7798

99+
100+
---
101+
102+
## cloud-build
103+
104+
```
105+
ar runtime cloud-build -f FILE
106+
```
107+
108+
### Options
109+
110+
| Flag | Type | Required | Default | Description |
111+
|------|------|----------|---------|-------------|
112+
| `-f`, `--file` | path | yes | | YAML file path (supports multi-document). |
113+
114+
Runs only the `spec.container.cloudBuild` step and does not create or update the
115+
runtime. For each document, the command invokes docker-image-builder and reports
116+
`completed` when the builder exits successfully. The builder skips existing
117+
target tags by default.
118+
119+
`cloud-build` uses the same credentials as `apply`: AgentRun profile values for
120+
Aliyun UID/AK/SK, and `DOCKER_IMAGE_BUILDER_USERNAME` /
121+
`DOCKER_IMAGE_BUILDER_PASSWORD` for registry auth unless the YAML overrides them
122+
under `cloudBuild.registry`.
123+
124+
### Examples
125+
126+
```bash
127+
# Build only; do not deploy the runtime.
128+
ar runtime cloud-build -f runtime-build.yaml
129+
```
130+
78131
---
79132

80133
## render
@@ -91,8 +144,10 @@ ar runtime render -f FILE
91144

92145
Validates the YAML, applies CLI auto-injection (`system_tags=["x-agentrun-cli"]`,
93146
`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`.
147+
and prints the SDK create-input as JSON without calling the server. When the
148+
YAML includes `cloudBuild`, `render` also prints a `cloudBuildPlan` preview but
149+
does not check the registry or build anything. Use this to preview changes
150+
before `apply`.
96151

97152
---
98153

0 commit comments

Comments
 (0)