Configuring the Bitrise Build Cache for Bazel in local environments
You can use the Bitrise Build Cache for Bazel on any machine: you just need to create a bitrise.bazelrc
configuration file that includes the required configuration for the cache endpoints.
-
Generate a Personal Access Token on Bitrise: Creating a personal access token.
Copy the value of the token, as you will need it during the process.
-
Find your Workspace ID: open the Workspace settings page and select General settings on the left navigation menu. You can find and copy the slug from there.
-
Set the following Environment Variables in your CI configuration:
-
BITRISE_BUILD_CACHE_AUTH_TOKEN
: The value should be your Personal Access Token. -
BITRISE_BUILD_CACHE_WORKSPACE_ID
: The value should be the Bitrise Workspace slug.
-
-
Download the CLI and install it in a temporary location. You will only need to use it to activate the build cache once, or if any of the settings change.
curl --retry 5 -sSfL 'https://raw.githubusercontent.com/bitrise-io/bitrise-build-cache-cli/main/install/installer.sh' | sh -s -- -b /tmp/bin -d
-
Activate the Bitrise Build Cache.
There are a couple of flags you can use to control the configuration, but we recommend these defaults:
/tmp/bin/bitrise-build-cache activate bazel --cache --cache-push=false
Pulling from cache
We recommend only pulling artifacts from the cache to avoid accidentally sharing incorrect cache data due to file modifications during a build.
For the full list of flags check the CLI’s
/tmp/bin/bitrise-build-cache activate bazel --help
command. -
If you have Remote Build Execution enabled for your workspace, you can also use it locally by adding the
--rbe
flag.Enabling RBE locally
You will need to have the workers set up for your workspace, and the pool configuration in your repository’s
.bazelrc
file before enabling RBE locally! -
Optionally, add your repository URL in your repository’s root
.bazelrc
file.We recommend doing this to be able to identify your local builds.
Replace the URL
Make sure to replace the placeholder URL in the command with your own!
build --remote_header='x-repository-url=https://github.com/bazelbuild/bazel.git' build --bes_header='x-repository-url=https://github.com/bazelbuild/bazel.git'
That's it! You can now run any bazel
commands and take advantage of the Bitrise Build Cache. You can check the invocation details through the link printed during builds:
