trunkjet

Builds and dependencies

On this page

Bazel remote cache and remote execution

A trunkjet server can be the build cache for Bazel (and other tools that speak the Remote Execution API, version 2): build results are stored once and every developer machine and CI runner reuses them. It can also run build actions on separate workers. Both use the same accounts, tokens and repository permissions as the rest of trunkjet; there is no second system to administer.

What you get

  • Remote cache (REAPI content store and action cache). A build that someone else already did on the same inputs downloads in seconds instead of rebuilding. Measured on the project's own CI: a full run took 64 seconds with a warm cache against 55 minutes with a cold one.
  • Remote execution. Actions are queued in the server and run by tjet-exec workers, with fair sharing between tenants and repositories. Nobody is ever refused for load: requests wait in the queue.
  • Access control that follows the repository: a cache is per repository (the Bazel instance name is the repository name), a digest is never a capability, and a client may only use content it is allowed to read.

For build users

Bazel needs the server address, the instance name (the repository) and a trunkjet token.

Put the settings in a user.bazelrc file (not committed; Bazel's .bazelrc can import it). The token goes in the file, never on a command line, where logs would keep it:

build --remote_cache=grpcs://scm.example.com
build --remote_instance_name=acme/shop
build --remote_header=authorization=Bearer <token>

Use grpc:// instead of grpcs:// only for a loopback development server.

Who may do what:

WhoCache
Anyone who may read the whole repositoryread: downloads hits
service principals, such as the CI identityread and write: fill the cache
Developers and agentsread only, unless the operator turned on client_writes (development)

Read-only machines see update_enabled=false and Bazel skips uploads by itself. Give CI jobs a token of a service principal (create one with tjet agent token create, see Agents and MCP) and let only trusted jobs write: a cache that untrusted jobs can write lets them plant outputs. A job on an untrusted pull request should use a read-only token and --noremote_upload_local_results.

Add --remote_cache_compression to send and fetch zstd-compressed blobs; it saves bandwidth to a remote server (on a loopback server it only costs CPU). If the server's database stalls, the build carries on: lookups count as misses and uploads fail fast with a warning.

Remote execution

With execution enabled (below) add the executor, which is the same address:

build --remote_executor=grpcs://scm.example.com

The sandbox gives actions no network, a read-only system, a private /tmp and a time limit (15 minutes by default, 1 hour at most). Whoever may write to the repository may execute; an agent's actions run on separate, stricter workers (the "untrusted" pool).

See your builds

Every bazel command that uses the server shows up in the repository's Builds page and on the CI/CD page, next to the presubmit runs of changes. We group the calls of one command by the invocation id Bazel sends with each call. For each build you see the number of actions, how many came from the cache, how many ran on our workers, the most cores in use at once and the targets Bazel named. We keep these summaries for 30 days, at most 1,000 per repository.

The server never sees Bazel's own exit code or its log, so a build without a failed remote action reads "Finished", not "Passed". For a timeline, run Bazel with --profile.

For operators: turn it on

In tjetd.toml (or with tjetd --reapi, or the environment variable TJET_REAPI=1):

[reapi]
enabled = true            # the cache; off by default
execution = false         # set true (or TJET_REAPI_EXECUTION=1) to serve remote execution
# client_writes = false   # let humans and agents write the cache (development only)
# ttl_days = 30           # evict entries not used for this many days
# max_instance_bytes = 214748364800   # byte budget per repository (default 200 GiB)

The cache is served on the API listener, so it needs the same TLS as the API (grpcs://). Entries are removed after 30 days unused, or least recently used first when a repository exceeds its budget; the cache never deletes source content. Large outputs are stored compressed where that pays.

Workers

Remote execution needs at least one tjet-exec process on a Linux host with bubblewrap installed (/usr/bin/bwrap) and a delegated cgroup (without one it refuses to start, unless you pass --no-cgroup-limits, which is unsafe for untrusted code). It reads the same FoundationDB and content store as tjetd:

tjet-exec --work-dir /var/lib/trunkjet/exec --slots 8 --cache-gib 20

The settings are the same environment variables as the server's (TJET_FDB_CLUSTER_FILE, TJET_INSTALLATION, TJET_CELL, TJET_STORE, TJET_STORE_DIR or TJET_S3_*) plus TJET_EXEC_WORK_DIR, TJET_EXEC_SLOTS (default: number of CPUs), TJET_EXEC_CACHE_GIB (default 20) and TJET_EXEC_BWRAP. Add more workers to run more actions at once; a worker that dies loses only the actions it was running, and those go back in the queue (at most three attempts). --trusted workers may also run actions that use restricted inputs; --untrusted workers serve agents and should be separate machines. Run tjet-exec --help for every option.

On Kubernetes the chart can run worker pools; see Install on Kubernetes.

Limits to know about

  • Workers run on Linux today; macOS and Windows workers will join with their own pool.
  • Actions cannot use the network.
  • In the project's own measurement, remote execution matched Buildbarn at 8 slots and was slower at 16 slots; use it for isolation and sharing, not yet as a speed promise.