Files
devos/Docs/DevOS-Platform-v2/34_DEPLOYMENT_INFRASTRUCTURE_RUNTIME.md
phptits 851ccf1d7f v2 platform runtime (docs 22 Phase 2/4/7 + 17): Project/Environment + Config + Storage + Observability
- Project/Environment model with default environments (dev/staging/prod)
- Config Runtime: cascade resolution (platform→org→project→env), secrets via vault
- Storage Runtime: local provider, sha256 dedup, integrity check, file list/upload/delete
- Observability: execution query, per-action summary (success rate, avg, p95), health
- Realtime SSE: workspace event stream endpoint (GET /api/v1/v2/realtime/events)
- Phase 1 acceptance: core.health.check, core.user.create, core.user.list
- Actions: core.project.*, core.config.*, core.file.*, core.user.* (62 total)
2026-09-11 21:11:07 +00:00

5813 lines
54 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# DevOS Deployment & Infrastructure Runtime
> Version: 1.0
> Status: Architecture Specification
> Scope: Deployment / Infrastructure / Runtime Environment / Server / Container / CI/CD / Health / Rollback
> Depends On: 01–33
> Project: `/home/dev/bun/devos`
---
# 1. 文档目标
本文定义 DevOS Deployment & Infrastructure Runtime。
核心目标:
> 让 DevOS 能够统一管理项目从“构建”到“部署”再到“运行、监控、升级、回滚”的完整生命周期。
最终链路:
```text
Project
↓
Build
↓
Artifact
↓
Deployment Plan
↓
Environment
↓
Infrastructure Provider
↓
Deploy
↓
Runtime Instance
↓
Health
↓
Observability
↓
Upgrade / Rollback
```
---
# 2. Deployment Runtime 定位
Deployment Runtime 不是:
- Docker CLI 的包装器
- SSH 脚本集合
- Kubernetes Dashboard
- 云厂商 SDK 集合
- CI/CD 脚本目录
它是:
> **DevOS 对“项目如何被部署、在哪里运行、如何升级和恢复”的统一抽象。**
---
# 3. 核心模型
核心对象:
```text
Project
Environment
Deployment
DeploymentPlan
DeploymentTarget
Artifact
RuntimeInstance
Service
Infrastructure
Provider
HealthCheck
Release
DeploymentStrategy
Rollback
```
关系:
```text
Project
↓
Environment
↓
Deployment Plan
↓
Artifact
↓
Deployment Target
↓
Runtime Instance
↓
Health
```
---
# 4. Deployment 与 Infrastructure 的区别
必须明确:
```text
Deployment
=
把应用发布到某个运行环境
```
而:
```text
Infrastructure
=
提供运行应用所需要的基础资源
```
例如:
```text
Infrastructure:
Server
Container
Network
Database
Object Storage
DNS
Load Balancer
Deployment:
把 my-app:v1.4.0 发布到 server-01
```
---
# 5. Provider
基础设施不能写死。
例如:
```text
Docker
SSH
AWS
Cloudflare
Kubernetes
Hetzner
DigitalOcean
Vercel
```
都应该通过:
```text
Provider Runtime
```
接入。
---
# 6. Provider Runtime
统一:
```ts
interface InfrastructureProvider {
id: string;
capabilities(): ProviderCapability[];
validate(
context: ProviderContext
): Promise<ValidationResult>;
plan(
request: DeploymentRequest
): Promise<DeploymentPlan>;
deploy(
plan: DeploymentPlan
): Promise<DeploymentResult>;
health(
target: DeploymentTarget
): Promise<HealthResult>;
destroy(
target: DeploymentTarget
): Promise<DestroyResult>;
}
```
---
# 7. Provider 不拥有 Deployment Runtime
Provider 只负责:
```text
实际基础设施操作
```
不能自己创建:
```text
Task Runtime
Event Runtime
Secret Runtime
Audit Runtime
```
统一使用 DevOS Runtime。
---
# 8. Deployment Architecture
```text
User / Agent / CI / CLI
↓
Security Context
↓
Deployment API
↓
Deployment Runtime
↓
Deployment Plan
↓
Provider Resolver
↓
Infrastructure Provider
↓
Infrastructure
↓
Runtime Instance
```
---
# 9. Deployment Action
部署本身是 Action:
```text
deployment.create
deployment.plan
deployment.deploy
deployment.cancel
deployment.rollback
deployment.restart
deployment.scale
deployment.destroy
```
进入:
```text
Action Runtime
```
---
# 10. Deployment 不直接执行
错误:
```text
Controller
↓
ssh
↓
docker run
```
正确:
```text
API
↓
Action
↓
Action Runtime
↓
Deployment Runtime
↓
Provider
↓
Task
↓
Execution
```
---
# 11. Deployment Plan
部署必须先 Plan:
```text
Project
↓
Artifact
↓
Environment
↓
Provider
↓
Deployment Plan
```
Plan 应包含:
```text
Artifact
Target
Environment
Services
Config
Secret References
Network
Health Checks
Strategy
Rollback
Resource Requirements
```
---
# 12. Plan / Apply
必须支持:
```bash
devos deploy plan
```
以及:
```bash
devos deploy apply
```
原则:
> **Plan 与 Apply 分离。**
---
# 13. Dry Run
支持:
```bash
devos deploy apply --dry-run
```
输出:
```text
Target:
production/server-01
Artifact:
my-app:1.4.0
Services:
api
worker
web
Changes:
+ api container
~ worker image
~ web image
Database:
migration pending
Risk:
HIGH
```
---
# 14. Environment
Deployment 永远属于:
```text
Environment
```
例如:
```text
development
staging
production
```
环境来自:
```text
Environment Runtime
```
不是 Deployment 自己创建一套环境系统。
---
# 15. Environment 隔离
必须:
```text
development
≠
staging
≠
production
```
至少隔离:
```text
Config
Secret
Credential
Provider
Database
Storage
Network
Deployment
Task
```
---
# 16. Production Guard
Production 默认:
```text
protected = true
```
高风险操作:
```text
Deploy
Destroy
Database Migration
Rollback
Credential Change
Infrastructure Change
```
可以要求:
```text
Approval Runtime
```
---
# 17. Deployment Target
Target 表示:
> 项目最终运行在哪里。
例如:
```text
server-01
docker-host-02
k8s-cluster-a
aws-ecs-prod
```
---
# 18. Target Schema
```ts
interface DeploymentTarget {
id: string;
organizationId: string;
providerId: string;
type: string;
environmentId: string;
region?: string;
metadata: Record<string, unknown>;
}
```
---
# 19. Runtime Instance
Deployment Target 是:
```text
目标
```
Runtime Instance 是:
```text
实际运行实例
```
例如:
```text
Target:
server-01
Instances:
api-01
worker-01
web-01
```
---
# 20. Service
一个 Project 可以包含多个 Service:
```yaml
services:
api:
type: web
worker:
type: worker
agent:
type: agent
web:
type: frontend
```
---
# 21. Service 与 Project
Project:
```text
业务项目
```
Service:
```text
运行单元
```
例如:
```text
SEO Agent Project
├── web
├── api
├── worker
└── agent
```
---
# 22. Service Definition
```ts
interface ServiceDefinition {
id: string;
projectId: string;
type: ServiceType;
artifact: ArtifactReference;
replicas: number;
ports?: PortDefinition[];
resources?: ResourceRequirements[];
healthCheck?: HealthCheckDefinition;
}
```
---
# 23. Service Types
初始:
```text
web
api
worker
agent
scheduler
mcp
cron
frontend
```
不要过度细分。
---
# 24. Artifact
Deployment 不应该直接从源码部署。
正确:
```text
Source
↓
Build
↓
Artifact
↓
Deploy
```
Artifact 通过:
```text
Artifact Runtime
```
管理。
---
# 25. Artifact Examples
```text
Docker Image
npm Package
Static Bundle
Tarball
Binary
Server Bundle
```
Artifact 必须记录:
```text
ID
Version
Checksum
Build
Project
Source Revision
CreatedAt
```
---
# 26. Build 与 Deployment
Build:
```text
产生 Artifact
```
Deployment:
```text
发布 Artifact
```
不要把两者混成:
```text
deploy.ts
```
---
# 27. Release
Release 是:
> 某个 Project 在某个版本下的一组可部署 Artifact。
例如:
```text
Release 1.4.0
api: image-a
worker: image-b
web: image-c
```
---
# 28. Release Schema
```ts
interface Release {
id: string;
projectId: string;
version: string;
sourceRevision?: string;
artifacts: ArtifactReference[];
createdAt: Date;
}
```
---
# 29. Immutable Release
Release 一旦发布:
```text
1.4.0
```
不应该修改成另一个内容。
如果代码变化:
```text
1.4.1
```
或者:
```text
1.4.0+build2
```
具体策略由版本 Runtime 决定。
---
# 30. Reproducible Deployment
生产部署必须尽量:
```text
Release
+
Environment
+
Config Snapshot
```
决定实际运行内容。
不能:
```text
deploy latest
```
---
# 31. 禁止 latest
生产环境禁止:
```text
image: latest
```
应该:
```text
image: my-app@sha256:...
```
或者:
```text
release: 1.4.0
artifactChecksum: ...
```
---
# 32. Deployment Lock
Deployment 应记录:
```text
DevOS Version
Project Version
Release Version
Artifact Version
Plugin Versions
Module Versions
Config Version
Provider Version
```
这样可以回答:
> 这个生产实例到底运行了什么?
---
# 33. Configuration
Deployment 配置来自:
```text
Configuration Runtime
```
例如:
```text
DATABASE_URL
LOG_LEVEL
PUBLIC_URL
MODEL
WORKER_CONCURRENCY
```
但业务代码不能:
```ts
process.env.DATABASE_URL
```
直接读取。
---
# 34. Secret
Secret 来自:
```text
Secret Runtime
```
Deployment 只能引用:
```text
secret://production/database
```
不能保存:
```text
password: "xxxxx"
```
---
# 35. Credential
Provider 认证使用:
```text
Credential Runtime
```
例如:
```text
AWS Credential
GitHub Credential
Cloudflare Credential
SSH Credential
Docker Registry Credential
```
Deployment 不直接读取 Credential 数据库。
---
# 36. Network
网络配置属于:
```text
Network Runtime
```
至少抽象:
```text
Port
DNS
Domain
TLS
Firewall
Private Network
Public Network
```
第一阶段可以提供:
```text
Docker Network
SSH Host
HTTP Endpoint
DNS Provider
```
---
# 37. Domain
Domain 例如:
```text
api.example.com
```
可以绑定:
```text
Service
Deployment
Environment
```
通过:
```text
DNS Provider
```
实现。
---
# 38. TLS
TLS 可以由:
```text
Provider
```
提供。
例如:
```text
Let's Encrypt
Cloudflare
Managed Certificate
```
Deployment Runtime 只描述:
```text
TLS Required
```
---
# 39. Health Check
部署完成不代表成功。
必须:
```text
Deploy
↓
Start
↓
Health Check
↓
Ready
```
---
# 40. Health Types
至少:
```text
Process Health
HTTP Health
TCP Health
Container Health
Dependency Health
Application Health
```
---
# 41. Readiness
服务:
```text
running
```
不代表:
```text
ready
```
例如:
```text
Database Migration
Loading Model
Warming Cache
```
期间:
```text
running = true
ready = false
```
---
# 42. Health Runtime
复用:
```text
Health Runtime
```
统一:
```text
liveness
readiness
dependency
health
```
---
# 43. Deployment State
建议:
```text
pending
planning
approved
deploying
starting
health_checking
ready
failed
rolling_back
rolled_back
cancelled
destroying
destroyed
```
---
# 44. Deployment State Machine
```text
pending
↓
planning
↓
approved
↓
deploying
↓
starting
↓
health_checking
↓
ready
```
失败:
```text
deploying
↓
failed
↓
rollback
```
---
# 45. Deployment Task
部署属于 Task:
```text
Deployment
↓
Task
↓
Jobs
```
例如:
```text
Pull Artifact
Prepare
Stop Old
Start New
Health Check
Switch Traffic
Cleanup
```
---
# 46. Worker
Deployment Job:
```text
Queue
↓
Worker
```
Worker 执行:
```text
Provider Action
```
而不是:
```text
Deployment Runtime
```
自己创建 worker。
---
# 47. Deployment Timeout
每一步必须有:
```text
timeout
```
例如:
```text
Pull Image: 5m
Start Container: 2m
Health Check: 3m
Migration: 10m
```
避免:
```text
Deployment hanging forever
```
---
# 48. Deployment Cancellation
支持:
```bash
devos deploy cancel <id>
```
但取消必须区分:
```text
Safe Cancellation
Unsafe Cancellation
```
例如:
```text
Pull Image
```
可以取消。
而:
```text
Database Migration
```
可能只能:
```text
Wait
```
或者:
```text
Rollback
```
---
# 49. Deployment Strategy
初始支持:
```text
recreate
rolling
blue-green
canary
```
第一阶段:
```text
recreate
rolling
```
优先。
---
# 50. Recreate
```text
Old
↓
Stop
↓
New
```
优点:
```text
Simple
```
缺点:
```text
Downtime
```
---
# 51. Rolling
```text
Old × N
↓
New × 1
↓
Health
↓
New × 2
↓
...
```
必须:
```text
Health Check
```
通过后才能继续。
---
# 52. Blue-Green
```text
Blue = Current
Green = New
Deploy Green
↓
Health
↓
Switch Traffic
↓
Blue remains
```
适合:
```text
Production
```
但第一阶段可以先作为抽象,不必立即完整实现。
---
# 53. Canary
```text
95% Old
5% New
```
然后:
```text
Metrics
↓
Health
↓
Increase
```
这是后续增强能力。
---
# 54. Traffic Switch
流量切换通过:
```text
Load Balancer
Reverse Proxy
DNS
Service Mesh
Provider
```
实现。
Deployment Runtime 不应该自己实现所有网络层。
---
# 55. Rollback
Rollback 不是:
```text
git checkout
```
而是:
> 将 Deployment 恢复到一个已知的 Release。
例如:
```text
Current:
1.5.0
Rollback:
1.4.2
```
---
# 56. Rollback Preconditions
必须确认:
```text
Artifact Exists
Config Compatible
Database Compatible
Plugin Compatible
Provider Available
```
否则:
```text
Rollback Blocked
```
---
# 57. Database Migration 与 Rollback
最危险的是:
```text
App Upgrade
+
Database Migration
```
例如:
```text
v1
column A
v2
column B
```
直接回滚代码:
```text
v2 → v1
```
可能失败。
所以 Migration 必须支持:
```text
Expand
Migrate
Contract
```
策略。
---
# 58. Expand / Contract
推荐:
```text
Release N
↓
Add new field
↓
Release N+1
↓
Use new field
↓
Release N+2
↓
Remove old field
```
避免:
```text
One-step destructive migration
```
---
# 59. Deployment Rollback Plan
每次生产部署前生成:
```text
Rollback Plan
```
包括:
```text
Previous Release
Previous Config
Database Compatibility
Traffic Strategy
Artifact
```
---
# 60. Deployment Approval
生产:
```text
Deployment Plan
↓
Risk Evaluation
↓
Approval
↓
Apply
```
高风险项:
```text
Database Migration
Permission Change
Secret Change
Infrastructure Destruction
```
必须更加严格。
---
# 61. Risk Level
部署风险:
```text
low
medium
high
critical
```
例如:
```text
Frontend only:
low
API:
medium
Database Migration:
high
Production Destruction:
critical
```
---
# 62. Deployment Policy
可以配置:
```yaml
production:
requireApproval: true
highRisk:
requireApproval: true
critical:
requireTwoPersonApproval: true
```
最终由:
```text
Policy Runtime
```
执行。
---
# 63. CI/CD
CI/CD 不是独立 Runtime。
它应该调用:
```text
Project Factory
Build Runtime
Artifact Runtime
Deployment Runtime
Task Runtime
```
---
# 64. CI Pipeline
推荐:
```text
Git Push
↓
CI
↓
Test
↓
Build
↓
Artifact
↓
Release
↓
Deployment Plan
↓
Approval
↓
Deploy
```
---
# 65. Git Provider
GitHub/GitLab/Bitbucket:
```text
Plugin
```
负责:
```text
Repository
Webhook
Commit
Pull Request
Release
```
---
# 66. CI Provider
第一阶段不要自己实现:
```text
GitHub Actions
GitLab CI
Jenkins
```
统一抽象:
```text
CIRuntime
```
后续通过 Provider 接入。
---
# 67. Deployment Trigger
支持:
```text
Manual
Git Push
Tag
Release
Webhook
Schedule
Agent
Workflow
```
都进入:
```text
Event Runtime
```
然后:
```text
Event
↓
Workflow / Deployment Action
```
---
# 68. Git Push
例如:
```text
push main
```
产生:
```text
git.push
```
然后:
```text
Workflow
↓
Build
↓
Release
↓
Deploy Staging
```
生产:
```text
Approval
```
---
# 69. Scheduled Deployment
可以:
```text
每周日凌晨部署
```
但 Scheduler 仍然是:
```text
Scheduler Runtime
```
Deployment Runtime 不创建第二套 Cron。
---
# 70. Agent Deployment
Agent 可以提出:
> 将 staging 上当前 release 部署到 production。
Agent:
```text
Goal
↓
Capability Discovery
↓
deployment.plan
↓
Risk
↓
Approval
↓
deployment.deploy
```
Agent 不可以:
```text
ssh root
```
直接部署。
---
# 71. MCP Deployment
MCP 可以提供:
```text
deployment.plan
deployment.status
deployment.deploy
deployment.rollback
```
但:
```text
MCP
↓
Action Runtime
```
不能:
```text
MCP
↓
Docker Socket
```
---
# 72. SSH Provider
SSH 是基础设施 Provider。
可以:
```text
Connect
Execute Allowed Command
Upload
Download
Check Health
```
但必须:
```text
Credential Runtime
Security Runtime
Audit Runtime
```
---
# 73. SSH Security
禁止默认:
```text
root
password auth
unrestricted shell
```
优先:
```text
SSH Key
Limited User
Command Policy
Network Policy
Audit
```
---
# 74. Docker Provider
Docker Provider 可以:
```text
Image Pull
Container Create
Container Start
Container Stop
Container Remove
Network
Volume
Health
```
但:
```text
Docker Provider
```
不拥有:
```text
Deployment State
Task Queue
Audit
Secret
```
---
# 75. Docker Socket
生产环境:
```text
Docker Socket
```
属于高权限资源。
不能:
```text
Plugin
Agent
MCP
```
直接访问。
只有:
```text
Infrastructure Provider
```
在受控权限下使用。
---
# 76. Kubernetes Provider
后续支持:
```text
Kubernetes
```
但不要第一阶段直接把 Kubernetes API 暴露给:
```text
Agent
Plugin
MCP
```
必须:
```text
Deployment Action
↓
Kubernetes Provider
```
---
# 77. Infrastructure Resource
未来可以统一抽象:
```text
Server
Container
Volume
Network
Database
Bucket
DNS
Certificate
LoadBalancer
```
这些属于:
```text
Infrastructure Resource
```
---
# 78. Infrastructure Resource 与业务 Resource
不要混淆。
```text
seo.website
```
是:
```text
Business Resource
```
而:
```text
server-01
```
是:
```text
Infrastructure Resource
```
但两者都可以遵循:
```text
Resource → Action → Runtime
```
---
# 79. Infrastructure Actions
例如:
```text
infra.server.create
infra.server.start
infra.server.stop
infra.server.restart
infra.container.deploy
infra.container.restart
infra.dns.create
infra.dns.delete
```
统一进入:
```text
Action Runtime
```
---
# 80. Infrastructure Query
查询:
```text
server list
container list
deployment status
health
```
通过:
```text
Query Runtime
```
而不是:
```text
Controller → Provider → random JSON
```
---
# 81. Infrastructure State
Provider 返回的状态:
```text
External State
```
DevOS 保存:
```text
Desired State
Observed State
```
---
# 82. Desired vs Observed
核心模型:
```text
Desired
↓
Deployment Plan
↓
Provider
↓
Observed
```
例如:
```text
Desired replicas = 3
Observed replicas = 2
```
则:
```text
Drift Detected
```
---
# 83. Drift Detection
必须支持:
```text
deployment.drift.detect
```
检测:
```text
Image
Replicas
Ports
Environment
Network
Domain
TLS
Resources
```
---
# 84. Reconciliation
后续可以:
```text
Desired
↓
Observed
↓
Diff
↓
Reconcile
```
但是第一阶段:
> 只检测,不自动修复。
生产自动修复属于后续能力。
---
# 85. Infrastructure Discovery
可以:
```text
devos infra discover
```
发现:
```text
Servers
Containers
Networks
Volumes
Domains
```
然后建立:
```text
Infrastructure Registry
```
---
# 86. Infrastructure Registry
记录:
```text
Provider
Resource
External ID
Environment
Organization
Project
Status
Metadata
Last Observed
```
---
# 87. External ID
必须保留:
```text
externalId
```
例如:
```text
AWS Instance ID
Docker Container ID
Kubernetes Pod ID
```
不能只使用 DevOS UUID。
---
# 88. Import Existing Infrastructure
DevOS 应支持:
```text
Import
```
例如:
```text
已有 Docker Server
↓
Discover
↓
Import
↓
Register
```
避免强制用户重新创建所有基础设施。
---
# 89. Infrastructure Ownership
资源可以:
```text
managed
external
imported
orphaned
```
只有:
```text
managed
```
默认允许自动修改。
---
# 90. Orphan Detection
例如:
```text
DevOS Deployment 已删除
但 Docker Container 还存在
```
应该:
```text
orphaned
```
而不是自动删除。
---
# 91. Cost
Infrastructure Provider 可以提供:
```text
estimatedCost
actualCost
usage
```
进入:
```text
Usage / Cost Runtime
```
例如:
```text
Project
↓
Deployment
↓
Provider
↓
Cost
```
---
# 92. Resource Quota
组织可以限制:
```text
CPU
Memory
Storage
Deployments
Servers
Containers
Network
Cost
```
通过:
```text
Quota Runtime
```
统一管理。
---
# 93. Deployment Budget
Agent Deployment 还可以有:
```text
Max Cost
Max Instances
Max Duration
Max Network
```
例如:
```text
Agent:
不要让部署成本超过 $20/月。
```
Resolver / Policy 必须验证。
---
# 94. Observability
Deployment 必须自动接入:
```text
Logging
Metrics
Tracing
Audit
Health
```
所有日志包含:
```text
deploymentId
projectId
environmentId
releaseId
providerId
```
---
# 95. Deployment Timeline
UI 显示:
```text
12:00 Plan
12:01 Approval
12:02 Pull Artifact
12:03 Stop Old
12:04 Start New
12:05 Health Check
12:06 Traffic Switch
12:07 Completed
```
数据来自:
```text
Task
Execution
Event
Audit
```
而不是 UI 自己维护状态。
---
# 96. Deployment Logs
Provider 日志:
```text
stdout
stderr
command result
provider response
```
进入:
```text
Logging / Artifact Runtime
```
敏感内容必须:
```text
Redact
```
---
# 97. Secret Leakage Protection
绝对禁止日志出现:
```text
API_KEY
PASSWORD
TOKEN
PRIVATE_KEY
```
例如:
```text
docker login -p XXXXX
```
必须:
```text
Redacted
```
---
# 98. Deployment Events
建议事件:
```text
deployment.created
deployment.planned
deployment.approved
deployment.started
deployment.progressed
deployment.ready
deployment.failed
deployment.rollback.started
deployment.rollback.completed
deployment.cancelled
deployment.destroyed
deployment.drift.detected
```
---
# 99. Notifications
事件可以触发:
```text
Notification Runtime
```
例如:
```text
Production Deployment Failed
```
通知:
```text
In-App
Email
Chat
```
Deployment 不直接发 Email。
---
# 100. Deployment API
建议:
```text
POST /v1/deployments
POST /v1/deployments/:id/plan
POST /v1/deployments/:id/apply
POST /v1/deployments/:id/cancel
POST /v1/deployments/:id/rollback
GET /v1/deployments
GET /v1/deployments/:id
GET /v1/deployments/:id/tasks
GET /v1/deployments/:id/logs
GET /v1/deployments/:id/health
```
---
# 101. Infrastructure API
```text
GET /v1/infrastructure/providers
GET /v1/infrastructure/targets
GET /v1/infrastructure/resources
POST /v1/infrastructure/discover
POST /v1/infrastructure/import
```
所有 API:
```text
Security
Authorization
Scope
Audit
```
---
# 102. Deployment SDK
建议:
```text
@devos/deployment-sdk
```
提供:
```ts
deployments.plan()
deployments.apply()
deployments.cancel()
deployments.rollback()
deployments.status()
deployments.health()
```
---
# 103. CLI
最终:
```bash
devos deploy plan
devos deploy apply
devos deploy status
devos deploy logs
devos deploy cancel
devos deploy rollback
devos deploy history
```
Infrastructure:
```bash
devos infra list
devos infra discover
devos infra health
devos infra doctor
```
---
# 104. Deployment UI
建议:
```text
Deployments
├── Overview
├── Releases
├── Environments
├── Targets
├── Services
├── Health
├── Logs
├── Timeline
└── Rollbacks
```
---
# 105. Project Detail
Project 页面可以:
```text
Project
↓
Deployments
```
显示:
```text
Development
Staging
Production
```
例如:
```text
Production
Release: 1.4.0
Status: Healthy
Target: server-01
Services: 4/4
```
---
# 106. Deployment Detail
显示:
```text
Release
Artifact
Environment
Provider
Target
Services
Health
Task
Logs
Events
Audit
Rollback
```
---
# 107. Agent Deployment UI
Agent 操作显示:
```text
Goal:
Deploy SEO Agent to production.
Plan:
1. Validate release
2. Run migration
3. Deploy API
4. Deploy worker
5. Health check
6. Switch traffic
Risk:
HIGH
Approval:
Required
```
而不是:
```text
Agent is thinking...
```
不展示隐藏 Chain-of-Thought。
---
# 108. Deployment History
必须保留:
```text
Release
Actor
Time
Environment
Target
Result
Rollback
```
可以回答:
> 谁在什么时候把哪个版本部署到了生产?
---
# 109. Deployment Audit
至少记录:
```text
deployment.plan
deployment.approved
deployment.started
deployment.completed
deployment.failed
deployment.rollback
deployment.destroy
```
---
# 110. Multi-Tenant Security
所有 Deployment:
```text
organizationId
projectId
environmentId
```
必须继承:
```text
SecurityContext
```
不能:
```text
Project A
↓
Deploy
↓
Project B
```
---
# 111. Environment Permission
权限示例:
```text
deployment.read
deployment.plan
deployment.deploy
deployment.rollback
deployment.destroy
environment.production.deploy
environment.production.destroy
```
---
# 112. Agent Permission
Agent 权限:
```text
deployment.plan
```
不等于:
```text
deployment.deploy
```
更不等于:
```text
production.destroy
```
---
# 113. Plugin Permission
Plugin 例如 Docker Plugin:
只能获得:
```text
docker.container.manage
```
不能:
```text
environment.production.admin
```
除非明确授予。
---
# 114. Provider Network Security
Provider 必须经过:
```text
Network Policy
```
控制:
```text
Allowed Hosts
Allowed Ports
Regions
Protocols
```
避免任意外连。
---
# 115. SSRF
特别是:
```text
HTTP Health Check
Webhook
Provider
Metadata API
```
必须防:
```text
169.254.169.254
localhost
127.0.0.1
private network
```
除非显式允许。
---
# 116. Command Execution
基础设施操作涉及:
```text
SSH
Docker
Shell
```
必须:
```text
Command Allowlist
Argument Validation
Timeout
Resource Limit
Audit
```
禁止:
```text
eval(userInput)
```
---
# 117. Shell Injection
错误:
```ts
exec(`docker run ${image}`);
```
正确:
```text
Structured Command
↓
Argument Validation
↓
Command Runtime
```
---
# 118. Infrastructure Secrets
禁止:
```text
SSH private key
Cloud API token
Registry password
```
进入:
```text
Project Manifest
Git
Artifact
Logs
```
只保存:
```text
Credential Reference
Secret Reference
```
---
# 119. Deployment Config Snapshot
部署时记录:
```text
Config Version
```
而不是:
```text
实时 Config
```
否则:
```text
昨天部署的版本
```
可能因为今天 Config 改了而无法重现。
---
# 120. Secret Snapshot
Secret 不保存 plaintext。
Deployment 记录:
```text
secretRef
secretVersion
```
这样可以知道:
> 使用的是哪个 Secret 版本。
---
# 121. Configuration Drift
如果:
```text
Desired Config
≠
Observed Config
```
报告:
```text
Config Drift
```
---
# 122. Deployment Drift
统一:
```text
Desired
Observed
```
检查:
```text
Artifact
Config
Replicas
Network
Domain
TLS
Resources
```
---
# 123. Deployment Repair
第一阶段:
```text
Detect
Report
```
第二阶段:
```text
Plan Repair
```
第三阶段:
```text
Auto Reconcile
```
不要第一阶段就自动修复生产。
---
# 124. Disaster Recovery
Deployment Runtime 需要考虑:
```text
Server Failure
Provider Failure
Database Failure
Storage Failure
Deployment Failure
```
但:
> Disaster Recovery 不应该重新创建一套 Storage/Backup Runtime。
复用:
```text
Storage Runtime
Artifact Runtime
Backup Provider
Task Runtime
```
---
# 125. Backup
生产部署前可以:
```text
Database Backup
Config Snapshot
Artifact Retention
```
Backup 通过:
```text
Backup Provider
```
实现。
---
# 126. Restore
支持:
```bash
devos backup list
devos backup restore
```
恢复必须:
```text
Approval
Audit
Environment Protection
```
---
# 127. Rollback 与 Restore
两者必须区分:
```text
Rollback
=
恢复应用 Release
```
```text
Restore
=
恢复数据 / 基础设施状态
```
不能混为一谈。
---
# 128. Disaster Recovery Plan
Project 可以声明:
```yaml
recovery:
rpo: 1h
rto: 30m
```
最终交给:
```text
Backup / Infrastructure / Deployment Runtime
```
实现。
---
# 129. Availability
服务可以定义:
```yaml
availability:
replicas: 2
strategy: rolling
```
Provider 决定实际实现。
---
# 130. Resource Requirements
Service 可以声明:
```yaml
resources:
cpu: "1"
memory: "1Gi"
storage: "10Gi"
```
Provider 转换为:
```text
Docker
Kubernetes
VM
Cloud
```
各自配置。
---
# 131. Resource Abstraction
不要:
```yaml
docker:
memory: 1024
```
作为业务 Manifest。
优先:
```yaml
resources:
memory: "1Gi"
```
Provider 自己映射。
---
# 132. Deployment Profile
Project Factory 可以声明:
```yaml
deployment:
profile: docker
```
后续:
```text
docker
kubernetes
serverless
cloud
bare-metal
```
---
# 133. Profile 与 Provider
Profile:
```text
运行方式
```
Provider:
```text
实际供应商
```
例如:
```text
Profile:
docker
Provider:
remote-docker
```
或者:
```text
Profile:
kubernetes
Provider:
aws-eks
```
---
# 134. Deployment Environment Matrix
项目可能:
```text
development → local docker
staging → remote docker
production → kubernetes
```
Manifest:
```yaml
deployment:
environments:
development:
profile: docker
staging:
profile: docker
production:
profile: kubernetes
```
---
# 135. Promote Release
推荐:
```text
Build once
Deploy many
```
即:
```text
Build
↓
Artifact
↓
Staging
↓
Production
```
不要:
```text
Build Staging
Build Production
```
两个不同 Artifact。
---
# 136. Promotion
```bash
devos release promote 1.4.0 \
--from staging \
--to production
```
实际:
```text
Same Artifact
```
---
# 137. Release Approval
Production Promotion:
```text
Release
↓
Tests
↓
Staging Health
↓
Approval
↓
Production
```
---
# 138. Deployment Verification
部署成功必须至少验证:
```text
Process
Health
Endpoint
Dependencies
Metrics
Error Rate
```
---
# 139. Post-Deploy Checks
例如:
```text
HTTP /health
HTTP /ready
Database Connection
Queue Connection
Storage Connection
Provider Health
```
失败:
```text
Deployment Failed
```
根据策略:
```text
Rollback
```
---
# 140. Smoke Test
可以定义:
```yaml
verification:
smoke:
- GET /health
- GET /ready
- GET /api/version
```
Smoke Test 通过后:
```text
Deployment Ready
```
---
# 141. Deployment Verification 与 E2E
Smoke:
```text
快速验证
```
E2E:
```text
完整业务流程
```
两者都应该进入:
```text
Task Runtime
```
---
# 142. Deployment Health Window
部署成功后可以观察:
```text
5 min
10 min
30 min
```
检查:
```text
Error Rate
Latency
CPU
Memory
Restart
```
异常:
```text
Auto Rollback
```
这是后续增强功能。
---
# 143. Auto Rollback Policy
示例:
```yaml
rollback:
automatic:
enabled: false
errorRate: 0.1
window: 5m
```
默认:
```text
false
```
生产自动回滚必须显式开启。
---
# 144. Deployment Notification
部署:
```text
started
success
failed
rollback
```
通过 Notification Runtime:
```text
In-App
Email
Slack
Discord
Webhook
```
---
# 145. Communication Provider
Deployment 不应该直接:
```text
sendSlack()
sendEmail()
```
而:
```text
Event
↓
Notification
↓
Communication Runtime
```
---
# 146. Deployment Cost
每次 Deployment 可以记录:
```text
Build Cost
Storage Cost
Provider Cost
Network Cost
Compute Cost
```
进入:
```text
Usage Runtime
```
---
# 147. Deployment Metrics
至少:
```text
deployment.duration
deployment.success
deployment.failure
deployment.rollback
deployment.health_check
deployment.drift
```
---
# 148. Infrastructure Metrics
```text
infra.cpu
infra.memory
infra.disk
infra.network
infra.container.restart
infra.provider.error
```
具体采集由:
```text
Observability Provider
```
完成。
---
# 149. Deployment Tracing
Trace:
```text
deployment action
↓
task
↓
job
↓
provider
↓
external request
```
所有步骤共享:
```text
traceId
correlationId
deploymentId
```
---
# 150. Deployment Tables
建议:
```text
projects
environments
deployment_targets
deployment_plans
deployments
deployment_services
releases
release_artifacts
runtime_instances
health_checks
deployment_events
infrastructure_resources
```
---
# 151. Project 与 Deployment
```text
Project
1
│
N
↓
Deployment
```
Deployment 必须属于:
```text
Project
Environment
Release
Target
```
---
# 152. Deployment 与 Release
```text
Release
1
│
N
↓
Deployment
```
同一个 Release 可以:
```text
staging
production
```
分别部署。
---
# 153. Deployment 与 Artifact
一个 Release:
```text
api artifact
worker artifact
web artifact
```
Deployment 使用:
```text
exact artifact
```
---
# 154. Infrastructure Registry
建议包:
```text
packages/infrastructure/
```
包含:
```text
resource
provider
target
discovery
drift
health
```
---
# 155. Deployment Packages
建议:
```text
packages/deployment/
packages/release/
packages/infrastructure/
packages/deployment-provider/
packages/deployment-testing/
packages/backup/
```
---
# 156. Provider Packages
例如:
```text
plugins/
├── docker/
├── ssh/
├── kubernetes/
├── cloudflare/
└── aws/
```
它们通过:
```text
Plugin Runtime
```
注册 Provider。
---
# 157. Docker Plugin
Docker 不应成为:
```text
Core
```
而应:
```text
Official Plugin
```
实现:
```text
Infrastructure Provider
```
---
# 158. SSH Plugin
同样:
```text
Official Plugin
```
实现:
```text
SSH Infrastructure Provider
```
---
# 159. Cloud Provider
例如 AWS:
```text
Official / Verified Plugin
```
提供:
```text
Compute
Storage
Network
DNS
Container
```
但每一项都通过:
```text
Provider Capability
```
声明。
---
# 160. Provider Capability
```ts
interface ProviderCapability {
id: string;
version: string;
resourceTypes: string[];
actions: string[];
regions?: string[];
}
```
例如:
```text
docker.container.deploy
aws.ec2.create
cloudflare.dns.create
```
---
# 161. Capability Discovery
Agent 不应该知道:
```text
AWS API
Docker API
```
它只发现:
```text
deployment.deploy
infra.container.deploy
```
然后:
```text
Provider Resolver
```
选择具体实现。
---
# 162. Provider Health
每个 Provider:
```text
healthy
degraded
unavailable
unknown
```
Provider Runtime 应定期:
```text
Health Check
```
---
# 163. Provider Failover
可以配置:
```text
Primary Provider
Secondary Provider
```
但生产自动 Failover 必须:
```text
Policy
Approval
Compatibility
```
不能简单:
```text
provider A failed
→ random provider B
```
---
# 164. Region
Provider 支持:
```text
region
zone
location
```
Project Manifest 不应该强绑定:
```text
AWS us-east-1
```
除非用户明确要求。
---
# 165. Infrastructure Scheduling
Deployment 可以选择:
```text
region
capacity
cost
latency
compliance
```
最终:
```text
Placement Policy
```
决定 Target。
---
# 166. Placement Policy
例如:
```yaml
placement:
region: ap-northeast-1
maxCost: 50
```
Resolver:
```text
Provider
↓
Available Targets
↓
Policy
↓
Selected Target
```
---
# 167. Compliance
未来可以支持:
```text
data residency
region restrictions
network restrictions
provider restrictions
```
但这些属于:
```text
Policy Runtime
```
而不是 Deployment 自己硬编码。
---
# 168. Deployment Testing
必须覆盖:
```text
Plan
Apply
Cancel
Retry
Health
Rollback
Drift
Provider Failure
Network Failure
Artifact Failure
Config Failure
Secret Failure
```
---
# 169. Provider Contract Test
每个 Provider 必须通过:
```text
Provider Contract Suite
```
验证:
```text
validate
plan
deploy
health
destroy
```
---
# 170. Fake Provider
测试环境提供:
```text
FakeInfrastructureProvider
```
可以模拟:
```text
Success
Timeout
Failure
Partial Failure
Drift
Health Failure
```
---
# 171. Deployment Integration Test
例如:
```text
Project
↓
Build
↓
Artifact
↓
Deployment
↓
Fake Docker
↓
Health
↓
Ready
```
完整测试。
---
# 172. E2E Test
至少:
```text
Create Project
↓
Generate
↓
Build
↓
Release
↓
Deploy Staging
↓
Health
↓
Promote
↓
Deploy Production
↓
Rollback
```
---
# 173. Chaos Tests
后续增加:
```text
Provider Timeout
Network Disconnect
Worker Crash
Container Crash
Health Failure
Database Failure
```
验证:
```text
Recovery
```
---
# 174. Worker Crash
Deployment Worker 在:
```text
deploying
```
时崩溃。
系统应该:
```text
Lease Expire
↓
Job Retry
↓
Check Actual State
↓
Resume
```
不能盲目重新执行破坏性操作。
---
# 175. Provider Timeout
Provider:
```text
timeout
```
不一定代表:
```text
operation failed
```
可能:
```text
external operation succeeded
but response lost
```
因此必须:
```text
Query Observed State
```
再决定 Retry。
---
# 176. Idempotency
Deployment Actions 必须支持:
```text
Idempotency-Key
```
例如:
```text
deploy(project=A, release=1.4.0)
```
重复请求:
```text
same operation
```
不能创建两个 Deployment。
---
# 177. Deployment Concurrency
同一个:
```text
Project + Environment
```
默认只能有:
```text
one active deployment
```
否则:
```text
Deploy A
Deploy B
```
互相覆盖。
---
# 178. Deployment Lock
使用:
```text
Redis Lease
```
协调:
```text
projectId
environmentId
```
但真正状态:
```text
PostgreSQL
```
持久化。
---
# 179. Queue
Deployment Queue 统一:
```text
Task
Job
Queue
Worker
```
不要创建:
```text
deploymentQueue
```
第二套系统。
可以:
```text
queue:deployment
```
作为逻辑队列。
---
# 180. Backpressure
大量项目同时部署:
```text
1000 deployments
```
必须:
```text
Queue
Concurrency
Rate Limit
Provider Limit
```
控制。
---
# 181. Deployment Priority
例如:
```text
critical
high
normal
low
```
但 Priority 不能绕过:
```text
Authorization
Approval
Environment Guard
```
---
# 182. Deployment Maintenance Window
生产可以定义:
```yaml
maintenance:
allowed:
- "02:00-04:00"
```
由:
```text
Scheduler / Policy Runtime
```
判断。
---
# 183. Emergency Deployment
可以支持:
```text
Break Glass
```
但必须:
```text
Short TTL
Strong Audit
Reason
Actor
Approval / notification
```
---
# 184. Production Protection
最终生产保护原则:
```text
PRIVATE
SCOPED
AUDITED
APPROVED
IDEMPOTENT
REVERSIBLE
```
---
# 185. Deployment Project Manifest
Project Factory 可以生成:
```yaml
deployment:
profile: docker
services:
api:
artifact: api
replicas: 2
worker:
artifact: worker
replicas: 1
web:
artifact: web
replicas: 2
environments:
staging:
target: staging
production:
target: production
approval: required
```
Manifest 描述:
> Desired Deployment。
具体 Provider 实现由 Runtime 决定。
---
# 186. Deployment Profile Example
```yaml
deployment:
profile: docker
services:
api:
type: api
port: 3000
worker:
type: worker
```
Docker Provider 可以转换:
```text
Docker Network
Container
Port
Health Check
```
---
# 187. Kubernetes Profile
未来:
```yaml
deployment:
profile: kubernetes
```
同样的 Service:
```text
api
worker
web
```
转换成:
```text
Deployment
Service
ConfigMap
Secret Reference
Ingress
```
但:
> Kubernetes-specific objects 应属于 Provider/Template,而不是业务 Manifest 核心模型。
---
# 188. Deployment Template
复杂部署可以使用:
```text
Deployment Template
```
例如:
```text
single-server
high-availability
worker-cluster
web-api-worker
```
Project Factory 可以选择。
---
# 189. Project Factory Integration
完整:
```text
Project Manifest
↓
Deployment Profile
↓
Service Definition
↓
Build
↓
Artifact
↓
Release
↓
Deployment Plan
```
---
# 190. Deployment Upgrade
升级:
```text
Release 1.4
↓
Release 1.5
```
流程:
```text
Compatibility
↓
Migration Plan
↓
Approval
↓
Deploy
↓
Health
↓
Promote
```
---
# 191. Deployment Version Compatibility
检查:
```text
Project Version
Runtime Version
Module Version
Plugin Version
Artifact Version
Database Version
Config Version
```
复用:
```text
Compatibility Runtime
```
---
# 192. Deployment Rollback Compatibility
Rollback 前:
```text
Previous Release
```
必须检查:
```text
DB Schema
Config
Plugin
Runtime
Artifact
```
---
# 193. Deployment Garbage Collection
旧 Artifact / Container:
```text
保留 N 个 Release
```
然后:
```text
Garbage Collection
```
但不能删除:
```text
Current Release
Rollback Release
Protected Artifact
```
---
# 194. Artifact Retention
例如:
```yaml
retention:
releases: 10
artifacts: 30d
```
通过:
```text
Artifact Runtime
```
执行。
---
# 195. Infrastructure Cleanup
删除 Project 后:
默认:
```text
Do Not Destroy External Infrastructure
```
必须明确:
```text
destroy infrastructure
```
并可能要求:
```text
Approval
```
---
# 196. Project Delete
正确:
```text
Delete Project
↓
Disable Deployment
↓
Keep Infrastructure
↓
Keep Artifacts
```
除非用户明确:
```text
Destroy
```
---
# 197. Infrastructure Destroy
Destroy 是:
```text
critical
```
必须:
```text
Explicit Action
Strong Authorization
Production Guard
Audit
Approval
```
---
# 198. Deployment Doctor
CLI:
```bash
devos deploy doctor
```
检查:
```text
Provider
Credential
Network
Artifact
Config
Secret
Target
Health
Task
Queue
Worker
```
---
# 199. Infrastructure Doctor
```bash
devos infra doctor
```
检查:
```text
Provider Connectivity
Credentials
Targets
Resource Drift
Health
Capacity
Network
```
---
# 200. Deployment Architecture Rules
必须:
```text
Deployment → Action Runtime
Deployment → Task Runtime
Deployment → Event Runtime
Deployment → Provider Runtime
Deployment → Config Runtime
Deployment → Secret Runtime
Deployment → Artifact Runtime
Deployment → Health Runtime
Deployment → Observability Runtime
```
禁止:
```text
Deployment → raw Docker
Deployment → raw SSH
Deployment → raw AWS SDK
Deployment → raw DB
```
---
# 201. Package Layout
推荐:
```text
packages/
├── deployment/
│ ├── domain/
│ ├── runtime/
│ ├── plan/
│ ├── strategy/
│ ├── rollback/
│ └── verification/
│
├── release/
├── infrastructure/
│ ├── domain/
│ ├── runtime/
│ ├── provider/
│ ├── target/
│ ├── discovery/
│ └── drift/
│
├── deployment-sdk/
└── deployment-testing/
```
---
# 202. Official Providers
第一阶段建议:
```text
Official Docker Provider
Official SSH Provider
Official Local Provider
```
后续:
```text
Kubernetes
AWS
Cloudflare
GCP
Azure
```
通过 Plugin。
---
# 203. Local Provider
开发环境非常重要:
```text
Local Provider
```
支持:
```text
Local Process
Local Docker
```
用于:
```text
dev
test
```
---
# 204. Mock Provider
测试:
```text
Mock Provider
```
不连接真实基础设施。
---
# 205. Provider Development
开发者可以通过:
```text
@devos/plugin-sdk
```
创建:
```text
Infrastructure Provider
```
而不是修改 DevOS Core。
---
# 206. Provider Certification
Provider 需要:
```text
Basic
Runtime Safe
Secure
Verified
Official
```
与 Plugin Certification 对齐。
---
# 207. Provider Permission Manifest
Provider Plugin 声明:
```yaml
permissions:
- infrastructure.read
- infrastructure.deploy
network:
allowed:
- "*.docker.local"
```
高权限 Provider:
```text
approval
```
---
# 208. Provider Isolation
未来支持:
```text
in-process
restricted
isolated
container
```
与 Plugin Sandbox 共用。
---
# 209. Deployment Runtime 不拥有 Cloud SDK
例如 AWS:
禁止:
```text
packages/deployment/aws.ts
```
大量写:
```ts
new EC2Client(...)
```
应该:
```text
AWS Plugin
↓
AWS Provider
↓
Deployment Runtime
```
---
# 210. Provider Adapter
Provider 负责:
```text
External API
↓
Normalize
```
例如:
```text
AWS response
Docker response
Kubernetes response
```
统一为:
```text
DeploymentResult
HealthResult
InfrastructureResource
```
---
# 211. Error Normalization
Provider 错误:
```text
DockerError
AWSError
SSHError
```
统一为:
```text
ProviderError
DeploymentError
InfrastructureError
```
并记录:
```text
code
retryable
safeMessage
providerCode
```
---
# 212. Retry
Deployment Retry:
```text
Provider Retry Policy
```
复用:
```text
Task Retry Runtime
```
不要:
```text
for (let i = 0; i < 5; i++)
```
散落在 Provider。
---
# 213. Circuit Breaker
Provider 连续失败:
```text
Provider
↓
Circuit Open
```
防止:
```text
1000 Deployments
↓
全部攻击 Provider
```
复用:
```text
Provider Runtime
```
---
# 214. Rate Limit
限制:
```text
Provider
Organization
Project
Environment
Action
```
复用:
```text
Rate Limit Runtime
```
---
# 215. Deployment Observability
每个 Deployment:
```text
deploymentId
```
贯穿:
```text
Action
Task
Job
Provider
Event
Audit
Logs
Metrics
Trace
```
这样可以做到:
> 一次部署全链路可追踪。
---
# 216. Deployment Cost Attribution
成本可以归属:
```text
Organization
Project
Environment
Deployment
Release
Agent
Actor
```
例如:
```text
Agent-generated deployment
```
可以统计:
```text
agent cost
infrastructure cost
```
---
# 217. Deployment Security Defaults
默认:
```text
DENY
PRIVATE
SCOPED
AUDITED
APPROVED
IDEMPOTENT
```
生产:
```text
PROTECTED
```
Secret:
```text
SHORT-LIVED
```
Provider:
```text
LEAST-PRIVILEGE
```
---
# 218. Zcode Implementation Protocol
实现本章必须按照:
```text
1. Deployment Domain
2. Release / Artifact Integration
3. Environment Integration
4. Provider Runtime
5. Mock Provider
6. Deployment Plan
7. Deployment Task
8. Health Verification
9. Docker Provider
10. SSH Provider
11. Rollback
12. Drift
13. UI
14. API / SDK / CLI
15. Security
16. Observability
17. Tests
```
---
# 219. 第一 Vertical Slice
实现:
```text
Local Project
↓
Build
↓
Artifact
↓
Local Provider
↓
Deployment
↓
Health
```
成功后再做:
```text
Docker
```
---
# 220. 第二 Vertical Slice
```text
Project
↓
Docker Artifact
↓
Docker Provider
↓
Deploy
↓
Health
↓
Logs
```
---
# 221. 第三 Vertical Slice
增加:
```text
Task
Job
Queue
Worker
```
验证:
```text
Deployment
```
不会阻塞 API。
---
# 222. 第四 Vertical Slice
增加:
```text
Release
Promotion
Staging
Production
Approval
```
验证:
```text
Build Once
Deploy Many
```
---
# 223. 第五 Vertical Slice
增加:
```text
Rollback
```
验证:
```text
Release 1
↓
Release 2
↓
Failure
↓
Rollback
↓
Release 1
```
---
# 224. 第六 Vertical Slice
增加:
```text
SSH Provider
```
验证:
```text
Remote Deployment
```
但:
```text
Credential
Security
Audit
```
必须完整接入。
---
# 225. 第七 Vertical Slice
Agent:
```text
Deploy staging
```
Agent:
```text
Plan
↓
Risk
↓
Approval
↓
Deploy
↓
Observe
```
---
# 226. 第八 Vertical Slice
自然语言:
> 把当前 staging 版本发布到生产,如果健康检查失败就停止。
转换:
```text
Goal
↓
Deployment Plan
↓
Policy
↓
Approval
↓
Deploy
↓
Health
```
Agent 不直接执行 Shell。
---
# 227. Deployment Definition of Done
第一阶段:
```text
[ ] Deployment Domain
[ ] Release
[ ] Artifact Integration
[ ] Environment Integration
[ ] Deployment Plan
[ ] Plan / Apply
[ ] Task Integration
[ ] Queue Integration
[ ] Worker Integration
[ ] Mock Provider
[ ] Local Provider
[ ] Docker Provider
[ ] Health Check
[ ] Logs
[ ] Deployment Events
[ ] Audit
[ ] Rollback
[ ] Deployment Lock
[ ] Idempotency
[ ] Security
[ ] Production Guard
[ ] API
[ ] SDK
[ ] CLI
[ ] UI
[ ] Contract Tests
[ ] Integration Tests
[ ] E2E Tests
```
---
# 228. Infrastructure Definition of Done
```text
[ ] Infrastructure Resource
[ ] Provider Runtime
[ ] Target
[ ] Discovery
[ ] Import
[ ] External ID
[ ] Health
[ ] Drift Detection
[ ] Docker Provider
[ ] SSH Provider
[ ] Credential Integration
[ ] Network Policy
[ ] Provider Health
[ ] Provider Contract Tests
[ ] Security Tests
```
---
# 229. Zcode 禁止事项
禁止:
```text
Controller → Docker
```
禁止:
```text
Controller → SSH
```
禁止:
```text
Agent → SSH
```
禁止:
```text
MCP → Docker Socket
```
禁止:
```text
Plugin → Production Infrastructure
```
禁止:
```text
Deployment → Secret plaintext
```
禁止:
```text
Deployment → custom queue
```
禁止:
```text
Deployment → custom scheduler
```
禁止:
```text
Project → infrastructure implementation
```
---
# 230. Zcode Deployment Master Prompt
```text
You are implementing the DevOS Deployment & Infrastructure Runtime.
Deployment is an Action Runtime capability.
The correct flow is:
Project
→ Release
→ Artifact
→ Environment
→ Deployment Plan
→ Approval
→ Deployment Task
→ Provider
→ Runtime Instance
→ Health
→ Event
→ Observability
Never let business code call:
Docker
SSH
AWS SDK
Kubernetes API
Cloud APIs
directly.
All infrastructure operations must go through:
Infrastructure Provider
Provider Runtime
Security Runtime
Credential Runtime
Action Runtime
Task Runtime
Deployment must use exact immutable artifacts.
Never deploy "latest" in production.
Plan and Apply must be separate.
Production deployments must respect:
Authorization
Environment Guard
Risk Policy
Approval
Rollback must restore a known Release, not simply change Git code.
Provider failures and timeouts must check observed state before retrying.
Deployment must be idempotent.
Do not create a second queue, scheduler, event bus, secret system,
logging system, or configuration system.
Reuse existing DevOS Runtime components.
The Infrastructure Provider is an adapter to external infrastructure,
not a second DevOS Runtime.
```
---
# 231. 最终 Deployment Architecture
```text
USER
│
AGENT
│
CI
│
CLI
│
↓
Security Context
│
↓
Deployment API
│
↓
Action Runtime
│
↓
Deployment Runtime
│
┌───────────┴────────────┐
↓ ↓
Release / Artifact Environment
│ │
└───────────┬────────────┘
↓
Deployment Plan
│
↓
Policy / Approval
│
↓
Task / Job / Queue
│
↓
Worker
│
↓
Provider Runtime
│
┌────────────┼────────────┐
↓ ↓ ↓
Docker SSH Kubernetes
│ │ │
└────────────┼────────────┘
↓
Runtime Instance
│
↓
Health
│
┌─────────┼──────────┐
↓ ↓ ↓
Event Logs Metrics
│ │ │
└─────────┼──────────┘
↓
Observability
│
↓
Notification / UI
```
---
# 232. DevOS 完整生产闭环
经过 33 + 34,DevOS 已经形成:
```text
Requirement
↓
Agent
↓
Project Manifest
↓
Project Factory
↓
Capability Resolver
↓
Module / Plugin
↓
Generated Project
↓
Build
↓
Artifact
↓
Release
↓
Deployment Plan
↓
Environment
↓
Provider
↓
Infrastructure
↓
Runtime Instance
↓
Health
↓
Observability
↓
Event
↓
Notification
```
发生故障:
```text
Health Failure
↓
Event
↓
Agent / Workflow
↓
Diagnosis
↓
Rollback Plan
↓
Approval
↓
Rollback
```
---
# 233. DevOS 最终职责边界
```text
Project Factory
↓
“我要什么项目?”
Build Runtime
↓
“如何产生 Artifact?”
Release Runtime
↓
“这个版本包含什么?”
Deployment Runtime
↓
“这个版本部署到哪里?”
Provider Runtime
↓
“如何操作外部基础设施?”
Environment Runtime
↓
“在哪个隔离环境运行?”
Health Runtime
↓
“它是否正常?”
Observability Runtime
↓
“发生了什么?”
Event Runtime
↓
“发生之后通知谁/触发什么?”
Agent Runtime
↓
“下一步应该做什么?”
```
---
# 234. 最终 Golden Rule
> **Deployment Runtime 负责描述和执行“把哪个 Release 部署到哪个 Environment”,Infrastructure Provider 负责“如何操作实际基础设施”;任何 Docker、SSH、Cloud、Kubernetes 操作都必须经过统一的 Security + Credential + Provider + Action + Task Runtime。**
最终链路:
```text
PROJECT
↓
RELEASE
↓
ARTIFACT
↓
DEPLOYMENT PLAN
↓
ENVIRONMENT
↓
APPROVAL / POLICY
↓
TASK / JOB
↓
PROVIDER
↓
INFRASTRUCTURE
↓
RUNTIME INSTANCE
↓
HEALTH
↓
OBSERVABILITY
↓
EVENT
↓
NOTIFICATION / AGENT / ROLLBACK
```
**DevOS 不应该成为另一个 Kubernetes,也不应该成为另一个 Terraform。**
它真正应该做的是:
> **把 Project、Artifact、Environment、Provider、Deployment、Task、Security、Observability 统一到一个可被 Human、Agent、Plugin、MCP、Workflow、CLI、API 共同使用的 Runtime 中。**