-
Notifications
You must be signed in to change notification settings - Fork 463
Speed up bazel CI builds via smarter caching #5142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Fixes #5142. Signed-off-by: Steffen Smolka <steffen.smolka@gmail.com>
Speeding up Bazel CI builds through smarter caching (#5142) can significantly reduce build times and resource consumption. Here’s how to optimize Bazel’s caching strategy for CI: 1. Enable Remote CachingBazel supports remote caching, which allows build outputs to be shared across different CI runs, preventing redundant compilations. Solution: Use a Remote Cache (e.g., Google Cloud, S3, or BuildBuddy)Modify your CI configuration to use a remote cache: bazel build --remote_cache=<your-remote-cache-url> --remote_upload_local_results If using Google Cloud Storage, configure it as follows: bazel build --remote_cache=grpc://bazel-cache.example.com For AWS S3, use: bazel build --experimental_remote_cache=your-s3-bucket-url 👉 Benefit: Cache reuse across different CI jobs. 2. Use Persistent Disk Caching in CITo store build artifacts locally, enable disk caching in your CI pipeline: bazel build --disk_cache=/cache/bazel In a Docker-based CI, mount a persistent volume for 👉 Benefit: Faster builds for frequently changed code. 3. Enable Remote Execution (Optional)If you have a distributed build environment, configure Bazel Remote Execution to offload computations. bazel build --remote_executor=grpc://build-cluster.example.com 👉 Benefit: Speed up builds by distributing workloads. 4. Reduce Unnecessary RebuildsModify build --repository_cache=~/.bazel-cache
build --config=ci Add bazel test --config=ci //... 👉 Benefit: Avoid rebuilding unchanged dependencies. 5. Optimize CI Cache KeysFor GitHub Actions, cache Bazel’s outputs: - name: Cache Bazel
uses: actions/cache@v3
with:
path: ~/.cache/bazel
key: ${{ runner.os }}-bazel-${{ github.sha }}
restore-keys: |
${{ runner.os }}-bazel- 👉 Benefit: Restores previous builds for faster execution. 6. Use
|
That's great to hear! https://github.com/p4lang/p4runtime/blob/main/.github/workflows/ci-build-proto.yml should be a great template, |
The bazel builds we run for continuous integration could likely be sped up significantly by using a smarter caching scheme, like P4Runtime and p4-constraints.
The text was updated successfully, but these errors were encountered: