Cloud Native 15 min read

How CNB Delivers Seconds‑Level AOSP Clone and Scales Concurrent Builds

A cloud‑native CI platform called CNB uses a custom git‑clone‑yyds plugin and Copy‑on‑Write overlayfs to reduce cloning of the 124 GB AOSP source tree from 20 minutes to a few seconds while keeping cache safe for high‑concurrency pipelines, dramatically cutting overall build time.

Tencent Cloud Developer
Tencent Cloud Developer
Tencent Cloud Developer
How CNB Delivers Seconds‑Level AOSP Clone and Scales Concurrent Builds

Background and Challenges

The team needed to build a custom ROM based on Android 14, requiring the full AOSP source (≈124.44 GB across 1,400 repositories). Pulling the code with repo took about 20 minutes, consumed massive disk space on each developer machine, and limited CI throughput because each pipeline had to clone the whole repository and could not run concurrently.

Long clone time: 20 minutes for a full pull.

Huge storage footprint: 125 GB per workstation.

Low efficiency: CI pipelines stalled at code preparation (≈20 min) and build (≈46 min), with total cycle >1 hour.

Concurrency bottleneck: Only one pipeline could use the workspace at a time; parallel pipelines caused conflicts and cache pollution.

Solution Overview: CNB

CNB (Cloud Native Build) is a cloud‑native CI system built on Docker that abstracts environment, cache, and plugins with a declarative syntax. Its key feature, “秒级克隆” (second‑level clone), prepares code in a few seconds regardless of repository size and is safe for concurrent builds.

Key URLs:

CNB homepage: https://cnb.cool

git‑clone‑yyds plugin source: https://cnb.cool/cnb/cool/git-clone-yyds

Migration Steps

Move the AOSP repo from repo to a single monorepo hosted on CNB’s Git service.

Create a Dockerfile based on Ubuntu 18.04 that contains the AOSP build environment.

Define the pipeline declaratively (Everything as Code) using CNB’s YAML‑style configuration.

build_config: &aosp_build_config
  runner:
    cpus: 64
  docker:
    build: .ide/Dockerfile
    volumes:
      - out:copy-on-write
  stages:
    - name: build
      env:
        BUILD_HOSTNAME: cnb-build
        shell: |
          source build/envsetup.sh
          lunch aosp_arm-eng
          make -j64
      script: bash -e -c "${shell}"

# Test with 6 concurrent pipelines
main:
  push:
    - *aosp_build_config
    - *aosp_build_config
    - *aosp_build_config
    - *aosp_build_config
    - *aosp_build_config
    - *aosp_build_config

Performance Results

First run (no cache): Clone 16 min 52 s (124.44 GB); Build 46 min 4 s.

Subsequent runs (with cache, 6 concurrent pipelines): Clone 3.8 s; Build 1 min 30 s.

These numbers show roughly a 200× speedup for code preparation and a 30× reduction in total build time.

Second‑Level Clone Mechanism

CNB achieves the fast clone via the open‑source git-clone-yyds plugin. The first clone populates a persistent cache on the master machine. Later pipelines mount this cache read‑only as the lower layer of an OverlayFS mount, then create a writable upper layer for the workspace. Because the lower layer is shared, all pipelines can start in seconds while keeping their modifications isolated.

Copy‑on‑Write (CoW) Principle

CoW allows multiple processes to share the same underlying files until a write occurs, at which point a private copy is created. Docker already uses OverlayFS for this purpose. CNB leverages the same technique: the cached Git repository lives in lowerdir, each pipeline gets its own upperdir, and the merged view presents an isolated workspace.

OverlayFS workflow:

Unmodified files appear directly from lowerdir.

Modified files are copied to upperdir and read from there.

Deleted files are marked as “whiteout” in upperdir.

New files are created in upperdir.

OverlayFS illustration
OverlayFS illustration

git‑clone‑yyds Workflow

Initialize or update the Git cache ( git init + git fetch).

Mount the cache as lowerdir via OverlayFS, create an empty upperdir, and expose the merged view as /workspace.

Run checkout, build, etc., inside the merged view; writes trigger CoW copies.

After the build, discard the temporary upperdir.

git-clone-yyds workflow diagram
git-clone-yyds workflow diagram

Performance Characteristics of git‑clone‑yyds

Time complexity: O(1) – clone time independent of repository size.

Space complexity: O(1) – storage does not grow with concurrency.

Key Takeaways

Seconds‑level code preparation for massive monorepos.

Safe concurrent pipeline execution without cache pollution.

Significant reduction of overall CI cycle time, making large‑scale Android builds practical.

Repository address used in the tests: https://cnb.cool/aosp/monorepo

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performanceCloud Nativeci/cdCopy-on-WriteAOSPGit Clone Optimization
Tencent Cloud Developer
Written by

Tencent Cloud Developer

Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.