Skip to content

Commit 95689ff

Browse files
fix: multiarch image builds by using host architecture for jq and crane (#869)
This PR builds on #794 to fix the failing CI jobs. Multiarch image builds can fail due to the target architecture for jq and crane. For example if you are building an arm64 image on a x86 machine a failure similar to this will occur: ``` line 52: ../jq_linux_arm64/jq: cannot execute binary file: Exec format error ``` As jq and crane run on the host building the images the host architecture should be used rather than the target arch. --------- Signed-off-by: Brian Carey <bcarey@redhat.com> Co-authored-by: Lionel Fleury <lionel_fleury@hotmail.com>
1 parent bf3c073 commit 95689ff

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

oci/private/push.bzl

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,23 +140,6 @@ multirun(
140140
[rules_multirun]: https://github.com/keith/rules_multirun
141141
"""
142142

143-
# Helper rule for ensuring that the crane and yq toolchains are actually
144-
# resolved for the architecture we are targeting.
145-
def _transition_to_target_impl(settings, _attr):
146-
return {
147-
# String conversion is needed to prevent a crash with Bazel 6.x.
148-
"//command_line_option:extra_execution_platforms": [
149-
str(platform)
150-
for platform in settings["//command_line_option:platforms"]
151-
],
152-
}
153-
154-
_transition_to_target = transition(
155-
implementation = _transition_to_target_impl,
156-
inputs = ["//command_line_option:platforms"],
157-
outputs = ["//command_line_option:extra_execution_platforms"],
158-
)
159-
160143
_attrs = {
161144
"image": attr.label(
162145
allow_single_file = True,
@@ -184,12 +167,9 @@ _attrs = {
184167
""",
185168
allow_single_file = True,
186169
),
187-
"_allowlist_function_transition": attr.label(
188-
default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
189-
),
190170
"_crane": attr.label(
191-
cfg = _transition_to_target,
192171
default = "@oci_crane_toolchains//:current_toolchain",
172+
cfg = "exec",
193173
),
194174
"_push_sh_tpl": attr.label(
195175
default = "push.sh.tpl",
@@ -198,17 +178,17 @@ _attrs = {
198178
"_runfiles": attr.label(default = "@bazel_tools//tools/bash/runfiles"),
199179
"_windows_constraint": attr.label(default = "@platforms//os:windows"),
200180
"_jq": attr.label(
201-
cfg = _transition_to_target,
202181
default = "@jq_toolchains//:resolved_toolchain",
182+
cfg = "exec",
203183
),
204184
}
205185

206186
def _quote_args(args):
207187
return ["\"{}\"".format(arg) for arg in args]
208188

209189
def _impl(ctx):
210-
crane = ctx.attr._crane[0][platform_common.ToolchainInfo]
211-
jq = ctx.attr._jq[0][platform_common.ToolchainInfo]
190+
crane = ctx.attr._crane[platform_common.ToolchainInfo]
191+
jq = ctx.attr._jq[platform_common.ToolchainInfo]
212192

213193
if not ctx.file.image.is_directory:
214194
fail("image attribute must be a oci_image or oci_image_index")

0 commit comments

Comments
 (0)