devops-automation

devops-automation

熱門

DevOps 與 IT 維運自動化 - CI/CD、監控、事件管理與基礎設施工作流程

316星標
70分支
更新於 2026/1/31
SKILL.md
唯讀
名稱
devops-automation
描述

DevOps 與 IT 維運自動化 - CI/CD、監控、事件管理與基礎設施工作流程

版本
1.0.0

DevOps 自動化

自動化 DevOps 工作流程,包括 CI/CD 管線、監控、事件管理與基礎設施操作。基於 n8n 的 IT 維運工作流程範本。

概述

此技能涵蓋:

  • CI/CD 管線自動化
  • 監控與警示
  • 事件管理
  • 基礎設施自動化
  • 部署工作流程

CI/CD 自動化

GitHub Actions 整合

workflow: "GitHub CI/CD 通知"

triggers:
  - github_push
  - github_pull_request
  - github_workflow_run
  
on_push:
  action:
    - trigger_ci: if_main_branch
    - notify_slack:
        channel: "#deployments"
        message: |
          📦 *新推送至 {branch}*
          
          提交:`{commit_sha_short}`
          作者:{author}
          訊息:{commit_message}
          
          [檢視差異]({compare_url})

on_pr_opened:
  action:
    - notify_slack:
        channel: "#code-review"
        message: |
          🔀 *新 Pull Request*
          
          標題:{pr_title}
          作者:{author}
          分支:{head} → {base}
          
          [審查 PR]({pr_url})
    - assign_reviewers: based_on_codeowners
    - run_ci_checks

on_workflow_complete:
  action:
    - notify_slack:
        message: |
          {status_emoji} *建置 {status}*
          
          工作流程:{workflow_name}
          分支:{branch}
          持續時間:{duration}
          
          {if_failed: [檢視日誌]({logs_url})}

部署管線

deployment_pipeline:
  stages:
    build:
      trigger: push_to_main
      steps:
        - checkout_code
        - install_dependencies
        - run_tests
        - build_artifact
        - push_to_registry
        
    staging:
      trigger: build_success
      steps:
        - deploy_to_staging
        - run_integration_tests
        - notify_qa
        
    production:
      trigger: manual_approval
      steps:
        - create_backup
        - deploy_to_production
        - run_smoke_tests
        - notify_team
        
  rollback:
    trigger: deployment_failed OR manual
    steps:
      - revert_to_previous
      - notify_team
      - create_incident

監控與警示

警示路由

alert_routing:
  sources:
    - prometheus
    - datadog
    - cloudwatch
    - new_relic
    
  severity_levels:
    critical:
      response_time: 5_minutes
      channels: [pagerduty, slack_urgent, sms]
      escalation: immediate
      
    high:
      response_time: 15_minutes
      channels: [slack_alerts, email]
      escalation: after_15_minutes
      
    medium:
      response_time: 1_hour
      channels: [slack_alerts]
      
    low:
      response_time: 24_hours
      channels: [slack_logging]
      
  routing_rules:
    - if: service == "payments"
      team: payments_oncall
      severity_boost: +1
      
    - if: service == "auth"
      team: security_oncall
      
    - default:
      team: platform_oncall

警示範本

alert_templates:
  infrastructure:
    cpu_high:
      title: "🔥 CPU 使用率過高"
      body: |
        伺服器:{host}
        CPU:{cpu_percent}%
        持續時間:{duration}
        
        閾值:{threshold}%
        
        [檢視儀表板]({grafana_url})
        
    memory_critical:
      title: "💾 記憶體不足"
      body: |
        伺服器:{host}
        記憶體:{memory_percent}%
        可用:{available_mb}MB
        
        [SSH 連線至伺服器]({ssh_link})
        
    disk_full:
      title: "💿 磁碟空間不足"
      body: |
        伺服器:{host}
        磁碟:{disk_percent}%
        可用:{available_gb}GB
        
        建議:清理日誌或擴充磁碟區
        
  application:
    error_spike:
      title: "📈 錯誤率飆升"
      body: |
        服務:{service}
        錯誤率:{error_rate}%
        正常值:{baseline}%
        
        主要錯誤:
        {top_errors}
        
    latency_high:
      title: "🐢 高延遲"
      body: |
        服務:{service}
        P99 延遲:{p99_ms}ms
        閾值:{threshold_ms}ms

事件管理

事件工作流程

