bazelbazel-remote-cachebazelisk

How to make Bazel remote caching $USER agnostic?


I'm working on a Bazel/Bazelisk configured project and need to use remote caching (using bazel-remote) in order to let developer machines use build artifacts generated on powerful build machines.

This scenario already works for me in general, but when I started to use Bazelisk the build cache was not used on all machines anymore.

Analyzing the execution log you get via --execution_log_json_file=<PATH> I found out that Bazel implicitly (and silently) captures the current user's $PATH in environmentVariables but also </path/to/home>/.cache/bazelisk/downloads/bazelbuild/bazel-7.1.1-linux-x86_64/bin:</path/to/home>/.cache/bazelisk/downloads/sha256/<SHA>/bin gets added to $PATH.

While it makes sense to take $PATH into account when looking for cached artifacts, and Bazelisk's bin folders have to be considered.. this breaks remote cache capabilities of course when user names differ (at least by default).

How am I supposed to solve this?

Should I create a 'well known folder' on every build machine/container which is user-agnostic and point Bazelisk to that folder?

Or can I somehow tell Bazel/Bazelisk to keep the .cache folder where it wants it to be (or where I want it to be) but not take it as input for environmentVariables used for the remote cache key? How?

And there might be some more options that come to my mind to workaround this behavior, but what's the intended approach?


Solution

  • Typically, one forces the action path be consistent with --incompatible_strict_action_env.

    (It's not just the bazelisk PATH entry to worry about. Developers like to mess with PATH to, for example, add their custom script directories.)