-
-
Notifications
You must be signed in to change notification settings - Fork 205
Description
While adding support for oci_image to rules_k8s I ran into the following issue.
I am pushing an image with --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 from my local osx machine and get the following error
push_push_api_image.sh: line 52: ../aspect_bazel_lib~~toolchains~jq_linux_amd64/jq: cannot execute binary file
Some investigation showed that I should set --extra_execution_platforms=@platforms//host, but this fails with the same error.
Investigating some more I found bazelbuild/bazel#19645 and https://github.com/bazel-contrib/rules_oci/blob/main/oci/private/push.bzl#L142-L155.
Together with the the fact that I am using Bazel 7.x and this commit bazelbuild/bazel@c602cec
Subsequent settings of --extra_execution_platforms now override previous settings, instead of adding them to a list.
I figured I can make it work with the snippet below. Instead of overwriting extra_execution_platforms, we preserve previous contents.
# Helper rule for ensuring that the crane and yq toolchains are actually
# resolved for the architecture we are targeting.
def _transition_to_target_impl(settings, _attr):
return {
# String conversion is needed to prevent a crash with Bazel 6.x.
"//command_line_option:extra_execution_platforms": [
str(platform)
for platform in settings["//command_line_option:extra_execution_platforms"] + settings["//command_line_option:platforms"]
],
}
_transition_to_target = transition(
implementation = _transition_to_target_impl,
inputs = ["//command_line_option:platforms", "//command_line_option:extra_execution_platforms"],
outputs = ["//command_line_option:extra_execution_platforms"],
)
I am not sure if this is the 'real' fix, but if it were then it would at least need a check for the Bazel version to do the right thing.