deployment

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Deployment

部署

Overview

概览

Set up CI/CD pipelines and deployment configurations that automate the path from code to production. This skill detects the deployment target, generates pipeline config, creates pre/post-deploy checklists, and configures monitoring — producing a fully automated, rollback-ready deployment pipeline.
Announce at start: "I am using the deployment skill to set up the deployment pipeline."
搭建CI/CD流水线和部署配置,实现从代码到生产流程的自动化。本技能可识别部署目标、生成流水线配置、创建部署前后检查清单、配置监控,最终输出一套完全自动化、支持回滚的部署流水线。
开始时声明: "我将使用部署技能来搭建部署流水线。"

Phase 1: Detect Deployment Target

阶段1:识别部署目标

STOP after this phase — present findings to user for confirmation before proceeding.
Ask questions to identify the full deployment context:
Platform Detection:
  • Where does this deploy? (Vercel, AWS, GCP, Azure, DigitalOcean, self-hosted)
  • Container-based? (Docker, Kubernetes)
  • Serverless? (Lambda, Cloud Functions, Edge Functions)
CI/CD Detection:
  • What CI system? (GitHub Actions, GitLab CI, CircleCI, Jenkins)
  • What triggers deployments? (push to main, tags, manual)
  • Multi-environment? (dev, staging, production)
Infrastructure Detection:
  • Database migrations needed?
  • Environment variables management? (secrets manager, .env)
  • CDN/caching? Asset pipeline?
  • Monitoring/alerting? (Datadog, Sentry, New Relic)
本阶段结束后暂停 —— 先将识别结果同步给用户确认后再继续。
通过提问确认完整的部署上下文:
平台识别:
  • 部署到哪里?(Vercel、AWS、GCP、Azure、DigitalOcean、自托管)
  • 是否基于容器?(Docker、Kubernetes)
  • 是否是Serverless架构?(Lambda、Cloud Functions、Edge Functions)
CI/CD识别:
  • 使用什么CI系统?(GitHub Actions、GitLab CI、CircleCI、Jenkins)
  • 部署的触发条件是什么?(推送到main分支、打标签、手动触发)
  • 是否有多环境?(开发、预发、生产)
基础设施识别:
  • 是否需要数据库迁移?
  • 环境变量如何管理?(密钥管理器、.env)
  • 是否需要CDN/缓存?资源构建流水线?
  • 是否需要监控/告警?(Datadog、Sentry、New Relic)

Platform Selection Decision Table

平台选择决策表

Project TypeRecommended PlatformCI/CDWhy
Static site / SPAVercel, Netlify, Cloudflare PagesBuilt-inZero config, edge CDN
Node.js APIAWS ECS, Cloud Run, RailwayGitHub ActionsContainer support, auto-scaling
Monorepo (frontend + backend)Vercel + AWS / RailwayGitHub ActionsSplit concerns, independent scaling
Enterprise / compliance-heavyAWS EKS, GKEGitLab CI, JenkinsFull control, audit trails
Hobby / side projectRailway, Fly.io, RenderBuilt-in or GitHub ActionsSimple, low cost
ML / data pipelinesAWS SageMaker, GCP VertexGitHub Actions + AirflowGPU support, pipeline orchestration
项目类型推荐平台CI/CD原因
静态站点/SPAVercel, Netlify, Cloudflare Pages内置零配置、边缘CDN
Node.js APIAWS ECS, Cloud Run, RailwayGitHub Actions支持容器、自动扩缩容
Monorepo(前端+后端)Vercel + AWS / RailwayGitHub Actions职责拆分、独立扩缩容
企业/强合规需求AWS EKS, GKEGitLab CI, Jenkins完全可控、审计轨迹
爱好/个人项目Railway, Fly.io, Render内置或GitHub Actions简单、低成本
ML/数据流水线AWS SageMaker, GCP VertexGitHub Actions + Airflow支持GPU、流水线编排

Phase 2: Design Pipeline

阶段2:设计流水线

STOP after this phase — present pipeline design to user for approval before generating config.
本阶段结束后暂停 —— 先将流水线设计方案同步给用户审批后再生成配置。

Standard Pipeline Stages

标准流水线阶段

┌─────────┐   ┌──────────┐   ┌──────────┐   ┌──────────┐   ┌──────────┐
│  Build   │──▶│   Test   │──▶│  Lint/   │──▶│  Deploy  │──▶│  Verify  │
│          │   │          │   │  Check   │   │          │   │          │
└─────────┘   └──────────┘   └──────────┘   └──────────┘   └──────────┘
Build: Install dependencies, compile, bundle Test: Unit tests, integration tests, coverage check Lint/Check: Linting, type checking, security audit Deploy: Push to target environment Verify: Health checks, smoke tests, monitoring
┌─────────┐   ┌──────────┐   ┌──────────┐   ┌──────────┐   ┌──────────┐
│  Build   │──▶│   Test   │──▶│  Lint/   │──▶│  Deploy  │──▶│  Verify  │
│          │   │          │   │  Check   │   │          │   │          │
└─────────┘   └──────────┘   └──────────┘   └──────────┘   └──────────┘
构建(Build): 安装依赖、编译、打包 测试(Test): 单元测试、集成测试、覆盖率检查 检查(Lint/Check): 代码检查、类型检查、安全审计 部署(Deploy): 推送到目标环境 验证(Verify): 健康检查、冒烟测试、监控

