Skip to content

Fix COPY/ADD --from= with ARG in stage scope#6730

Open
Honny1 wants to merge 1 commit intocontainers:mainfrom
Honny1:copy-from-arg-resolve
Open

Fix COPY/ADD --from= with ARG in stage scope#6730
Honny1 wants to merge 1 commit intocontainers:mainfrom
Honny1:copy-from-arg-resolve

Conversation

@Honny1
Copy link
Member

@Honny1 Honny1 commented Mar 13, 2026

Fixes: #6719

What type of PR is this?

/kind api-change

/kind bug

/kind cleanup
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
/kind other

What this PR does / why we need it:

How to verify it

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fixes `COPY/ADD --from=` when the source stage is defined via a stage scoped `ARG`, ensuring correct source resolution.

Fixes: containers#6719

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 13, 2026
Copy link
Member

@nalind nalind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, but questions about handling precedence when an ARG is provided a default value both in the header and in a stage and how the ARG value is de-quoted.

// not record the right value here.
rootfs := after
b.rootfsMap[rootfs] = struct{}{}
logrus.Debugf("rootfs needed for COPY in stage %d: %q", stageIndex, rootfs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these lines and the preceding comment still correct and/or necessary given the addition being made below?

// specified but default value is set in Containerfile
// via `ARG key=value` so default value can be used.
userArgs = slices.Concat(builtinArgs, userArgs, headingArgs)
userArgs = slices.Concat(builtinArgs, userArgs, headingArgs, localScopeArgs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this handle conflicting values, when one should override another? For example, what happens when tests/bud/copy-from-stage-scoped-arg/Containerfile.multi-copy-arg-override has ARG VARIANT=dev added to its header, before the "build" stage?

if arg != nil {
argName, argValue, hasValue := strings.Cut(arg.Value, "=")
if hasValue && argName != "" {
stageLocalScopeArgs[argName] = strings.Trim(argValue, "\"'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to use imagebuilder.ProcessWord() to handle the quoting here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just reviewing another PR, and was reminded by openshift/imagebuilder#210 that there might be multiple ARGs defined on this line.

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using a default ARG as a parameter for COPY --from= doesn't use previously defined stage

2 participants