This tutorial points Bazel at a Virtual Registry that caches the Bazel Central Registry, or a Bazel Modules repository in JFrog Artifactory. The modules a MODULE.bazel depends on, and the archives they are built from, are then downloaded through the cache.
MODULE.bazel), the default since Bazel 7.virtual_registry:
registries:
- name: bazel
remotes:
- url: https://bcr.bazel.build
The examples below reach the registry as https://bazel.example.com, a host that the registry named bazel answers (see name).
Most modules in the Bazel Central Registry are downloaded from another host, mostly GitHub releases. The registry rewrites the archive URL in each version’s source.json to run through it, so Bazel needs no --downloader_config. With deny_unknown_hosts set, the hosts the archives are on, and the hosts they redirect to, have to be listed in extra_known_hosts. For archives on GitHub releases, that is GitHub and the host it redirects downloads to:
virtual_registry:
redirects:
deny_unknown_hosts: true
extra_known_hosts:
- github.com
- release-assets.githubusercontent.com
A module whose archive is on another host needs that host listed as well.
Package types describes how the registry files and the archives are cached.
Set the registry in .bazelrc, in the workspace or in your home directory:
common --registry=https://bazel.example.com/
Builds now resolve and download through the registry:
bazel fetch //...
MODULE.bazel.lock records the files it read from a registry under their URL, so the first build after the change updates the lockfile. The mirror_urls in source.json are left pointing at their own hosts, so if a download through the registry fails, Bazel falls back to them directly, outside the cache.
A Bazel Modules repository in JFrog Artifactory is reached under its API path. With https://artifactory.example.com as the registry’s remote, --registry names the repository on the registry’s host:
common --registry=https://bazel.example.com/artifactory/api/bazelmodules/<repo>/
Artifactory points each archive at itself, and those URLs are rewritten to the registry’s base URL too. With deny_unknown_hosts set, check whether Artifactory redirects archive downloads to its cloud storage, as JFrog’s SaaS does. The Location of a curl -I on an archive URL in Artifactory names the host, such as <bucket>.s3.amazonaws.com, which then has to be listed in extra_known_hosts. A local repository can replace a version that was already published, so set max_ttl on a registry in front of one, or a replaced version keeps being served from the cache:
virtual_registry:
registries:
- name: bazel
max_ttl: 86400
remotes:
- url: https://artifactory.example.com
--remote_cache) stores build outputs, not modules, and is not served by the Virtual Registry.