feat: add desired-state deploy reconciler

This commit is contained in:
Codex
2026-05-16 07:58:39 +00:00
parent 0c3cdb4ee0
commit e841c929cf
11 changed files with 1209 additions and 691 deletions
+6 -5
View File
@@ -1,10 +1,11 @@
# Code Queue Deploy
`bun scripts/cli.ts codex deploy <commitId>` D601 Code Queue 的正式部署入口。命令只在主 server 工作区执行;它会立即返回异步 job id,后台 job 通过 backend-core 的 `host.ssh` dispatch 在 D601 完成实际部署。
`bun scripts/cli.ts codex deploy <commitId>`兼容入口。新的正式部署入口是 `bun scripts/cli.ts deploy apply --service code-queue`;兼容入口会生成一个只包含 Code Queue repo 与 commit 的临时 desired manifest,再调用同一个 deploy reconciler。命令只在主 server 工作区执行;它会立即返回异步 job id,后台 job 通过 backend-core 的 `host.ssh` dispatch 在 D601 完成实际部署。
## Command
```bash
bun scripts/cli.ts deploy apply --service code-queue
bun scripts/cli.ts codex deploy <commitId>
bun scripts/cli.ts job status <jobId> --tail-bytes 30000
```
@@ -12,15 +13,15 @@ bun scripts/cli.ts job status <jobId> --tail-bytes 30000
- `commitId` 必须是已经 push 到 remote 的 7-40 位 hex commit SHA。
- `--provider-id D601` 是默认值;当前部署路径只支持 D601 active instance。
- `--timeout-ms N` 控制后台部署总超时,默认 `900000`
- `--skip-build` 只用于已确认目标镜像已在 D601 Docker 和 k3s containerd 中存在的诊断场景;正式部署默认必须构建镜像
- `--skip-build` 不再支持;target-side Docker build 是强制步骤
## Pipeline
部署 job 的步骤固定为:
1. 在 D601 `/home/ubuntu/unidesk``git fetch` remote,并用 `git archive <commitId>` 导出 tracked files 到 `/tmp/unidesk-codex-deploy-src-*`
1. 在 D601 的 deploy cache`git fetch` remote,并用 `git archive <commitId>` 导出 tracked files 到一次性 export 目录
2.`rsync --delete` 同步导出的 repo 到 `/home/ubuntu/cq-deploy`,保留 `.state/``logs/``.git/``node_modules/``dist/`
3.`/home/ubuntu/cq-deploy` 构建 `unidesk-code-queue:d601`
3.D601 用目标 Docker daemon 的本地 BuildKit builder 构建 `unidesk-code-queue:d601`,复用 D601 上已有基础镜像和 layer cacheprovider-gateway egress proxy 只作为本次 build 的环境变量与 build-arg 注入,并配合本次 build 的 `--network host` 让 RUN 阶段访问 D601 宿主 loopback proxy,不能污染 D601 宿主 Docker/HTTP proxy 配置
4. `docker save` 镜像并导入 k3s containerd`docker exec -i unidesk-v8s-server ctr -n k8s.io images import -`
5. `kubectl apply -f src/components/microservices/v3sctl-adapter/v3s/code-queue.k8s.yaml`,其中包含 Code Queue 和 `d601-tcp-egress-gateway`
6. 将解析后的 40 位 remote commit 写入 `deployment/code-queue``CODE_QUEUE_DEPLOY_COMMIT` / `CODE_QUEUE_DEPLOY_REQUESTED_COMMIT`,并记录到 Deployment annotation。
@@ -29,7 +30,7 @@ bun scripts/cli.ts job status <jobId> --tail-bytes 30000
## Observability
`codex deploy` 本身不阻塞等待部署结束。返回 JSON 中的 `statusCommand``tailCommand` 是唯一状态入口。后台 job 的 stderr 是 JSONL progress,每个长步骤会记录远端 `/tmp/unidesk-codex-deploy-*.log` 和 sentinel 文件;失败时 `job status` 会显示最后日志尾部。
`codex deploy` 本身不阻塞等待部署结束。返回 JSON 中的 `statusCommand``tailCommand` 是唯一状态入口。后台 job 的 stderr 是 JSONL progress,每个长步骤会记录远端 `/tmp/unidesk-deploy-*.log` 和 sentinel 文件;失败时 `job status` 会显示最后日志尾部。
`job status``succeeded` 时,部署 job 已经完成 live commit 验证。需要人工复核时可用以下命令确认 `deploy.commit`