Fix TARGETARCH resolution in COPY --from and ADD --from - #6969
Fix TARGETARCH resolution in COPY --from and ADD --from#6969mahendrarathore1742 wants to merge 1 commit into
Conversation
8024a9b to
34608d5
Compare
|
Ephemeral COPR build failed. @containers/packit-build please check. |
|
Do note that the actual issue (at least for my case) is that the copy of |
Two complementary fixes for TARGETARCH not being properly resolved
in multi-platform builds:
1. Fix extractHeadingArgsFromNode in builder.go (root cause):
The function creates a temporary builder to evaluate heading ARGs
before the first FROM. However, it used NewBuilder() which gets the
host's BuiltinArgDefaults instead of the current builder's
platform-specific values. When --platform overrides TARGETARCH, the
heading args would resolve with the wrong architecture.
Fix: Copy the current builder's BuiltinArgDefaults into the
temporary builder before evaluating heading args.
2. Fix flag arg resolution in dispatchers.go:
The add(), dispatchCopy(), and run() dispatchers did not include
BuiltinArgDefaults or HeadingArgs in their userArgs when resolving
flag arguments via ProcessWord. This caused COPY --from=artifacts-
${TARGETARCH} to fail since ${TARGETARCH} was never substituted.
Fix: Add BuiltinArgDefaults and HeadingArgs to userArgs, matching
the pattern already used by the from() dispatcher.
Adds integration tests for both COPY --from and FROM with TARGETARCH
variable substitution.
Fixes: podman-container-tools#6964
Signed-off-by: Mahendra Rathore <49229348+mahendrarathore1742@users.noreply.github.com>
34608d5 to
dd173b2
Compare
|
@isaac-sec Thanks for the pointer! I've incorporated your fix from imagebuilder#322 (openshift/imagebuilder#322) into this PR as well — the extractHeadingArgsFromNode fix in builder.go. I also included an additional fix in the dispatchers (add(), dispatchCopy(), run()) where BuiltinArgDefaults and HeadingArgs weren't included in userArgs for ProcessWord — which meant COPY --from=artifacts-${TARGETARCH} couldn't resolve the variable at all. Both fixes are now in the commit. Could you verify if the dispatcher fix is still needed on top of yours, or if your root cause fix alone covers all cases? |
The dispatchCopy, add, and run dispatchers in the vendored openshift/imagebuilder library did not include BuiltinArgDefaults (contains TARGETARCH, TARGETOS, TARGETPLATFORM, etc.) or HeadingArgs in their userArgs when resolving flag arguments via ProcessWord.
This caused COPY --from=artifacts-${TARGETARCH} to fail with:
COPY --from=artifacts-arm64: no stage or image found with that name
The from() dispatcher already correctly included these args, which is why FROM artifacts-${TARGETARCH} worked but COPY --from did not.
Fix by adding BuiltinArgDefaults and HeadingArgs to userArgs in the add(), dispatchCopy(), and run() dispatchers, matching the pattern used by from().
Adds integration tests for both COPY --from and FROM with TARGETARCH variable substitution.
Fixes: #6964