bazel-contrib / bazel-contrib/rules_oci
oci_push rule fails on osx when pushing a linux image
- Dominant language
- Starlark
- Stars
- 423
- Forks
- 213
- Avg merge
- 53m
- Merged PRs (30d)
- 1
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 https://github.com/bazelbuild/bazel/issues/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 https://github.com/bazelbuild/bazel/commit/c602cec7887470db3e8ed69600f5bd2f38e160d5
```
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.
Contributor guide
Research direction
Reproduce the failure by pushing with --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 from macOS, then read rules_oci's oci/private/push.bzl around lines 142-155 and the _transition_to_target_impl transition. Check how extra_execution_platforms behaves across Bazel 6.x and 7.x. Done means a Linux image can be pushed from macOS without the jq architecture error while preserving the required execution platforms.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100