Skip to content

Commit 889e5ac

Browse files
authored
doc: bazel downloader (#3519) (#3530)
This adds documentation on how to configure the Bazel downloader in order to work with network isolated registries. Fixes #3519
1 parent c52aeaa commit 889e5ac

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/pypi/download.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,53 @@ available flags:
269269
[pep600]: https://peps.python.org/pep-0600/
270270
[pep656]: https://peps.python.org/pep-0656/
271271

272+
## Internal dependencies and private repositories
273+
274+
The `rules_python` Bazel module downloads Python interpreters and
275+
dependencies as part of its functionality. These artifacts are fetched
276+
using Bazel's internal HTTP downloader, not using the `pip` tool.
277+
278+
If you are in a network-restricted environment and must use internal
279+
registries, you can configure the Bazel downloader to redirect all of
280+
these downloads to a different registry.
281+
282+
Example of a `bazel_downloader.cfg`:
283+
```cfg
284+
all_blocked_message See internal.mirror.lan/registry/ for more information
285+
allow s3.amazon.com
286+
287+
# Rewrite everything to files.pythonhosted to the internal mirror with two
288+
# capture groups: the first group matches the host and is appended first,
289+
# the second matches the entire path and is appended second
290+
rewrite (files.pythonhosted.org)/(.*) internal.mirror.lan/python/$1/$2
291+
rewrite (pypi.python.org)/(.*) internal.mirror.lan/python/$1/$2
292+
293+
# Allow the internal mirror and block everything else
294+
allow internal.mirror.lan
295+
block *
296+
```
297+
298+
Use the config file with `--experimental_downloader_config=bazel_downloader.cfg`.
299+
300+
### How the config is parsed:
301+
302+
* Uses Java regular expressions
303+
* Matching is performed only on host and path components of the URL, not the scheme
304+
* Directives are applied in the following order: `rewrite, allow, block`
305+
* Back references are numbered starting from `$1`
306+
* Expressions must match the entire string being tested, not just find a substring.
307+
308+
If your patterns don't seem to match or rewrite:
309+
310+
* Begin with simple patterns to ensure they match as expected.
311+
* Be cautious when using `block` statements to avoid unintentionally blocking necessary downloads. Add `block` statements incrementally and test thoroughly after each change.
312+
313+
### References:
314+
315+
* [Configuring Bazel's Downloader](https://blog.aspect.build/configuring-bazels-downloader)
316+
* [URLRewriterConfig.java Source Code](https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/UrlRewriterConfig.java)
317+
* [Issue 3519](https://github.com/bazel-contrib/rules_python/issues/3519)
318+
272319
(credential-helper)=
273320
## Credential Helper
274321

0 commit comments

Comments
 (0)