local_repository vs http_archive for Private Dependencies Under Hermetic Sandbox
0 reputation · 14 Jul 2020, 05:29 UTC
0 reputation · 14 Jul 2020, 05:29 UTC
A workspace declares a private dependency that exists on developer machines at a fixed absolute path. Using local_repository in WORKSPACE (or MODULE.bazel with local_path_override) lets the build succeed locally without network access. In production CI and remote execution, the same absolute path does not exist, and the hermetic sandbox prevents access to undeclared host files, causing the build to fail.
--incompatible_strict_action_env, sandbox mode) is mandatory in production and remote executors.sha256 is available without an internal artifact server.Switching to http_archive with an internal URL and declared sha256 restores hermeticity and reproducibility, but requires publishing the artifact to an internal server and populating the remote cache. Keeping local_repository preserves local speed but breaks production unless the same path is materialized in every executor (e.g., via a checked-in vendor directory or CI-mounted volume), which re-introduces non-hermetic assumptions.
Which approach better satisfies the constraint that the same source tree must build identically on a developer laptop, in CI, and on a remote executor without manual path provisioning? Should the dependency be vendored into the repository to avoid both network fetch and host-path reliance, or is an internal artifact server with pre-seeded remote cache the lower-maintenance path?
35275 reputation · 14 Jul 2020, 08:45 UTC
For a private dependency that must build identically on a developer laptop, in CI, and on remote executors without manually provisioning host paths, the recommended approach is to use http_archive pointing to an internal artifact server with a declared sha256 and to ensure the artifact is pre‑populated in the remote execution cache. This satisfies hermeticity and reproducibility while keeping the developer workflow fast.
local_repository binds the workspace to an absolute host path; under Bazel’s hermetic sandbox (--incompatible_strict_action_env) the build fails in CI or remote execution when that path is missing or inaccessible.http_archive fetches a tarball from a URL and validates it with a declared sha256. When the artifact is served by an internal mirror and the hash matches, the same WORKSPACE or MODULE.bazel definition works unchanged on a developer machine (if the internal mirror is reachable) and in CI/remote execution without any host‑path mounts.http_archive solutionmydep-1.2.3.tar.gz) to an internal artifact server that is accessible from developer machines and from the remote execution environment.sha256 of the tarball and record it in the WORKSPACE or MODULE.bazel definition:http_archive(
name = "my_private_dep",
urls = ["https://internal-artifacts.example.com/mydep-1.2.3.tar.gz"],
sha256 = "abcd1234..." # replace with actual hash
)bazel build //... --incompatible_strict_action_envIf the dependency is very small, changes infrequently, and the team accepts the extra repository size, vendoring removes the need for an internal server and guarantees zero‑network fetches. However, this approach trades maintenance overhead for simplicity and may not scale well for larger binaries or frequently updated libraries.
Knowing the approximate size of the private dependency and how often it updates would help decide whether the maintenance cost of vendoring outweighs the operational overhead of running an internal artifact server. If the artifact is large (> 100 MB) or updated weekly, the internal server with pre‑seeded cache is clearly lower‑maintenance; if it is tiny (< 1 MB) and stable, vendoring becomes a viable alternative.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.