Branch Strategy Decision Table

分支策略决策表

BranchActionEnvironmentGate
feature/*
Build + Test + LintNonePR checks pass
main
Build + Test + Lint + DeployStagingAll checks green
release/*
or tags
Build + Test + Lint + DeployProductionManual approval
hotfix/*
Build + Test + DeployProduction (expedited)Senior approval
分支动作环境门槛
feature/*
构建 + 测试 + 代码检查PR检查通过
main
构建 + 测试 + 代码检查 + 部署预发所有检查通过
release/*
或标签
构建 + 测试 + 代码检查 + 部署生产人工审批
hotfix/*
构建 + 测试 + 部署生产(加急)高级负责人审批

Deployment Strategy Decision Table

部署策略决策表

StrategyWhen to UseRisk LevelRollback Speed
Direct deploySolo/hobby projects, stagingHighSlow (redeploy)
Blue-greenApps with health checks, low-downtime needsLowInstant (switch)
CanaryHigh-traffic production, gradual rolloutVery LowFast (reroute)
RollingKubernetes clusters, stateless servicesLowMedium
Feature flagsDecoupled deploy from releaseVery LowInstant (toggle)
策略使用场景风险等级回滚速度
直接部署单人/爱好项目、预发环境慢(重新部署)
蓝绿部署有健康检查、低停机需求的应用instant(切换流量)
金丝雀部署高流量生产环境、渐进式发布极低快(重新路由流量)
滚动部署Kubernetes集群、无状态服务中等
功能开关部署与发布解耦极低瞬时(切换开关)

Phase 3: Generate Config

阶段3:生成配置

GitHub Actions Example

GitHub Actions 示例

yaml
name: CI/CD Pipeline

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      - run: npm ci
      - run: npm run lint
      - run: npm run type-check
      - run: npm test -- --coverage
      - run: npm run build

  deploy-staging:
    needs: build-and-test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - uses: actions/checkout@v4
      # [platform-specific deploy steps]

  deploy-production:
    needs: build-and-test
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/checkout@v4
      # [platform-specific deploy steps]
yaml
name: CI/CD Pipeline

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      - run: npm ci
      - run: npm run lint
      - run: npm run type-check
      - run: npm test -- --coverage
      - run: npm run build

  deploy-staging:
    needs: build-and-test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - uses: actions/checkout@v4
      # [platform-specific deploy steps]

  deploy-production:
    needs: build-and-test
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/checkout@v4
      # [platform-specific deploy steps]

GitLab CI Example

GitLab CI 示例

yaml
stages:
  - build
  - test
  - deploy

build:
  stage: build
  script:
    - npm ci
    - npm run build
  artifacts:
    paths: [dist/]

test:
  stage: test
  script:
    - npm run lint
    - npm run type-check
    - npm test -- --coverage

deploy-staging:
  stage: deploy
  environment: staging
  script:
    - # platform-specific deploy
  only:
    - main

deploy-production:
  stage: deploy
  environment: production
  script:
    - # platform-specific deploy
  when: manual
  only:
    - tags
yaml
stages:
  - build
  - test
  - deploy

build:
  stage: build
  script:
    - npm ci
    - npm run build
  artifacts:
    paths: [dist/]

test:
  stage: test
  script:
    - npm run lint
    - npm run type-check
    - npm test -- --coverage

deploy-staging:
  stage: deploy
  environment: staging
  script:
    - # platform-specific deploy
  only:
    - main

deploy-production:
  stage: deploy
  environment: production
  script:
    - # platform-specific deploy
  when: manual
  only:
    - tags

Phase 4: Create Deployment Checklists

阶段4:创建部署检查清单

STOP — present checklists to user. Customize based on their stack.
暂停 —— 向用户展示检查清单,可基于用户的技术栈自定义。

Pre-Deploy Checklist

部署前检查清单

markdown
undefined
markdown
undefined

Pre-Deploy Checklist

部署前检查清单

  • All tests passing on CI
  • Code reviewed and approved
  • No critical/high security vulnerabilities
  • Environment variables configured for target environment
  • Database migrations tested (if applicable)
  • Feature flags configured (if applicable)
  • Rollback plan documented
  • Monitoring/alerts configured
  • Changelog updated
  • Version bumped
undefined
  • CI上所有测试通过
  • 代码已审核并批准
  • 无严重/高危安全漏洞
  • 目标环境的环境变量已配置
  • 数据库迁移已测试(如有)
  • 功能开关已配置(如有)
  • 回滚方案已文档化
  • 监控/告警已配置
  • 更新日志已更新
  • 版本号已升级
undefined

Post-Deploy Verification

部署后验证清单

markdown
undefined
markdown
undefined

Post-Deploy Verification

部署后验证清单

  • Health check endpoint returns 200
  • Smoke tests passing
  • Error rate within normal range
  • Response times within SLA
  • Database migrations applied successfully
  • Feature flags active/inactive as expected
  • Monitoring dashboard showing expected metrics
  • No new errors in error tracking (Sentry, etc.)
undefined
  • 健康检查接口返回200
  • 冒烟测试通过
  • 错误率在正常范围内
  • 响应时间符合SLA要求
  • 数据库迁移执行成功
  • 功能开关状态符合预期
  • 监控面板展示指标正常
  • 错误追踪工具(Sentry等)无新增报错
undefined

Phase 5: Review and Finalize

阶段5:审核和定稿

Present the complete pipeline configuration to the user:
  1. VERIFY CI/CD config file syntax is valid
  2. VERIFY all environment variables are documented
  3. VERIFY rollback plan exists
  4. VERIFY pre/post-deploy checklists are complete
  5. VERIFY the pipeline can be tested locally (act, etc.)
Save config to
.github/workflows/
or equivalent.
向用户展示完整的流水线配置:
  1. 确认CI/CD配置文件语法正确
  2. 确认所有环境变量已文档化
  3. 确认存在回滚方案
  4. 确认部署前后检查清单完整
  5. 确认流水线可在本地测试(act等工具)
将配置保存到
.github/workflows/
或对应目录。

Anti-Patterns / Common Mistakes

反模式/常见错误

Anti-PatternWhy It Is WrongWhat to Do Instead
Manual production deploysError-prone, no audit trailAutomate via CI/CD pipeline
No rollback planStuck if deploy breaks productionDefine rollback before every deploy
Skipping stagingBugs found in productionAlways deploy to staging first
Secrets in code/config filesSecurity breach riskUse secrets manager or env vars
latest
tag for production images
Non-reproducible deploysPin specific version tags
No concurrency controlConflicting deploysAdd concurrency groups to CI
Deploying without health checksNo visibility into deploy healthAdd health endpoint + post-deploy check
Alert fatigue from noisy monitorsReal issues get missedAlert on symptoms, tune thresholds
反模式问题正确做法
手动部署生产环境容易出错,无审计轨迹通过CI/CD流水线自动化
无回滚方案部署导致生产故障时无法快速恢复每次部署前先定义回滚方案
跳过预发环境bug直接在生产环境被发现始终先部署到预发环境验证
密钥放在代码/配置文件中存在安全泄露风险使用密钥管理器或环境变量
生产镜像使用
latest
标签
部署不可复现绑定具体的版本标签
无并发控制出现冲突部署为CI任务添加并发组
部署无健康检查无法感知部署是否正常新增健康检查接口+部署后校验
监控告警过多导致告警疲劳真实问题被忽略仅对异常症状告警,调整阈值

Key Principles

核心原则

  • Automate everything — no manual steps in the critical path
  • Fast feedback — fail early, fail fast
  • Environment parity — staging matches production
  • Rollback-ready — every deploy has a rollback plan
  • Observable — monitoring before, during, and after deploy
  • Secure — no secrets in code, use secrets management
  • Idempotent — deploying the same version twice produces the same result
  • 全自动化 —— 关键路径上无人工步骤
  • 快速反馈 —— 尽早失败、快速失败
  • 环境一致 —— 预发环境与生产环境配置一致
  • 支持回滚 —— 每次部署都有回滚方案
  • 可观测 —— 部署前、中、后全流程监控
  • 安全 —— 代码中无密钥,使用密钥管理工具
  • 幂等 —— 相同版本部署多次结果一致

Integration Points

集成点

SkillIntegration
senior-devops
Provides Docker, K8s, and IaC patterns used in deploy config
git-commit-helper
Conventional commits drive changelog and version bumping
finishing-a-development-branch
Branch completion triggers deployment pipeline
verification-before-completion
Post-deploy verification gate
security-review
Security scan stage in the pipeline
planning
Deployment plan is part of the implementation plan
技能集成方式
senior-devops
提供部署配置中使用的Docker、K8s和IaC模式
git-commit-helper
约定式提交驱动更新日志和版本升级
finishing-a-development-branch
分支合并触发部署流水线
verification-before-completion
部署后校验关卡
security-review
流水线中的安全扫描阶段
planning
部署方案是实现方案的一部分

Skill Type

技能类型

FLEXIBLE — Adapt pipeline design, platform selection, and tooling to the project's cloud provider, team size, and operational maturity. The principles (automation, rollback, observability) are constant; specific tools are interchangeable.
灵活适配 —— 可根据项目的云服务商、团队规模和运维成熟度调整流水线设计、平台选择和工具链。核心原则(自动化、回滚、可观测性)保持不变,具体工具可替换。