@ease-ops/onboard 0.0.0-stage → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,686 @@
1
+ # payload v1 · `.ease-ops/onboarding.yaml`
2
+
3
+ `ease_ops_plan_onboarding` 与 `ease_ops_apply_onboarding` 的**唯一输入**。Skill 写它,平台读它,人审它。
4
+
5
+ ## 三条铁律
6
+
7
+ 违反任意一条,plan 直接返回错误,不会"尽力而为":
8
+
9
+ | # | 规则 | 错误码 |
10
+ |---|---|---|
11
+ | 1 | 未知字段不忽略,直接报错 | `unknown_field` |
12
+ | 2 | 密钥的值永远不出现,只出现 key + `secret: true` | `secret_in_payload` |
13
+ | 3 | 平台内部 ID 永远不出现,只用 code / name / 逻辑名 | `platform_id_forbidden` |
14
+
15
+ 另有一条形态约束:**不写 `null`**。未设置就用空字符串 `""` 或省略字段。
16
+
17
+ ---
18
+
19
+ ## 1. 顶层
20
+
21
+ | 字段 | 类型 | 必填 | 默认 | 说明 |
22
+ |---|---|---|---|---|
23
+ | `version` | int | ✅ | — | 固定 `1` |
24
+ | `mode` | enum | | `auto` | `auto` / `new_project` / `add_component` |
25
+ | `project` | object | | — | 见 §2;`mode=add_component` 时必填 |
26
+ | `repos` | array | ✅ | — | 见 §3,至少 1 项 |
27
+ | `hosts` | array | | `[]` | 部署目标主机,见 §3b;不部署就不写 |
28
+ | `components` | array | ✅ | — | 见 §4,至少 1 项 |
29
+ | `checkout_mode` | enum | | `shared` | `shared` / `separate` |
30
+ | `configs` | array | | `[]` | 环境变量,见 §5 |
31
+ | `resources` | array | | `[]` | 配置模板文件,见 §6 |
32
+ | `flows` | array | | `[]` | 流程插入,见 §7 |
33
+ | `acknowledge` | string[] | | `[]` | 回填 plan 的 `acknowledge_required[].code` |
34
+ | `verify` | object | | `{build:false,env:test}` | `build`(bool) / `env`(string) |
35
+
36
+ `mode` 的取值由**阶段 0 的事实**决定,不由用户措辞决定:直接采用 `resolve_repo` 返回的 `mode`(`new_project` / `add_component` / `ambiguous`);只有 `ambiguous` 时等用户选完(或选"新建项目")才定。
37
+
38
+ ---
39
+
40
+ ## 2. `project`
41
+
42
+ | 字段 | 类型 | 必填 | 默认 | 说明 |
43
+ |---|---|---|---|---|
44
+ | `strategy` | enum | | `auto` | `auto` / `create` / `use` |
45
+ | `name` | string | `create` 时 ✅ | — | 展示名,中文可 |
46
+ | `code` | string | | 由仓库名 slug 化 | `^[a-z][a-z0-9-]{1,31}$`,项目内唯一 |
47
+
48
+ - `strategy: use` 表示"接进已有项目",此时 `code` 必填,且必须能命中;命中失败 → `project_not_found`。
49
+ - 环境树(`default` 根 + `test` / `prod`)与 share flow 由平台在建项目时自动初始化,**payload 不描述环境**。
50
+
51
+ ---
52
+
53
+ ## 3. `repos[]`
54
+
55
+ | 字段 | 类型 | 必填 | 默认 | 说明 |
56
+ |---|---|---|---|---|
57
+ | `key` | string | ✅ | — | `^[a-z][a-z0-9-]{0,31}$`,组件用它引用;不用 URL 当键 |
58
+ | `url` | string | ✅ | — | 归一化后的 git 远程地址(去 `.git`、ssh/https 等价);**必须是真实远程** |
59
+ | `branch` | string | | 见下 | 检出节点使用的分支 |
60
+ | `credential_ref` | string | | — | `platform:<name>` / `project:<name>` / `<name>` |
61
+ | `checkout_dir` | string | | 由 URL 末段派生 | 工作区下的检出目录名 |
62
+ | `origin` | enum | | `root` | `root` / `submodule` / `nested` |
63
+
64
+ **`branch` 的取值**:优先复用仓库已记录的默认分支,其次本地 `git symbolic-ref refs/remotes/origin/HEAD`,再退到 `git branch --show-current`(后两者必须标 `(推断)` 进待复核清单)。未填且无可继承默认分支时按 `main` 处理并给出 `repo_branch_defaulted` 警告。
65
+
66
+ **本地仓库一律拒**:`file://`、绝对/相对路径、`~` 开头的地址会被 `repo_remote_required` 阻断——runner 靠远程地址检出,没有远程仓库的目录接不进平台。
67
+
68
+ **仓库类型由平台推断**:`github.com` / `gitlab` / `gitee` 按域名归类,其余网络地址(如 `git.company.com`)归通用 `git`。类型只影响仓库元数据与默认分支策略,检出统一按 URL 走;payload 不提供 type 字段。
69
+
70
+ **`origin` 的语义**:`root` 是当前工作目录所在仓库;`submodule` / `nested` 只在用户明确要求接入时才出现,否则应写进 plan 的 `nested.detected_but_skipped`,不进 payload。
71
+
72
+ `credential_ref` 只写引用,不写用户名密码。解析顺序:
73
+
74
+ | 写法 | 解析范围 |
75
+ |---|---|
76
+ | `platform:<name>` | 只在平台级凭证里找,找不到 → `credential_not_found` |
77
+ | `project:<name>` | 只在目标项目里找 |
78
+ | `<name>` | 先项目级、再平台级;两处同名同时命中 → 报 `code_conflict`,要求加前缀 |
79
+
80
+ purpose 只有四类:`git_https` / `git_ssh` / `host_ssh` / `registry`。用错 purpose → `credential_purpose_mismatch`。凭证还没建也能继续:留空即可,plan 会把它记进 `secret_requirements`,apply 后落在 `pre_build_blockers`。
81
+
82
+ ---
83
+
84
+ ## 3b. `hosts[]`(部署目标主机)
85
+
86
+ | 字段 | 类型 | 必填 | 默认 | 说明 |
87
+ |---|---|---|---|---|
88
+ | `key` | string | ✅ | — | `^[a-z][a-z0-9-]{0,31}$`,`deploy.targets[].host_ref` 用它引用 |
89
+ | `name` | string | | 取 `ip` | 主机展示名 |
90
+ | `ip` | string | ✅ | — | IPv4 / IPv6 / 主机名;**不写端口、不写 URL**(端口是下一个字段) |
91
+ | `port` | int | | `22` | SSH 端口 |
92
+ | `credential_ref` | string | 新建主机 ✅ | — | 这台机器的登录凭证(purpose `host_ssh`) |
93
+ | `description` | string | | — | 备注 |
94
+
95
+ 规则:
96
+
97
+ - **与 `repos[]` 对称**:主机在这里声明一次,多个组件共用,避免把同几台机器抄两遍。幂等键是 `(项目, ip, port)`:已存在就复用,不存在就新建。
98
+ - **凭证只挂在主机上**:部署运行时取的是主机绑定的登录方式(ssh 优先、https 回落),部署步骤上没有凭证字段。
99
+ - 新建主机必须给 `credential_ref`,缺 → `host_credential_required`(不建"永远登不进去"的半成品主机)。
100
+ - 复用已有主机可留空 = 沿用它现有绑定;若这台机器没绑定过 → 进 `pre_build_blockers`,先走补录。
101
+ - 复用主机上给了**不同的** `credential_ref` 会覆盖现有登录方式 → plan 产出 `acknowledge_required: ["host_cred_override:<key>"]`,人不点头不执行(同机器上其它流水线的登录会一起变)。
102
+ - 主机自动绑到 `flows[]` 里出现过的环境(`env_hosts`);没声明流程就不猜环境归属。
103
+
104
+ ---
105
+
106
+ ## 4. `components[]`
107
+
108
+ | 字段 | 类型 | 必填 | 默认 | 说明 |
109
+ |---|---|---|---|---|
110
+ | `code` | string | ✅ | — | `^[a-z][a-z0-9-]{2,47}$`,项目内唯一 |
111
+ | `name` | string | ✅ | — | 展示名 |
112
+ | `repo_refs` | string[] | ✅ | — | `repos[].key`,第 1 项是**主仓库** |
113
+ | `work_dir` | string | | `.` | 相对**主仓库根**的构建目录 |
114
+ | `languages` | string[] | | `[unknown]` | 见下方枚举 |
115
+ | `build` | object | ✅ | — | 见 §4.1 |
116
+ | `deploy` | object | | — | 见 §4.2;**段的存在即要部署** |
117
+
118
+ `languages` 合法值(平台枚举,照抄,别自造):`java` `go` `python` `javascript` `typescript` `ruby` `php` `c` `swift` `rust` `react` `vue` `node` `unknown`。
119
+
120
+ ### 4.1 `build`
121
+
122
+ | 字段 | 类型 | 必填 | 说明 |
123
+ |---|---|---|---|
124
+ | `kind` | enum | ✅ | `script` / `docker` |
125
+ | `runtime` | string | `kind=script` 时 ✅ | 逻辑名,如 `go-1.23` / `node-20` |
126
+ | `script` | string | `kind=script` 时 ✅ | 在 `work_dir` 下执行的 shell |
127
+ | `dockerfile` | string | `kind=docker` 时 | 相对 `work_dir`,默认 `./Dockerfile` |
128
+ | `artifacts` | array | ✅ | 构建产物声明,至少 1 项 |
129
+
130
+ `artifacts[]`:
131
+
132
+ | 字段 | 类型 | 必填 | 说明 |
133
+ |---|---|---|---|
134
+ | `name` | string | ✅ | 产物标识,如 `dist` / `api-binary`;**不要带扩展名**(写 `api-binary` 不写 `api.jar`) |
135
+ | `required` | bool | | 默认 `true`;缺失时构建判失败 |
136
+ | `rules` | array | ✅ | `[{ work_dir: "bin", patterns: ["**/*"] }]` |
137
+
138
+ **规则怎么写**:`work_dir` 指到"这份产物对应哪个目标目录",`patterns` 用 `["**/*"]` 把该目录整体收进来。
139
+
140
+ - 要部署的组件:`work_dir: bin` + `patterns: ["**/*"]` —— 归档里就是目录内容本身,部署脚本 `rsync -avc {{artifact:api-binary}}/ /opt/shop/bin/` 一行对齐。
141
+ - `work_dir: "."` + `patterns: ["bin/api"]` 会把 `bin/` 这层也带进归档(`{{artifact:x}}/bin/api`),下发后容易变成 `/opt/shop/bin/bin/api` → `artifact_paths_nested` 警告。
142
+ - 只构建打包的组件不必迁就目标目录,`patterns: ["dist/**"]` 这类写法照旧。
143
+ - 同一工件不要写多条 `work_dir` 相同、其中一条是兜底 glob 的规则(同一文件会被重复收录)→ `artifact_rules_overlap` 警告。
144
+
145
+ `runtime` 的解析规则(详见设计文档 §4.7):
146
+
147
+ 1. 只写逻辑名或白名单内的完整镜像名;不写 `image_version_id`、不写 registry 前缀(除非兜底)。
148
+ 2. 解析顺序:全局目录 → 项目目录 → 未命中则**新建项目级 Ref 镜像**(纯 DB 写,不触发构建)。
149
+ 3. `kind=docker` 不需要 `runtime`——Dockerfile 自带 `FROM`。
150
+
151
+ ### 4.2 `deploy`
152
+
153
+ | 字段 | 类型 | 必填 | 说明 |
154
+ |---|---|---|---|
155
+ | `script` | string | ✅ | 部署脚本;在目标机的暂存根目录执行(cwd 与构建时一致,引用一律用相对路径) |
156
+ | `start_command` | string | | 启动命令(部署脚本之后执行) |
157
+ | `stop_command` | string | | 停止命令(部署脚本之前执行) |
158
+ | `targets` | array | ✅ | `[{ host_ref: "app-1" }]` 引用 `hosts[].key`,或 `[{ scope: env }]` |
159
+
160
+ - **`script` 是工件与配置下发的唯一驱动**:runner 只下载脚本里 `{{artifact:<name>}}` / `{{conf:<rel_path 首段>}}` 引用的东西。没有脚本 = 声明了部署却什么都不发,plan 报 `deploy_script_required`。
161
+ - 脚本以 `set -euo pipefail` 开头,一条命令一行;目标目录写绝对路径,`{{artifact:x}}/` 与 `{{conf:key}}/` 末尾的 `/` 表示"把目录内容拷进去"。默认模板:
162
+
163
+ ```sh
164
+ set -euo pipefail
165
+ rsync -avc {{artifact:api-binary}}/ /opt/shop/bin/
166
+ rsync -avc {{conf:conf}}/ /opt/shop/conf/
167
+ ```
168
+
169
+ - 目标目录(`/opt/<code>/...`)是推断值,必须标 `(推断)` 进待复核清单;不默认加 `--delete`。
170
+ - 引用的工件名必须是 `build.artifacts[].name` 里有的(否则 `deploy_artifact_unknown`);`{{conf:}}` 的 key 必须能命中 `resources[].rel_path` 的前缀(否则 `deploy_conf_unknown`)。声明了模板却没被任何脚本引用 → `conf_unreferenced` 警告:配置不会下发,补一条 rsync。
171
+ - 启停命令单独放 `start_command` / `stop_command`,没有就省略。
172
+ - **没有"健康检查"字段**:健康检查类子步骤只认平台里已登记的巡检项,接入造不出来;要检查就写在 `start_command` 末尾(它是最后一个执行的动作),如 `systemctl restart shop-api && curl -fsS http://127.0.0.1:8080/health`。
173
+ - **只构建打包 = 删掉整段 `deploy`**。没有 `enabled` 这个字段(写 `enabled` 会被 `unknown_field` 拒),也不允许 `{ targets: [] }` 这种空脚本。
174
+ - 没有 `credential_ref` 这个字段:登录方式属于 `hosts[]`(见 §3b)。
175
+ - `host_ref` 与 `scope` 互斥:前者"只发这几台",后者"发该流程环境绑定的全部机器"(增减机器不必重跑接入)。
176
+
177
+ ---
178
+
179
+ ## 5. `configs[]`(环境变量)
180
+
181
+ | 字段 | 类型 | 必填 | 说明 |
182
+ |---|---|---|---|
183
+ | `key` | string | ✅ | 变量名,如 `DB_HOST` |
184
+ | `scope` | enum | ✅ | `project` / `component` |
185
+ | `component` | string | `scope=component` 时 ✅ | 组件 `code` |
186
+ | `values` | map | | `{ test: "...", prod: "" }`,键是环境节点 code |
187
+ | `secret` | bool | | 默认 `false` |
188
+ | `required` | string[] | | 如 `["prod"]`,表示这些环境必须由人填 |
189
+
190
+ 规则:
191
+
192
+ - **`secret: true` 时禁止出现 `values`**,连空字符串都不行——出现即 `secret_in_payload`。只留 key,值走 intake。
193
+ - `values` 的空字符串 = "未设置",不是"设为空"。平台据此区分"没配"和"配成空串"。
194
+ - `test` 可写非密默认值;`prod` 一律留空 + `required: ["prod"]`。
195
+ - 同一 key 在同一 scope 下重复 → `code_conflict`。
196
+
197
+ ---
198
+
199
+ ## 6. `resources[]`(配置模板)
200
+
201
+ | 字段 | 类型 | 必填 | 说明 |
202
+ |---|---|---|---|
203
+ | `rel_path` | string | ✅ | 环境内唯一路径,如 `config/app.yaml` |
204
+ | `kind` | enum | ✅ | `yaml` / `properties` / `compose` / `shell` / `other` |
205
+ | `component` | string | | 组件级资源才填;省略即项目级 |
206
+ | `from` | string | | 仓库内来源路径,仅用于溯源与审计 |
207
+ | `content` | string | ✅ | **模板正文**,占位符写成 `${VAR}` |
208
+ | `placeholders` | string[] | ✅ | 正文里出现的 `${VAR}`,平台据此校验 |
209
+ | `values` | map | | `{ test: true, prod: true }`,哪些环境下发 |
210
+
211
+ - `content` 由 Skill 读取仓库文件后内联;平台不 clone 仓库,别写"参考仓库里的 xxx"。
212
+ - `placeholders` 与实际 `${VAR}` 不一致 → `placeholders_unresolved`。
213
+ - `content` 里出现疑似真实密钥 → `secret_in_config_file`,**先整改仓库**,不要试图脱敏后上传。
214
+
215
+ ---
216
+
217
+ ## 7. `flows[]`
218
+
219
+ | 字段 | 类型 | 必填 | 默认 | 说明 |
220
+ |---|---|---|---|---|
221
+ | `env` | string | ✅ | — | 只能是环境树已有节点:`test` / `prod` |
222
+ | `target` | enum | ✅ | — | `existing`(插入已有流程)/ `new`(新建) |
223
+ | `name` | string | ✅ | — | 流程名,`existing` 时必须精确命中 |
224
+ | `action` | enum | ✅ | — | `insert` / `skip` |
225
+ | `strategy` | enum | | `deploy_sequence` | `deploy_sequence` / `deploy_parallel` |
226
+ | `template` | string | | `null` | 仅 `target=new` 时可覆盖模板名 |
227
+
228
+ - `env: staging` 之类 → `warning: env_unsupported`,降级为 `test`,plan 里明说。
229
+ - `target=existing` 但流程不存在 → `flow_not_found`(可自愈:改 `target: new`)。
230
+ - v1 只做"追加一条并行分支 + 检出复用",**不改既有节点**。
231
+
232
+ ---
233
+
234
+ ## 8. `acknowledge` / `verify`
235
+
236
+ `acknowledge` 必须覆盖 plan 返回的全部 `acknowledge_required[].code`,缺一个 → `ack_missing`,apply 拒绝。
237
+
238
+ 已知的 ack code:
239
+
240
+ | code | 触发 |
241
+ |---|---|
242
+ | `shared_repo` | 该 git 已被其他项目使用,用户仍要新建项目接入 |
243
+ | `config_value_changed:<KEY>` | 覆盖已有非密值 |
244
+ | `host_cred_override:<key>` | 复用主机上要把它已绑定的登录凭证换成另一把 |
245
+
246
+ `verify.build: true` 时 apply 成功后会先发布流程快照、再触发一次构建,返回 `verify: {env, flow, flow_id, flow_run_id, status, hint}` 与顶层 `flow_run_id`。
247
+
248
+ - `verify.env` 只能是 `test` / `prod`,缺省 `test`;`flows[]` 里必须有该环境的流程,否则 `verify.status=skipped`;
249
+ - `pre_build_blockers` 非空时不会触发(先把凭证 / 密钥补齐);
250
+ - `verify.status=failed` 不影响 `status=applied`,接入结果不回滚;处置见 `references/verify.md`。
251
+
252
+ 默认 `false`,构建验证交给 `/ease-ops:verify`。
253
+
254
+ ---
255
+
256
+ ## 9. 完整 JSON Schema
257
+
258
+ ```json
259
+ {
260
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
261
+ "title": "ease-ops onboarding payload v1",
262
+ "type": "object",
263
+ "additionalProperties": false,
264
+ "required": ["version", "repos", "components"],
265
+ "properties": {
266
+ "version": { "const": 1 },
267
+ "mode": { "enum": ["auto", "new_project", "add_component"], "default": "auto" },
268
+ "project": {
269
+ "type": "object",
270
+ "additionalProperties": false,
271
+ "properties": {
272
+ "strategy": { "enum": ["auto", "create", "use"], "default": "auto" },
273
+ "name": { "type": "string", "minLength": 1 },
274
+ "code": { "type": "string", "pattern": "^[a-z][a-z0-9-]{1,31}$" }
275
+ }
276
+ },
277
+ "repos": {
278
+ "type": "array", "minItems": 1,
279
+ "items": {
280
+ "type": "object", "additionalProperties": false,
281
+ "required": ["key", "url"],
282
+ "properties": {
283
+ "key": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,31}$" },
284
+ "url": { "type": "string", "minLength": 1 },
285
+ "branch": { "type": "string" },
286
+ "credential_ref": { "type": "string" },
287
+ "checkout_dir": { "type": "string" },
288
+ "origin": { "enum": ["root", "submodule", "nested"], "default": "root" }
289
+ }
290
+ }
291
+ },
292
+ "hosts": {
293
+ "type": "array",
294
+ "items": {
295
+ "type": "object", "additionalProperties": false,
296
+ "required": ["key", "ip"],
297
+ "properties": {
298
+ "key": { "type": "string", "pattern": "^[a-z][a-z0-9-]{0,31}$" },
299
+ "name": { "type": "string" },
300
+ "ip": { "type": "string", "minLength": 1 },
301
+ "port": { "type": "integer", "minimum": 1, "maximum": 65535, "default": 22 },
302
+ "credential_ref": { "type": "string" },
303
+ "description": { "type": "string" }
304
+ }
305
+ }
306
+ },
307
+ "components": {
308
+ "type": "array", "minItems": 1,
309
+ "items": {
310
+ "type": "object", "additionalProperties": false,
311
+ "required": ["code", "name", "repo_refs", "build"],
312
+ "properties": {
313
+ "code": { "type": "string", "pattern": "^[a-z][a-z0-9-]{1,47}$" },
314
+ "name": { "type": "string", "minLength": 1 },
315
+ "repo_refs": { "type": "array", "minItems": 1, "items": { "type": "string" } },
316
+ "work_dir": { "type": "string", "default": "." },
317
+ "languages": {
318
+ "type": "array",
319
+ "items": {
320
+ "enum": ["java", "go", "python", "javascript", "typescript", "ruby",
321
+ "php", "c", "swift", "rust", "react", "vue", "node", "unknown"]
322
+ }
323
+ },
324
+ "build": {
325
+ "type": "object", "additionalProperties": false,
326
+ "required": ["kind", "artifacts"],
327
+ "properties": {
328
+ "kind": { "enum": ["script", "docker"] },
329
+ "runtime": { "type": "string" },
330
+ "script": { "type": "string" },
331
+ "dockerfile": { "type": "string", "default": "./Dockerfile" },
332
+ "artifacts": {
333
+ "type": "array", "minItems": 1,
334
+ "items": {
335
+ "type": "object", "additionalProperties": false,
336
+ "required": ["name", "rules"],
337
+ "properties": {
338
+ "name": { "type": "string" },
339
+ "required": { "type": "boolean", "default": true },
340
+ "rules": {
341
+ "type": "array", "minItems": 1,
342
+ "items": {
343
+ "type": "object", "additionalProperties": false,
344
+ "required": ["patterns"],
345
+ "properties": {
346
+ "work_dir": { "type": "string", "default": "." },
347
+ "patterns": { "type": "array", "minItems": 1, "items": { "type": "string" } }
348
+ }
349
+ }
350
+ }
351
+ }
352
+ }
353
+ }
354
+ },
355
+ "allOf": [
356
+ {
357
+ "if": { "properties": { "kind": { "const": "script" } } },
358
+ "then": { "required": ["runtime", "script"] }
359
+ }
360
+ ]
361
+ },
362
+ "deploy": {
363
+ "type": "object", "additionalProperties": false,
364
+ "required": ["script", "targets"],
365
+ "properties": {
366
+ "script": { "type": "string", "minLength": 1 },
367
+ "start_command": { "type": "string" },
368
+ "stop_command": { "type": "string" },
369
+ "targets": {
370
+ "type": "array", "minItems": 1,
371
+ "items": {
372
+ "type": "object", "additionalProperties": false,
373
+ "oneOf": [
374
+ { "required": ["host_ref"], "properties": { "host_ref": { "type": "string", "minLength": 1 }, "scope": { "not": {} } } },
375
+ { "required": ["scope"], "properties": { "scope": { "const": "env" }, "host_ref": { "not": {} } } }
376
+ ]
377
+ }
378
+ }
379
+ }
380
+ }
381
+ }
382
+ }
383
+ },
384
+ "checkout_mode": { "enum": ["shared", "separate"], "default": "shared" },
385
+ "configs": {
386
+ "type": "array",
387
+ "items": {
388
+ "type": "object", "additionalProperties": false,
389
+ "required": ["key", "scope"],
390
+ "properties": {
391
+ "key": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" },
392
+ "scope": { "enum": ["project", "component"] },
393
+ "component": { "type": "string" },
394
+ "values": { "type": "object", "additionalProperties": { "type": "string" } },
395
+ "secret": { "type": "boolean", "default": false },
396
+ "required": { "type": "array", "items": { "type": "string" } }
397
+ },
398
+ "allOf": [
399
+ {
400
+ "if": { "properties": { "secret": { "const": true } }, "required": ["secret"] },
401
+ "then": { "not": { "required": ["values"] } }
402
+ }
403
+ ]
404
+ }
405
+ },
406
+ "resources": {
407
+ "type": "array",
408
+ "items": {
409
+ "type": "object", "additionalProperties": false,
410
+ "required": ["rel_path", "kind", "content", "placeholders"],
411
+ "properties": {
412
+ "rel_path": { "type": "string" },
413
+ "kind": { "enum": ["yaml", "properties", "compose", "shell", "other"] },
414
+ "component": { "type": "string" },
415
+ "from": { "type": "string" },
416
+ "content": { "type": "string" },
417
+ "placeholders": { "type": "array", "items": { "type": "string" } },
418
+ "values": { "type": "object", "additionalProperties": { "type": "boolean" } }
419
+ }
420
+ }
421
+ },
422
+ "flows": {
423
+ "type": "array",
424
+ "items": {
425
+ "type": "object", "additionalProperties": false,
426
+ "required": ["env", "target", "name", "action"],
427
+ "properties": {
428
+ "env": { "type": "string" },
429
+ "target": { "enum": ["existing", "new"] },
430
+ "name": { "type": "string", "minLength": 1 },
431
+ "action": { "enum": ["insert", "skip"] },
432
+ "strategy": { "enum": ["deploy_sequence", "deploy_parallel"], "default": "deploy_sequence" },
433
+ "template": { "type": ["string", "null"] }
434
+ }
435
+ }
436
+ },
437
+ "acknowledge": { "type": "array", "items": { "type": "string" } },
438
+ "verify": {
439
+ "type": "object", "additionalProperties": false,
440
+ "properties": {
441
+ "build": { "type": "boolean", "default": false },
442
+ "env": { "type": "string", "default": "test" }
443
+ }
444
+ }
445
+ }
446
+ }
447
+ ```
448
+
449
+ ---
450
+
451
+ ## 10. 正例
452
+
453
+ ### 10.1 场景 1:前后端同仓(monorepo → 两个组件共用一次检出)
454
+
455
+ ```yaml
456
+ version: 1
457
+ mode: new_project
458
+ project: { strategy: create, name: 商城, code: shop }
459
+ repos:
460
+ - { key: shop, url: git@github.com:acme/shop.git, branch: main,
461
+ credential_ref: platform:git-acme-ro, checkout_dir: shop, origin: root }
462
+ components:
463
+ - code: shop-web
464
+ name: 商城前端
465
+ repo_refs: [shop]
466
+ work_dir: ./web
467
+ languages: [typescript]
468
+ build:
469
+ kind: script
470
+ runtime: node-20
471
+ script: npm ci && npm run build
472
+ artifacts:
473
+ - { name: dist, required: true, rules: [{ work_dir: ".", patterns: ["dist/**"] }] }
474
+ - code: shop-api
475
+ name: 商城后端
476
+ repo_refs: [shop]
477
+ work_dir: ./api
478
+ languages: [go]
479
+ build:
480
+ kind: script
481
+ runtime: go-1.23
482
+ script: go build -o bin/api ./cmd/api
483
+ artifacts:
484
+ - { name: api-binary, required: true, rules: [{ work_dir: bin, patterns: ["**/*"] }] }
485
+ checkout_mode: shared
486
+ configs:
487
+ - { key: DB_HOST, scope: project, values: { test: 10.0.0.5 } }
488
+ - { key: DB_PASSWORD, scope: project, secret: true, required: [prod] }
489
+ - { key: VITE_API_BASE, scope: component, component: shop-web,
490
+ values: { test: "http://test-api", prod: "https://api" } }
491
+ resources:
492
+ - rel_path: config/app.yaml
493
+ kind: yaml
494
+ component: shop-api
495
+ from: ./api/config/app.yaml
496
+ content: |
497
+ db:
498
+ host: ${DB_HOST}
499
+ password: ${DB_PASSWORD}
500
+ placeholders: [DB_HOST, DB_PASSWORD]
501
+ values: { test: true, prod: true }
502
+ flows:
503
+ - { env: test, target: existing, name: 商城测试流水线, action: insert, strategy: deploy_sequence }
504
+ acknowledge: []
505
+ verify: { build: false, env: test }
506
+ ```
507
+
508
+ ### 10.2 场景 2:已有项目加一个组件并插入流程
509
+
510
+ ```yaml
511
+ version: 1
512
+ mode: add_component
513
+ project: { strategy: use, code: shop }
514
+ repos:
515
+ - { key: shop, url: git@github.com:acme/shop.git, branch: main,
516
+ credential_ref: platform:git-acme-ro }
517
+ components:
518
+ - code: shop-worker
519
+ name: 商城任务worker
520
+ repo_refs: [shop]
521
+ work_dir: ./services/worker
522
+ languages: [go]
523
+ build:
524
+ kind: script
525
+ runtime: go-1.23
526
+ script: go build -o bin/worker ./cmd/worker
527
+ artifacts:
528
+ - { name: worker-binary, required: true, rules: [{ work_dir: bin, patterns: ["**/*"] }] }
529
+ checkout_mode: shared
530
+ flows:
531
+ - { env: test, target: existing, name: 商城测试流水线, action: insert, strategy: deploy_parallel }
532
+ acknowledge: []
533
+ ```
534
+
535
+ ### 10.3 多仓:后端 + 独立前端仓库
536
+
537
+ ```yaml
538
+ version: 1
539
+ mode: new_project
540
+ project: { strategy: create, name: 商城, code: shop }
541
+ repos:
542
+ - { key: api, url: git@github.com:acme/shop-api.git, branch: main, credential_ref: platform:git-acme-ro }
543
+ - { key: web, url: git@github.com:acme/shop-web.git, branch: main, credential_ref: platform:git-acme-ro }
544
+ components:
545
+ - code: shop-api
546
+ name: 商城后端
547
+ repo_refs: [api]
548
+ work_dir: .
549
+ languages: [go]
550
+ build:
551
+ kind: script
552
+ runtime: go-1.23
553
+ script: go build -o bin/api ./cmd/api
554
+ artifacts: [{ name: api-binary, rules: [{ work_dir: bin, patterns: ["**/*"] }] }]
555
+ - code: shop-web
556
+ name: 商城前端
557
+ repo_refs: [web]
558
+ work_dir: .
559
+ languages: [node]
560
+ build:
561
+ kind: script
562
+ runtime: node-20
563
+ script: npm ci && npm run build
564
+ artifacts: [{ name: dist, rules: [{ patterns: ["dist/**"] }] }]
565
+ checkout_mode: separate
566
+ ```
567
+
568
+ ### 10.4 最小 payload:只接组件,不碰流程和配置
569
+
570
+ ```yaml
571
+ version: 1
572
+ repos:
573
+ - { key: demo, url: git@github.com:acme/demo.git }
574
+ components:
575
+ - code: demo-api
576
+ name: Demo
577
+ repo_refs: [demo]
578
+ build:
579
+ kind: docker
580
+ dockerfile: ./Dockerfile
581
+ artifacts: [{ name: image, rules: [{ patterns: ["Dockerfile"] }] }]
582
+ ```
583
+
584
+ ### 10.5 接入 + 部署到两台机器(前后端共用同一批机器、同一把登录凭证)
585
+
586
+ ```yaml
587
+ version: 1
588
+ mode: add_component
589
+ project: { strategy: use, code: shop }
590
+ repos:
591
+ - { key: shop, url: git@github.com:acme/shop.git, branch: main, credential_ref: platform:git-acme-ro }
592
+ hosts:
593
+ - { key: app-1, ip: 10.0.0.11, credential_ref: project:ssh-shop }
594
+ - { key: app-2, ip: 10.0.0.12, port: 2222, credential_ref: project:ssh-shop }
595
+ components:
596
+ - code: shop-api
597
+ name: 商城后端
598
+ repo_refs: [shop]
599
+ work_dir: ./api
600
+ languages: [go]
601
+ build:
602
+ kind: script
603
+ runtime: go-1.23
604
+ script: go build -o bin/api ./cmd/api
605
+ artifacts:
606
+ - { name: api-binary, rules: [{ work_dir: bin, patterns: ["**/*"] }] }
607
+ deploy:
608
+ script: |
609
+ set -euo pipefail
610
+ rsync -avc {{artifact:api-binary}}/ /opt/shop/bin/
611
+ stop_command: systemctl stop shop-api # 推断值,待用户复核
612
+ start_command: systemctl start shop-api && curl -fsS http://127.0.0.1:8080/health
613
+ targets: [ { host_ref: app-1 }, { host_ref: app-2 } ]
614
+ - code: shop-cron
615
+ name: 定时任务
616
+ repo_refs: [shop]
617
+ work_dir: ./cron
618
+ languages: [go]
619
+ build:
620
+ kind: script
621
+ runtime: go-1.23
622
+ script: go build -o bin/cron ./main.go
623
+ artifacts:
624
+ - { name: cron-binary, rules: [{ patterns: ["bin/cron"] }] }
625
+ # 没有 deploy 段:只构建打包
626
+ checkout_mode: shared
627
+ flows:
628
+ - { env: test, target: existing, name: 商城测试流水线, action: insert }
629
+ acknowledge: []
630
+ ```
631
+
632
+ 这个形态里四件事值得注意:产物都没写 `required: true`(都是推断值);两台机器共用一把 `project:ssh-shop`,密值走 intake 不进 payload;`shop-cron` 不部署;`deploy.script` 里的 `/opt/shop/bin/` 与 `start_command` 里的服务名都是推断值,要进待复核清单。
633
+
634
+ ---
635
+
636
+ ## 11. 反例(平台会拒绝)
637
+
638
+ | 反例 | 错误码 | 正确写法 |
639
+ |---|---|---|
640
+ | `configs: [{key: DB_PASSWORD, secret: true, values: {prod: "hunter2"}}]` | `secret_in_payload` | 删掉 `values`,留 `required: [prod]` |
641
+ | `runtime: 12`(镜像是数字 ID) | `platform_id_forbidden` | `runtime: go-1.23` |
642
+ | `targets: [{host_id: 7}]` | `platform_id_forbidden` | `targets: [{host_ref: "app-1"}]`,主机在 `hosts[]` 里声明 |
643
+ | `deploy: {enabled: false}` | `unknown_field` | 只构建打包就删掉整段 `deploy` |
644
+ | `deploy: {targets: [{host_ref: app-1}]}`(没有 `script`) | `deploy_script_required` | 补 `script`:至少一条 `rsync -avc {{artifact:<name>}}/ <目标目录>/` |
645
+ | `deploy: {status_command: ...}` | `unknown_field` | 1.3.0 已删除;健康检查写进 `start_command` 末尾 |
646
+ | `script: rsync -avc {{artifact:api}}/ ...`(工件叫 `api-binary`) | `deploy_artifact_unknown` | 引用名必须与 `build.artifacts[].name` 一致 |
647
+ | `script: rsync -avc {{conf:config}}/ ...`(模板是 `conf/app.yaml`) | `deploy_conf_unknown` | `{{conf:}}` 的 key 用 `rel_path` 首段,这里是 `conf` |
648
+ | `deploy: {targets: [{host_ref: app-1, scope: env}]}` | `schema_invalid` | 两者互斥:要么列主机,要么 `[{scope: env}]` |
649
+ | `hosts: [{key: app-1, ip: "10.0.0.11:22"}]` | `schema_invalid` | 端口写在 `port: 22`,`ip` 只放地址 |
650
+ | `repos: [{url: "/srv/shop"}]` | `repo_remote_required` | 换成真实远程地址;本地目录接不进平台 |
651
+ | `work_dir: ../shop-web`(指向非主仓库) | `work_dir_not_found` | 组件只在自己主仓库内取目录 |
652
+ | `flows: [{env: staging, ...}]` | `warning: env_unsupported` | `env: test` |
653
+ | `build: {kind: script, script: "make build"}`(缺 runtime) | `runtime_required` | 补 `runtime: <逻辑名>` |
654
+ | `languages: [cpp]` | `schema_invalid`(枚举不匹配) | `c`(C/C++ 统一记 `c`) |
655
+ | `configs: [{key: db.host, scope: project}]` | `config_key_invalid`(格式不符) | `DB_HOST` |
656
+ | `repos: [{url: ...}]`(缺 key) | `schema_invalid`(缺必填) | 补 `key` |
657
+
658
+ ---
659
+
660
+ ## 12. 幂等
661
+
662
+ | 对象 | 幂等键 |
663
+ |---|---|
664
+ | 仓库 | `repos[].url` 归一化值 |
665
+ | 主机 | `project` + `ip` + `port`(与平台主机查重同一把) |
666
+ | 主机凭证绑定 | `host` + `auth_mode`(已有绑定不覆盖,除非用户已 ack override) |
667
+ | 主机环境绑定 | `env` + `host`(只新增,从不删已有绑定) |
668
+ | 项目 | `project.code` |
669
+ | 组件 | `project.code` + `component.code` |
670
+ | 运行时镜像 | 逻辑名 + `scope` |
671
+ | 环境变量 | `env` + `scope` + `component` + `key` |
672
+ | 配置资源 | `env` + `rel_path` |
673
+ | 流程插入 | `env` + `flow.name` |
674
+
675
+ 同一份 payload 连续 plan 两次,第二次只应产出 `reuse` / `update` / `skip`;出现新的 `create` 说明幂等键没对上,要查 payload 而不是重跑 apply。
676
+
677
+ ---
678
+
679
+ ## 13. 四个容易判断错的点
680
+
681
+ | 场景 | 判断 |
682
+ |---|---|
683
+ | 前后端同仓、同一个 `package.json` 顶层 | 仍是两个组件:`work_dir` 分别是 `./web` `./api`,`checkout_mode: shared` |
684
+ | 前端仓 + 后端仓,业务上是一个系统 | 两个 `repos`,两个组件,各自 `repo_refs`,`checkout_mode: separate` |
685
+ | 仓库里有 `docker-compose.yml` 但没有 Dockerfile | 不是 docker 构建;按 `script` 构建,compose 只作为 `resources[]` 的模板素材 |
686
+ | 用户说"用最新版 node" | 不写 `node`(无 tag),写 `node-20` 这类逻辑名;无法判断时先 `list_runtime_images` 查目录 |