ci-cd-optimizer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCI/CD Optimizer
CI/CD 优化器
Optimize CI/CD pipelines for faster builds and reliable deployments.
优化CI/CD流水线以实现更快的构建与可靠的部署。
Quick Start
快速开始
Parallelize jobs, cache dependencies, use smaller images, implement health checks, automate rollbacks.
并行执行任务、缓存依赖项、使用更小的镜像、实现健康检查、自动回滚。
Instructions
操作指南
Pipeline Optimization
流水线优化
Parallel execution:
yaml
undefined并行执行:
yaml
undefinedGitHub Actions
GitHub Actions
jobs:
test:
strategy:
matrix:
node: [14, 16, 18]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: npm test
**Caching dependencies:**
```yaml
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}Docker layer caching:
dockerfile
undefinedjobs:
test:
strategy:
matrix:
node: [14, 16, 18]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- run: npm test
**缓存依赖项:**
```yaml
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}Docker层缓存:
dockerfile
undefinedOrder layers by change frequency
Order layers by change frequency
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
undefinedFROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
undefinedDeployment Strategies
部署策略
Blue-green deployment:
yaml
deploy:
steps:
- name: Deploy to green
run: kubectl set image deployment/app app=myapp:${{ github.sha }} --record
- name: Wait for rollout
run: kubectl rollout status deployment/app
- name: Run smoke tests
run: ./smoke-tests.sh
- name: Switch traffic
run: kubectl patch service app -p '{"spec":{"selector":{"version":"green"}}}'Canary deployment:
yaml
- name: Deploy canary (10%)
run: kubectl set image deployment/app-canary app=myapp:${{ github.sha }}
- name: Monitor metrics
run: ./check-metrics.sh
- name: Promote to 100%
run: kubectl set image deployment/app app=myapp:${{ github.sha }}蓝绿部署:
yaml
deploy:
steps:
- name: Deploy to green
run: kubectl set image deployment/app app=myapp:${{ github.sha }} --record
- name: Wait for rollout
run: kubectl rollout status deployment/app
- name: Run smoke tests
run: ./smoke-tests.sh
- name: Switch traffic
run: kubectl patch service app -p '{"spec":{"selector":{"version":"green"}}}'金丝雀部署:
yaml
- name: Deploy canary (10%)
run: kubectl set image deployment/app-canary app=myapp:${{ github.sha }}
- name: Monitor metrics
run: ./check-metrics.sh
- name: Promote to 100%
run: kubectl set image deployment/app app=myapp:${{ github.sha }}Best Practices
最佳实践
- Fail fast with linting/tests first
- Use matrix builds for multiple versions
- Cache dependencies and build artifacts
- Use smaller Docker images
- Implement automated rollbacks
- Add health checks
- Monitor pipeline metrics
- 优先执行代码检查/测试以快速失败
- 使用矩阵构建适配多版本
- 缓存依赖项与构建产物
- 使用更小的Docker镜像
- 实现自动回滚
- 添加健康检查
- 监控流水线指标