-
Notifications
You must be signed in to change notification settings - Fork 691
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
Transition container image target platform #1963
Conversation
7cc6c1d
to
d889a1e
Compare
I noticed that unlike |
@smukherj1 do you have any answer to that question about why Java is different in this regard? |
@alexeagle Thanks for taking a look! I'm not too familiar with the java image rules, java rules or cross-compilation of java. I'm not sure what effect changing the target platform would have, if any. A cursory Google shows that Java may sometimes depend on C as you suggested. As such, even if the JARs are portable, the C would still need to be built for the correct target platform. |
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.
This seems fantastic. Does it mean users no longer need to specify a --platform
on the command line when building an image? I think some documentation update may be required too.
Maintainers here don't know much about transitions, we'll try to get someone from the bazel team to help verify.
ecf7f7e
to
a76c92d
Compare
Thanks @alexeagle! You're absolutely correct, explicitly targeting platforms with the I think you're right that some documentation updates may be in order. I'll take a look tomorrow. 😄 |
fd04391
to
73964b2
Compare
Hey @uhthomas I tried consuming rules from your repo.
I'm using the same command which runs when using
I get error related to bazelbuild/bazel#10134
I'm using |
Thank you for trying out these changes @ahmedkirasystems. You're completely right and I feel silly for not testing this on a more minimal repo which doesn't have additional CC toolchains. I cannot reproduce this with a minimal container_image(name = "some_image") but I can reproduce this with go_image(
name = "some_image",
embed = [":some_lib"],
)
This behaviour can be observed with rules_docker v0.21.0 and the following # fail
go_image(
name = "some_image",
embed = [":some_lib"],
goarch = "amd64",
goos = "linux",
pure = "off",
)
# ok
go_image(
name = "some_image",
embed = [":some_lib"],
goarch = "amd64",
goos = "linux",
pure = "on",
)
# ok
go_image(
name = "some_image",
embed = [":some_lib"],
goarch = "amd64",
goos = "linux",
pure = "auto",
)
# ok (implicit `pure = "auto"`)
go_image(
name = "some_image",
embed = [":some_lib"],
goarch = "amd64",
goos = "linux",
) This seems like some weird behaviour on Side note: I spent a little bit trying to understand why both I was going to suggest that this could be fixed by setting So I think the correct fix is either transition Sorry, I understand this comment is quite long. TL;DR: The |
I wonder if there's some sort of subtle bug somewhere in
So, I'm not sure why pure mode is not enabled when there is no C/C++ toolchain. |
47c404c
to
719cfdf
Compare
rules_docker is hard to maintain due to all the languages being supported in this repo! I don't know the answer for this Go transition question either. Does it make sense to cut scope of this PR to cover everything except Go? Or else maybe we need another maintainer like @pcj (or a rules_go maintainer like @achew22 or @steeve ) to advise why the auto-selection of |
I was trialing some changes which would configure cgo on behalf of bazel build --platforms=//:linux_x86_64 //:some_bin platform(
name = "linux_x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:linux",
],
)
# fail
go_binary(
name = "some_bin",
embed = [":some_lib"],
visibility = ["//visibility:public"],
)
# fail
go_binary(
name = "some_bin",
embed = [":some_lib"],
pure = "off",
visibility = ["//visibility:public"],
)
# fail
go_binary(
name = "some_bin",
embed = [":some_lib"],
pure = "on",
visibility = ["//visibility:public"],
)
# ok
go_binary(
name = "some_bin",
embed = [":some_lib"],
goarch = "amd64",
goos = "linux",
visibility = ["//visibility:public"],
)
# ok
go_binary(
name = "some_bin",
embed = [":some_lib"],
goarch = "amd64",
goos = "linux",
pure = "on",
visibility = ["//visibility:public"],
) |
Is it possible to update the release notes for |
@uhthomas what about the config option to disable transitions? #1963 (comment) |
@uhthomas In the (probably very common) case of a Linux x86_64 image built as part of a build with target platform Linux x86_64, the transition to a synthetic platform will change the configuration and thus cause all dependencies of the image to be rebuilt. Do you think that it would be feasible to move the configuration change from an incoming to an outgoing dependency edge, perhaps by wrapping the image rules in a macro that applies a forwarding rule? This would make it possible to make the transition a no-op if CPU and OS are already at the expected values. |
Sounds like a reasonable suggestion. I can cut a PR for that soon. |
That's an interesting idea, I like it. Would you be able to help me understand how the transition would become no-op by switching to an outgoing dependency edge? |
@uhthomas I've thought more about it and now see two ways to prevent rebuilds:
Happy to provide more details and think about further alternatives. |
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.
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.
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.
I think it's a good idea to merge #2068. The next LTS release of Bazel will include optional toolchains, which should resolve this whole thing altogether bazelbuild/bazel#3601 (comment). |
The next LTS release is still half a year away isn't it? |
* Make transitions optional 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. * Update ubuntu image to try to bust the bazel cache
the suggestion
|
@thefallentree which version of rules_docker are you using? (including sha256) |
I've been using this.
which doesn't work, so I have been stuck on 0.22.0. instead. And just to clarify , 0.23.0 doesn't work for me because of java_image rule is complaining about unresolved c++ toolchain, so I'm not sure how that's possible, do you have any more information about it? |
For anyone landed here: Now with you can now use and it should work! |
I don't know what other people's use cases are - it sounds like a lot of people wanted a disable transitions flag because of an error with go images in macOS. For us, we are having some inconveniences because as I believe @fmeum has said, the build configurations for images are different which is causing us to have to reproduce all of the build steps anytime we build an image, even if I had already built all the prior steps. Since we don't have any special build targets, I went ahead and tried using the new disable transitions flag, but I don't think this works at least for my use case. Images still have a different build configuration and makes me run my pipeline from scratch. Maybe optional toolchaining or something like what @fmeum suggested would be better. Or maybe this is an issue with the disable transitions flag. In the meantime, my team has not felt like the latest releases have caused more slowness then help, so we've just been staying at 0.22 rules_docker since we don't have any special build targets. |
* 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
Transition to the target platform associated with the
architecture
andoperating_system
attributes on container image rules.This change allows for container image rules to build the correct binary for
the target platform, regardless of the host platform. Container image rules
would require the use of the
target_compatible_with
attribute to preventmismatching host and target platforms building dependencies incorrectly.
Additionally, hosts which did not match the target platform had to explicitly
specify the target platform with the
--platforms
command-line option.This change fixes the aforementioned issues and
#690.
Massive thank you to @joneshf for the initial source. It has been adapted to
automatically select the target platform associated with the container image,
as opposed to always using
@io_bazel_rules_go//go/toolchain:linux_amd64
.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?
Issue Number: #690
container_image
rules do not transition the target platform.What is the new behavior?
container_image
rules transition the target platform associated with thearchitecture
andoperating_system
attributes.Does this PR introduce a breaking change?
Other information