incident_workflow:
  detection:
    sources: [monitoring, user_report, automated_check]
    
  triage:
    auto_severity:
      - if: affects_payments
        severity: critical
      - if: affects_auth
        severity: critical
      - if: affects_api AND error_rate > 10%
        severity: high
        
  response:
    critical:
      - create_incident_channel: "#inc-{timestamp}"
      - page_oncall: immediately
      - notify_stakeholders: [engineering_lead, product]
      - start_war_room: zoom_link
      - create_status_page: incident
      
    high:
      - create_incident_channel
      - notify_oncall: slack
      - create_ticket: jira
      
  communication:
    internal:
      frequency: every_30_minutes
      channel: incident_channel
      template: |
        📊 *事件更新*
        
        狀態:{status}
        影響:{impact}
        下次更新:{next_update_time}
        
        目前行動:
        {action_items}
        
    external:
      channel: status_page
      template: customer_facing_update
      
  resolution:
    steps:
      - confirm_resolution
      - update_status_page: resolved
      - notify_stakeholders
      - schedule_postmortem
      - close_incident_channel: after_24h

事後檢討範本

postmortem_template:
  sections:
    summary:
      - incident_title
      - duration
      - severity
      - impact
      
    timeline:
      format: |
        | 時間 | 事件 |
        |------|-------|
        | {time} | {event} |
        
    root_cause:
      - what_happened
      - why_it_happened
      - contributing_factors
      
    impact:
      - users_affected
      - revenue_impact
      - sla_breach
      
    resolution:
      - how_it_was_fixed
      - time_to_detect
      - time_to_resolve
      
    action_items:
      format: |
        | 行動 | 負責人 | 截止日期 | 狀態 |
        |--------|-------|----------|--------|
        
    lessons_learned:
      - what_went_well
      - what_went_poorly
      - lucky_breaks

基礎設施自動化

伺服器佈建

provisioning_workflow:
  trigger: jira_ticket OR slack_request
  
  steps:
    1. validate_request:
        check: [budget_approval, security_review]
        
    2. create_infrastructure:
        terraform:
          - vpc
          - security_groups
          - ec2_instances
          - load_balancer
          
    3. configure_server:
        ansible:
          - base_configuration
          - security_hardening
          - monitoring_agent
          - application_setup
          
    4. validate:
        - health_check
        - security_scan
        - performance_baseline
        
    5. notify:
        slack: "✅ 伺服器 {hostname} 已就緒"
        include: [ssh_access, dashboard_link]

排程維護

maintenance_automation:
  tasks:
    certificate_renewal:
      schedule: "到期前 30 天"
      action:
        - request_new_cert: letsencrypt
        - deploy_cert
        - verify_ssl
        - notify: if_failure
        
    security_patching:
      schedule: "每週"
      action:
        - check_updates
        - if_critical: immediate_patch
        - else: schedule_maintenance_window
        
    log_rotation:
      schedule: "每日"
      action:
        - rotate_logs
        - compress_old
        - upload_to_s3
        - delete_local: older_than_7_days
        
    backup_verification:
      schedule: "每週"
      action:
        - restore_to_test_env
        - run_integrity_checks
        - report_status

Kubernetes 自動化

K8s 工作流程

kubernetes_automation:
  deployment:
    trigger: docker_image_pushed
    steps:
      - update_manifest: with_new_image_tag
      - apply_to_staging
      - run_tests
      - if_success: apply_to_production
      
  scaling:
    trigger: metric_threshold
    rules:
      - if: cpu > 80%
        action: scale_up
        max_replicas: 10
      - if: cpu < 20%
        action: scale_down
        min_replicas: 2
        
  rollback:
    trigger: health_check_failed
    action:
      - kubectl_rollout_undo
      - notify_team
      - create_incident

輸出範例

請求:「設定 GitHub Actions 的部署通知」

輸出

# GitHub Actions 部署通知

## n8n 工作流程

```yaml
trigger: GitHub Webhook
events: [workflow_run]

通知範本

建置開始:

🚀 *部署已開始*

分支:main
提交:abc1234
作者:@developer
觸發原因:推送

[檢視工作流程](https://github.com/...)

建置成功:

✅ *部署成功*

環境:Production
持續時間:3m 42s
版本:v1.2.3

變更:
• 功能 X
• 錯誤修正 Y

[檢視部署](https://app.example.com)

建置失敗:

❌ *部署失敗*

階段:Test
錯誤:npm test failed

[檢視日誌](https://github.com/...)
[重試](https://github.com/...)

Slack 整合

channel: "#deployments"
mention_on_failure: "@oncall"
thread_replies: true

---

*DevOps 自動化技能 - Claude Office Skills 的一部分*