Skip to content
返回部署

使用 Semaphore 部署

高性能 CI/CD,支持自动扩缩 runner 和基于 YAML 的流水线。

CI/CD进阶

为什么

Semaphore 针对速度优化,支持自动扩缩 runner 和快速缓存,适合大型测试套件。DORA 2024 DevOps 状态报告显示精英团队部署频率比低绩效团队高 973 倍。

带自动化测试的 CI/CD 管道将变更失败率降至 5-15%,而手动部署为 40-60%。

何时使用

需要快速 CI、自动扩缩和 monorepo 支持的项目。贡献者少于 5 人的仓库避免复杂管道编排 — pre-commit 钩子 + GitHub Actions 足够。

除非需要 GPU 或 VPN 访问,否则跳过自托管 runner。

如何做

# .semaphore/semaphore.YML version: v1.0 name: CI Pipeline agent: machine: type: e1-standard-2 os_image: ubuntu2004 blocks: - name: Build task: jobs: - name: npm build commands: - checkout - npm ci - npm run build - cache store build dist/ - name: Deploy dependencies: ["Build"] task: jobs: - name: deploy commands: - checkout - cache restore build - kubectl apply -f k8s/ 4. 验证部署 — curl -I https://your-app.example.com 5. 监控日志 — 前 5 分钟检查错误 6. 需要时回滚 — 回退到上一版本

示例

// 配置 — deploy-semaphore const config = require("./config"); # Semaphore promotion (auto-部署 on main) promotions: - name: Deploy to production pipeline_file: deploy.yml auto_promote_on: - result: passed branch: - main

常见问题

  • ⚠缓存未命中 — 确保 store/restore key 匹配
  • ⚠Runner 排队 — 增大 agent machine type
  • ⚠环境间配置漂移 — 使用基础设施即代码(Terraform/Pulumi)保持 dev/staging/prod 一致

最佳实践

  • ✓用 monorepo project analysis — 仅运行受影响 block
  • ✓用 auto-promotion — 合并到 main 时自动部署
  • ✓设置健康检查和优雅关闭 — 处理 SIGTERM 以在退出前排空进行中的请求

常见问题解答