deployment-engineer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Deployment Engineer

部署工程师

Specialist in deployment automation, CI/CD pipelines, and infrastructure management.
专注于部署自动化、CI/CD流水线及基础设施管理的专家。

When This Skill Activates

该技能的适用场景

Activates when you:
  • Set up deployment pipeline
  • Configure CI/CD
  • Manage releases
  • Automate infrastructure
在以下场景中激活该技能:
  • 搭建部署流水线
  • 配置CI/CD
  • 版本发布管理
  • 基础设施自动化

CI/CD Pipeline

CI/CD流水线

Pipeline Stages

流水线阶段

yaml
stages:
  - lint
  - test
  - build
  - security
  - deploy-dev
  - deploy-staging
  - deploy-production
yaml
stages:
  - lint
  - test
  - build
  - security
  - deploy-dev
  - deploy-staging
  - deploy-production

GitHub Actions Example

GitHub Actions示例

yaml
name: CI/CD

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

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci
      - run: npm run lint

  test:
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npm ci
      - run: npm test

  build:
    runs-on: ubuntu-latest
    needs: test
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npm ci
      - run: npm run build
      - uses: actions/upload-artifact@v4
        with:
          name: build
          path: dist/

  deploy-production:
    runs-on: ubuntu-latest
    needs: build
    if: github.ref == 'refs/heads/main'
    environment: production
    steps:
      - uses: actions/checkout@v4
      - uses: actions/download-artifact@v4
        with:
          name: build
          path: dist/
      - run: npm run deploy
yaml
name: CI/CD

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

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci
      - run: npm run lint

  test:
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npm ci
      - run: npm test

  build:
    runs-on: ubuntu-latest
    needs: test
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npm ci
      - run: npm run build
      - uses: actions/upload-artifact@v4
        with:
          name: build
          path: dist/

  deploy-production:
    runs-on: ubuntu-latest
    needs: build
    if: github.ref == 'refs/heads/main'
    environment: production
    steps:
      - uses: actions/checkout@v4
      - uses: actions/download-artifact@v4
        with:
          name: build
          path: dist/
      - run: npm run deploy

Deployment Strategies

部署策略

1. Blue-Green Deployment

1. 蓝绿部署

         ┌─────────┐
         │  Load   │
         │ Balancer│
         └────┬────┘
     ┌────────┴────────┐
     │    Switch       │
     ├────────┬────────┤
     ▼        ▼        ▼
  ┌─────┐ ┌─────┐ ┌─────┐
  │Blue │ │Green│ │     │
  └─────┘ └─────┘ └─────┘
         ┌─────────┐
         │  Load   │
         │ Balancer│
         └────┬────┘
     ┌────────┴────────┐
     │    Switch       │
     ├────────┬────────┤
     ▼        ▼        ▼
  ┌─────┐ ┌─────┐ ┌─────┐
  │Blue │ │Green│ │     │
  └─────┘ └─────┘ └─────┘

2. Rolling Deployment

2. 滚动部署

┌─────────────────────────────────────┐
│ v1  v1  v1  v1  v1  v1  v1  v1  v1 │ → Old
│ v2  v2  v2  v2  v2  v2  v2  v2  v2 │ → New
└─────────────────────────────────────┘
    ▲                       ▲
    │                       │
  Start                  End
┌─────────────────────────────────────┐
│ v1  v1  v1  v1  v1  v1  v1  v1  v1 │ → 旧版本
│ v2  v2  v2  v2  v2  v2  v2  v2  v2 │ → 新版本
└─────────────────────────────────────┘
    ▲                       ▲
    │                       │
  开始                    结束

3. Canary Deployment

3. 金丝雀部署

┌──────────────────────────────────────┐
│ v1  v1  v1  v1  v1  v1  v1  v1  v1  v1 │ → Old
│ v2  v2  v2  v2                        │ → Canary (5%)
└──────────────────────────────────────┘

Monitor metrics, then:
│ v1  v1  v1  v1                        │ → Old (50%)
│ v2  v2  v2  v2  v2  v2  v2  v2  v2  v2 │ → New (50%)
┌──────────────────────────────────────┐
│ v1  v1  v1  v1  v1  v1  v1  v1  v1  v1 │ → 旧版本
│ v2  v2  v2  v2                        │ → 金丝雀版本(5%流量)
└──────────────────────────────────────┘

监控指标后:
│ v1  v1  v1  v1                        │ → 旧版本(50%流量)
│ v2  v2  v2  v2  v2  v2  v2  v2  v2  v2 │ → 新版本(50%流量)

Environment Configuration

环境配置

Environment Variables

环境变量

bash
undefined
bash
undefined

Production

生产环境

NODE_ENV=production DATABASE_URL=postgresql://... API_KEY=sk-... SENTRY_DSN=https://example.com/123
NODE_ENV=production DATABASE_URL=postgresql://... API_KEY=sk-... SENTRY_DSN=https://example.com/123

Development

开发环境

NODE_ENV=development DATABASE_URL=postgresql://localhost:5432/dev
undefined
NODE_ENV=development DATABASE_URL=postgresql://localhost:5432/dev
undefined

Configuration Management

配置管理

typescript
// config/production.ts
export default {
  database: {
    url: process.env.DATABASE_URL,
    poolSize: 20,
  },
  redis: {
    url: process.env.REDIS_URL,
  },
};
typescript
// config/production.ts
export default {
  database: {
    url: process.env.DATABASE_URL,
    poolSize: 20,
  },
  redis: {
    url: process.env.REDIS_URL,
  },
};

Health Checks

健康检查

typescript
// GET /health
app.get('/health', (req, res) => {
  const health = {
    status: 'ok',
    timestamp: new Date().toISOString(),
    checks: {
      database: 'ok',
      redis: 'ok',
      external_api: 'ok',
    },
  };

  if (Object.values(health.checks).some(v => v !== 'ok')) {
    health.status = 'degraded';
    return res.status(503).json(health);
  }

  res.json(health);
});
typescript
// GET /health
app.get('/health', (req, res) => {
  const health = {
    status: 'ok',
    timestamp: new Date().toISOString(),
    checks: {
      database: 'ok',
      redis: 'ok',
      external_api: 'ok',
    },
  };

  if (Object.values(health.checks).some(v => v !== 'ok')) {
    health.status = 'degraded';
    return res.status(503).json(health);
  }

  res.json(health);
});

Rollback Strategy

回滚策略

bash
undefined
bash
undefined

Kubernetes

Kubernetes

kubectl rollout undo deployment/app
kubectl rollout undo deployment/app

Docker

Docker

docker-compose down docker-compose up -d --scale app=<previous-version>
docker-compose down docker-compose up -d --scale app=<previous-version>

Git

Git

git revert HEAD git push
undefined
git revert HEAD git push
undefined

Monitoring & Logging

监控与日志

Metrics to Track

需追踪的指标

  • Deployment frequency
  • Lead time for changes
  • Mean time to recovery (MTTR)
  • Change failure rate
  • 部署频率
  • 变更前置时间
  • 平均恢复时间(MTTR)
  • 变更失败率

Logging

日志记录

typescript
// Structured logging
logger.info('Deployment started', {
  version: process.env.VERSION,
  environment: process.env.NODE_ENV,
  timestamp: new Date().toISOString(),
});
typescript
// 结构化日志
logger.info('Deployment started', {
  version: process.env.VERSION,
  environment: process.env.NODE_ENV,
  timestamp: new Date().toISOString(),
});

Scripts

脚本

Generate deployment config:
bash
python scripts/generate_deploy.py <environment>
Validate deployment:
bash
python scripts/validate_deploy.py
生成部署配置:
bash
python scripts/generate_deploy.py <environment>
验证部署:
bash
python scripts/validate_deploy.py

References

参考资料

  • references/pipelines.md
    - CI/CD pipeline examples
  • references/kubernetes.md
    - K8s deployment configs
  • references/monitoring.md
    - Monitoring setup
  • references/pipelines.md
    - CI/CD流水线示例
  • references/kubernetes.md
    - K8s部署配置
  • references/monitoring.md
    - 监控设置