Set up the Bazel cache
Bazel can keep what it builds in a remote cache and reuse it on every other machine. Snowstead works with Bazel's built-in remote cache, over HTTP or gRPC, so there's nothing to install. Bazel still runs the build on your machines.
Create a cache in the dashboard and enable Bazel, or turn it on in an existing cache's Settings. A cache can hold any mix of Nix, Go, sccache, and Bazel, with the same visibility and tokens.
A machine that reads downloads what the cache already holds and uploads nothing. A machine that reads and writes also uploads what it builds, so other machines skip that work and use what it uploaded. Writing always needs a token that can write. You choose which machines get one.
1. Point Bazel at your cache
Add the cache's address to the .bazelrc in your repository. It holds no secret, so commit it and every machine picks it up.
This example uses organization acme and cache main; your cache's Bazel tab has the flags with your own address.
build --remote_cache=https://acme.snowstead.com/main/bazel
The HTTP address is your cache's address followed by /bazel: https://<org-slug>.snowstead.com/<cache-name>/bazel. Bazel adds /ac/ and /cas/ itself; don't add them.
HTTP and gRPC reach the same entries, so machines can mix them. Use TLS for every connection that isn't local.
2. Build with the cache
Create a token under Tokens in the dashboard that reads this cache, and store it as SNOWSTEAD_TOKEN in your shell profile. The last flag turns uploads off, whatever the token allows.
A .bazelrc doesn't expand environment variables, so pass the token on the command line, or use Bazel's credential helper.
Keep it out of source control.
bazel build //... \ --remote_header="Authorization=Bearer $SNOWSTEAD_TOKEN" \ --remote_upload_local_results=false
3. Use it in CI
Store the token as the SNOWSTEAD_TOKEN repository secret. GitHub gives workflows from fork pull requests no secrets, so those runs
have no token and can't read a private cache, and this workflow runs them without the cache.
on:
push:
branches: [main]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build with the cache
if: ${{ !github.event.pull_request.head.repo.fork }}
env:
SNOWSTEAD_TOKEN: ${{ secrets.SNOWSTEAD_TOKEN }}
run: |
bazel build //... \
--remote_header="Authorization=Bearer $SNOWSTEAD_TOKEN" \
--remote_upload_local_results=false
- name: Build fork pull requests without the cache
if: ${{ github.event.pull_request.head.repo.fork }}
run: |
bazel build //... \
--remote_cache= What makes a hit
Machines share only what they build the same way. Bazel decides which outputs are reusable; Snowstead doesn't change your build.
- The same Bazel version and flags. Pin the version in
.bazelversionand keep shared flags in.bazelrc. - The same toolchains. Compilers and SDKs found on the machine are inputs too, so a Mac's builds never match Linux CI's.
--incompatible_strict_action_enveverywhere, so each shell'sPATHstays out of the keys.
Whatever a build outputs is uploaded, and build logs can be too. A secret written into a generated file or a stamped binary is stored like any other output. Keep secrets out of builds, and keep the cache private when in doubt.
4. Check that it works
Build a target, then build the same commit on another machine, or from a clean output directory as below, with the same toolchain and flags. A local incremental build alone doesn't prove the remote cache works.
bazel --output_user_root="$(mktemp -d)" build //... \ --remote_header="Authorization=Bearer $SNOWSTEAD_TOKEN" \ --remote_upload_local_results=false \ --remote_download_outputs=all
Bazel's last lines say where each action came from. Look for remote cache hit:
INFO: Elapsed time: 21.412s, Critical Path: 3.12s
INFO: 2847 processes: 2846 remote cache hit, 1 internal.
INFO: Build completed successfully, 2847 total actions - No
remote cache hit: check the address, read permission, and whether the first build used the same inputs. See What makes a hit. Evicted outputs are normal misses and build again. - Unauthenticated: supply a current token. See Tokens.
- Permission denied: check the token's caches and Bazel permissions, and whether your tier includes private caches.
- Invalid digest or size: the uploaded bytes don't match their declared SHA-256 or size. Never disable Bazel's download verification.
Retention and limits
Bazel entries have no fixed lifetime. In the background, the least recently used entries go first, approximately: reads are sampled, so entries you use often usually stay longer. Uploads never wait for space, so stored bytes can pass the storage target for a while. Each Bazel cache gets an equal share of the organization's storage left after other products, capped by its own target.
A successful upload isn't a promise to keep an entry. Eviction can race an upload of the same digest and cause another miss. Readers only receive verified, complete blobs; a miss makes Bazel build the output again.
Usage totals are measured in the background and can lag uploads and eviction. The Bazel tab shows when they were measured, with stored blobs and uploads in progress listed separately. Replaced entries are reclaimed on the next collection; interrupted uploads are cleaned up after two hours.
Blobs can be up to 8 GiB, hashed with SHA-256. A proxy in front of your builds can impose a lower upload limit; a 413 response means the request exceeded it. Batch requests and action results are limited to 4 MiB. An action result can reference up to 16 MiB of distinct output trees and 100,000 output and traversed nodes.
Upload sessions expire after one hour. A gRPC upload must make progress within 30 seconds and finish within one hour. The service offers uncompressed transfers and caching for Remote Execution API 2.0 and 2.1; it doesn't run builds remotely.
For Nix setup, see Getting started.