bazelbuild / rules_docker

Rules for building and handling Docker images with Bazel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

toolchain configuration is not correctly invalidated when local install changes

nate-thirdwave opened this issue Β· comments

🐞 bug report

Affected Rule

The issue is caused by the rule: toolchain_configure

Is this a regression?

Not that it would appear.

Description

Bazel repository caching means that the toolchain_configure repository rule gets cached as it stands. Unfortunately the internals of this rule call out to repository_ctx.which() and thus are sensitive to the files that may or may not be available on the system. If a run of the toolchain_configure is done on a system without the docker binary, that result is cached and is not invalidated if docker is later installed and the bazel build is re-run.

πŸ”¬ Minimal Reproduction

Given a repo using rules_docker:

  1. bazel sync
  2. bazel build <target needing docker>
  3. -- observe successful build --
  4. sudo mv /usr/bin/docker /usr/bin/missing-docker
  5. bazel build <target needing docker>
  6. -- observe UNEXPECTED success --
  7. bazel sync
  8. bazel build <target needing docker>
  9. -- observe failure to find docker --
  10. sudo mv /usr/bin/missing-docker /usr/bin/docker
  11. bazel build <target needing docker>
  12. -- observe UNEXPECTED failure to find docker --

Expectation: Step 6 fails, and step 12 succeeds. Note that while in this example we removed the docker binary entirely, you could similarly simply update the docker binary version and have a lack of reproduceability as well.

I believe the difficulty is that we need to have the binary as a dep in some way. Possibly the repository rule could emit the sha256 of the chosen docker and xz binaries and take them in as attributes as well. If the user had specified the attributes, then the code would simply assert that the found binaries indeed match the attribute. In the "standard" use pattern though, the user does not specify these attributes and the toolchain rule always runs but because the hash is in the output and is stable, the dependent rules are still valid in the cache from run to run in the common case. If the binaries are updated, then the cached entries would have a different value and thus the dependent rules would also be re-run as needed.

πŸ”₯ Exception or Error






🌍 Your Environment

Operating System:

  
$ uname -a
Linux dev 5.18.10-76051810-generic #202207071639~1659403207~20.04~cb5f582~dev-Ubuntu SMP PREEMPT_DY x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.1 LTS
Release:	20.04
Codename:	focal

  

Output of bazel version:

  
$ bazel --version
bazel 4.2.0
  

Rules_docker version:

  
0.25.0 (release)
  

Anything else relevant?

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days.
Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_docker!

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"