agentleFS
28672032962867203296/hermes-agent/skills/devops/zero-downtime-deploy/SKILL.md

zero-downtime-deploy

Skill0 starsChanged 3 months agoMITView on GitHub

零停机部署:蓝绿部署、金丝雀发布、滚动更新、回滚策略.

The file

Files
SKILL.md

零停机部署

四种策略

1. 蓝绿部署
   蓝(当前)← 用户
   绿(新版)← 部署好但没流量
   切换 → 绿←用户,蓝←备用
   出问题 → 秒切回蓝
   成本:需要双倍资源

2. 金丝雀发布
   新版 → 5%用户
   没问题的 → 25% → 50% → 100%
   出问题 → 只影响 5%
   成本:无额外资源

3. 滚动更新
   逐个替换实例
   始终保持 N-1 个实例在线
   成本:无额外资源
   Kubernetes 默认方式

4. 功能开关
   代码部署到全部实例
   开关控制谁看到新功能
   成本:无额外资源

简单实现(Nginx 反向代理)

upstream app {
    server 127.0.0.1:8000;  # 蓝
    server 127.0.0.1:8001;  # 绿
}

# 部署流程:
# 1. 绿(8001)部署新版
# 2. 验证绿正常
# 3. Nginx 切流量到绿
# 4. 蓝(8000)部署新版(或保留备用)

数据库迁移策略

扩展兼容迁移(向后兼容):
1. 先加新列(允许 NULL 或有默认值)
2. 新旧代码都能跑
3. 数据迁移完成
4. 删旧列

禁止:直接删列/改类型 → 旧代码立刻崩溃!

回滚

回滚不是"退回旧代码"
而是"切换回旧版本"

快速回滚条件:
1. 旧版本代码仍然可用
2. 数据库迁移向后兼容
3. 有健康检查(自动检测+回滚)
4. 回滚时间 < 5 分钟

检查清单

部署前:
□ staging 环境验证通过
□ 数据库迁移向后兼容
□ 健康检查端点正常
□ 有回滚方案

部署中:
□ 监控错误率/QPS
□ 分阶段发布
□ 随时准备回滚

部署后:
□ 验证关键功能
□ 监控 30 分钟
□ 清理旧版本

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.