-
Notifications
You must be signed in to change notification settings - Fork 690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make transitions optional #2068
Conversation
3af18bd
to
7b061c0
Compare
Transitions, introduced in bazelbuild#1963 can now be disabled by calling bazel with `--@io_bazel_rules_docker//transitions:enable=no`. Added tests to verify the behaviour.
7b061c0
to
386a89f
Compare
Strange, //tests/docker/package_managers:install_pkgs_reproducibility_test fails in ci, but passes locally. I'm not sure how that would be related to the changes in this PR. I'd appreciate any input on how to debug this. |
I've updated the ubuntu base image, which caused the containers to rebuild and now it passes. Bazel probably had the targets cached built at different times. |
Thanks for the contribution! Initially it seems sensible, I'll take a proper look tomorrow if that's okay 😄 |
This is great & will help us a lot. Do we know when 0.25.0 will be released @uhthomas? |
return { | ||
"//command_line_option:platforms": settings["//command_line_option:platforms"], | ||
"@io_bazel_rules_docker//platforms:image_transition_cpu": "//plaftorms:image_transition_cpu_unset", | ||
"@io_bazel_rules_docker//platforms:image_transition_os": "//plaftorms:image_transition_os_unset", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there @laurynaslubys, First of all thanks a bunch for making these changes and my team has been really interested in something to address some of the overhead issues created by transitions which we think is a nice feature, but mostly not relevant to us because are target and host are always the same . I wanted to mention 2 things:
- I noticed this when I was trying to debug my own issue. But it looks like there is a typo here
plaftorm
instead ofplatform
. - I think one of the main reasons my team is interested in this MR is because it could reduce the number of rebuilds. Since 0.23, we will basically have to rebuild/recompile our entire pipeline, even though our host and target are the same, because I think the transition settings get hashed into the built directory. (i.e. our bazel-out directory
k8-fastbuild
becomesk8-fastbuild-ST-<someHashHere.
). I'm happy to open an issue, but I would really like if things could behave as before in rules_docker 0.22 where if you didn't explicitly specify something, it didn't create a new output directory for docker images.
I noticed that having the transitions:enable
flag be false causing this function to return an empty JSON object works. But it sounds like your comment says maybe that's an issue for people below Bazel 5.0.
This is still a great change and my no means want to downplay it. But at least wanted to share these thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cfife-btig Thank you for pointing this out. I spent several hours tracking down the exact same cache miss issue. Patching this to return an empty dict on 0.25.0 and turning transitions off has resolved my issue for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @scasagrande ! I just tracked it down today, only our version of Bazel doesn't seem to be compatible with the empty dict solution, so I'm looking at 0.22.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a dumb sanity check @abentley-ssimwave but are you setting io_bazel_rules_docker/transitions:enable=false
on the command-line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abentley-ssimwave well hello!! Yes I should have included my bazel version, we were on 5.2 at time of my prior comment and we're now up to 5.3.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like what should happen. You need to both use the patch and set the flag transitions:enable=false. Sorry if this is redundant, but if you're not doing both of those things together then I don't think it will disable transitions.
If you only set the flag, it just sets the directory <myoutdir>-hash
to <myoutdir>-somenewhash
because removing those build settings are just generating a new transition hash (when it should really remove the transition has altogether), whereas in 0.22, I believe there were no transitions to begin with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cfife-btig Yes, I set --@io_bazel_rules_docker//transitions:enable=false
you can see it in the output I posted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cfife-btig The result of using the flag with your patch on 3.4.1 is a whole pile of errors, and I do not agree that that "should" happen, although I can accept that there may not be a better solution for 0.25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm. I'm not sure then. My guess would be your version of Bazel is the issue. I think I'm on 5.2
Basically the patch file returns an empty dict instead of unset
, and i didn't write it but there's a comment implying it might not be supported in < 5.0 Bazel.
# Once bazel < 5.0 is not supported we can return an empty dict here
- return {
- "//command_line_option:platforms": settings["//command_line_option:platforms"],
- "@io_bazel_rules_docker//platforms:image_transition_cpu": "//plaftorms:image_transition_cpu_unset",
- "@io_bazel_rules_docker//platforms:image_transition_os": "//plaftorms:image_transition_os_unset",
- }
+ return {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cfife-btig Yes, I agree.
Just FYI, even with this disabling transitions (which I'm not totally sure is actually happening due to the typo I commented about above). The "unset" value still gets hashed. So even with this change applied working, all this does is change If you are trying to get docker rules to use the same bazel-out bins as the rest of your rules (so you have less rebuilding), your options are to either A.) Switch back to rules_docker 0.22 (before transitions were added) Here's the patch file I created from Git. I'm not guaranteeing you can copy/paste this, but it at least shows what needs to be changed. 0001-Remove-transition-settings.patch index ceeea01..f2762d4 100644
--- a/container/image.bzl
+++ b/container/image.bzl
@@ -769,11 +769,7 @@ _outputs["build_script"] = "%{name}.executable"
def _image_transition_impl(settings, attr):
if not settings["@io_bazel_rules_docker//transitions:enable"]:
# Once bazel < 5.0 is not supported we can return an empty dict here
- return {
- "//command_line_option:platforms": settings["//command_line_option:platforms"],
- "@io_bazel_rules_docker//platforms:image_transition_cpu": "//plaftorms:image_transition_cpu_unset",
- "@io_bazel_rules_docker//platforms:image_transition_os": "//plaftorms:image_transition_os_unset",
- }
+ return {}
return {
"//command_line_option:platforms": "@io_bazel_rules_docker//platforms:image_transition",
-- |
* Make transitions optional Transitions, introduced in bazelbuild#1963 can now be disabled by calling bazel with `--@io_bazel_rules_docker//transitions:enable=no`. Added tests to verify the behaviour. * Update ubuntu image to try to bust the bazel cache
Summary: Rules docker transitions the platforms option when building targets for a container. This causes duplicate builds of anything that ends up in a docker container. However, our containers are the same as our target platform so this is unnecessary. From rules_docker v0.25, they provide a flag `--@io_bazel_rules_docker//transitions:enable=false` to disable the transitions. However, there are some issues with this flag discussed here: bazelbuild/rules_docker#2068 (comment). So we also needed the patch suggested there in order to get it to work. This change reduces a clean `bazel build //...` from 4:48 on bombe to 3:30. Test Plan: Used bazel's execlog to check that the UI bundle is only built once after the changes. Reviewers: zasgar, vihang, michelle, #third_party_approvers Reviewed By: zasgar, vihang, #third_party_approvers Signed-off-by: James Bartlett <jamesbartlett@pixielabs.ai> Differential Revision: https://phab.corp.pixielabs.ai/D12605 GitOrigin-RevId: 557790be20042185b59d5641c9b3af8e94200178
For folks who aren't particularly thrilled about patches or simply want to disable transitions in a limited capacity, load("@io_bazel_rules_docker//container:container.bzl", "image")
load("@bazel_skylib//lib:dicts.bzl", "dicts")
container_image_without_transition = rule(
attrs = dicts.omit(image.attrs, ["_allowlist_function_transition"]),
executable = True,
outputs = image.outputs,
toolchains = ["@io_bazel_rules_docker//toolchains/docker:toolchain_type"],
implementation = image.implementation,
) |
Transitions, introduced in #1963 can now be disabled by calling bazel with
--@io_bazel_rules_docker//transitions:enable=no
.Added tests to verify the behaviour.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Transitions based on container_image attributes were always enabled.
Issue Number: N/A
What is the new behavior?
Transitions based on container_image attributes are enabled by default, but can be disabled by specifying
--@io_bazel_rules_docker//transitions:enable=false
Does this PR introduce a breaking change?
Other information