Skip to content

Fix TARGETARCH resolution in COPY --from and ADD --from - #6969

Open
mahendrarathore1742 wants to merge 1 commit into
podman-container-tools:mainfrom
mahendrarathore1742:fix/targetarch-copy-from-resolution
Open

Fix TARGETARCH resolution in COPY --from and ADD --from#6969
mahendrarathore1742 wants to merge 1 commit into
podman-container-tools:mainfrom
mahendrarathore1742:fix/targetarch-copy-from-resolution

Conversation

@mahendrarathore1742

Copy link
Copy Markdown

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

@mahendrarathore1742
mahendrarathore1742 force-pushed the fix/targetarch-copy-from-resolution branch from 8024a9b to 34608d5 Compare July 17, 2026 10:37
@packit-as-a-service

Copy link
Copy Markdown

Ephemeral COPR build failed. @containers/packit-build please check.

@isaac-sec

Copy link
Copy Markdown

Do note that the actual issue (at least for my case) is that the copy of BuiltinArgDefault that is used to resolve HeadlingArgs is simply wrong. I have a much smaller patch that I posted on the imagebuilder repository, and it fixes all the cases that I tested.

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>
@mahendrarathore1742
mahendrarathore1742 force-pushed the fix/targetarch-copy-from-resolution branch from 34608d5 to dd173b2 Compare July 18, 2026 06:50
@mahendrarathore1742

Copy link
Copy Markdown
Author

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Podman doesn't resolve TARGETARCH properly in FROM and COPY --from

2 participants