Skip to content

云原生构建介绍

云原生构建基于 Docker 生态,对环境、缓存和插件进行了抽象。通过声明式语法,帮助开发者更高效地构建软件。

  • 声明式:可编程、易分享的配置语法。
  • 易管理:与代码同源管理,版本可追溯。
  • 云原生:资源池化,降低基础设施运维负担。

构建环境声明

.cnb.yml

yaml
main:
  push:
    - docker:
        image: node:20
      stages:
        - node -v
        - npm install
        - npm test

构建缓存声明

.cnb.yml

yaml
main:
  push:
    - docker:
        image: node:20
      volumes:
        - /root/.npm:copy-on-write
      stages:
        - node -v
        - npm install
        - npm test

Docker 作为任务的运行环境

.cnb.yml

yaml
main:
  push:
    - stages:
        - name: run with node 20
          image: node:20
          script: node -v
        - name: run with node 21
          image: node:21
          script: node -v

基于 Docker 生态的插件

.cnb.yml

yaml
main:
  push:
    - stages:
        - name: hello world
          image: cnbcool/hello-world

按需获取计算资源

.cnb.yml

yaml
main:
  push:
    - runner:
        cpus: 64
      docker:
        image: node:20
      stages:
        - node -v
        - npm install
        - npm test

云原生开发

.cnb.yml

yaml
$:
  vscode:
    - runner:
        cpus: 64
      services:
        - vscode
      docker:
        image: node:20
      volumes:
        - node_modules:copy-on-write
      stages:
        - npm install

高性能

CPU 弹性伸缩

  • runner.cpus: 通过 runner.cpus 可按需申请 CPU 资源,最高 64 核。

秒级克隆

基于 OverlayFS 的 git-clone-yyds 可在数秒内完成代码准备,轻松支持 100GB+ 超大仓库。

缓存并发

  • copy-on-write: copy-on-write 可实现缓存的写时复制,并发场景下无需担心缓存读写冲突。 .cnb.yml
yaml
main:
  push:
    - runner:
        cpus: 64
      docker:
        image: node:20
      volumes:
        - /root/.npm:copy-on-write
      stages:
        - node -v
        - npm install
        - npm test

相关文档

基础使用

插件

进阶使用

迁移指南

示例介绍