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