84 lines
2.2 KiB
Markdown
84 lines
2.2 KiB
Markdown
---
|
||
title: "CI/CD Pipeline"
|
||
type: concept
|
||
tags: [DevOps, Automation, Software Delivery]
|
||
sources: [engineering-devops-automator]
|
||
last_updated: 2026-05-01
|
||
---
|
||
|
||
# CI/CD Pipeline
|
||
|
||
## 定义
|
||
CI/CD 流水线是自动化软件交付的端到端管道,包含持续集成(Continuous Integration)、持续交付(Continuous Delivery)和持续部署(Continuous Deployment)三个阶段。
|
||
|
||
## 三个阶段
|
||
|
||
### 持续集成(CI)
|
||
- 开发者频繁提交代码到共享仓库
|
||
- 每次提交自动触发构建和测试
|
||
- 早期发现集成问题
|
||
|
||
### 持续交付(CD)
|
||
- 代码通过所有自动化测试后自动部署到 staging 环境
|
||
- 人工审批后部署到生产环境
|
||
- 确保每次变更都可部署
|
||
|
||
### 持续部署(Continuous Deployment)
|
||
- 代码通过所有测试后自动部署到生产环境
|
||
- 无需人工干预
|
||
- 需要完善的测试和监控体系支撑
|
||
|
||
## 核心组件
|
||
|
||
### 构建阶段
|
||
- 代码编译
|
||
- 依赖安装
|
||
- 制品构建(Docker 镜像/二进制文件)
|
||
|
||
### 测试阶段
|
||
- 单元测试
|
||
- 集成测试
|
||
- 端到端测试
|
||
- 安全扫描
|
||
|
||
### 部署阶段
|
||
- 部署到目标环境
|
||
- 健康检查
|
||
- 流量切换
|
||
- 回滚机制
|
||
|
||
## DevOps Automator 的标准流水线
|
||
```yaml
|
||
security-scan → test → build → deploy
|
||
```
|
||
- security-scan:依赖漏洞扫描 + 静态安全分析
|
||
- test:单元测试 + 集成测试
|
||
- build:容器构建 + 推送镜像仓库
|
||
- deploy:零停机部署(蓝绿/金丝雀/滚动)
|
||
|
||
## 相关工具
|
||
- [[GitHub Actions]]:DevOps Automator 默认选择
|
||
- Jenkins:开源 CI/CD 服务器
|
||
- GitLab CI:GitLab 内置 CI/CD
|
||
- ArgoCD:GitOps 持续交付
|
||
- Spinnaker:多云持续交付平台
|
||
|
||
## 相关概念
|
||
- [[Infrastructure as Code]]:CI/CD 部署目标通常是 IaC 管理的基础设施
|
||
- [[Zero-Downtime Deployment]]:CI/CD 的部署策略
|
||
- [[Blue-Green Deployment]]:CI/CD 常用部署策略
|
||
|
||
## 关键指标
|
||
- **部署频率**:每日部署次数
|
||
- **变更前置时间**:代码提交到生产的时间
|
||
- **变更失败率**:生产环境回滚或失败的百分比
|
||
- **MTTR**:平均恢复时间
|
||
|
||
## Aliases
|
||
- CI/CD
|
||
- CI/CD Pipeline
|
||
- 持续集成/持续交付
|
||
- Continuous Integration
|
||
- Continuous Delivery
|
||
- Continuous Deployment
|