Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stage_executor: reset platform in systemcontext for every stage. #5971

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

flouthoc
Copy link
Collaborator

@flouthoc flouthoc commented Feb 4, 2025

On processing of every stage platform spec in systemcontext must be correctly reset.

[NO NEW TESTS NEEDED]

Closes: #5968

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?

stage_executor: reset platform in systemcontext for every stage.

Copy link
Contributor

openshift-ci bot commented Feb 4, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: flouthoc
Once this PR has been reviewed and has the lgtm label, please assign lsm5 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@flouthoc
Copy link
Collaborator Author

flouthoc commented Feb 4, 2025

Just wondering how to test this in CI since binfmt will correctly run every image type.

Copy link

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

@flouthoc flouthoc force-pushed the reset-context-platform branch from d15172e to 8cef977 Compare February 4, 2025 18:04
@flouthoc flouthoc added the No New Tests Allow PR to proceed without adding regression tests label Feb 4, 2025
@flouthoc
Copy link
Collaborator Author

flouthoc commented Feb 4, 2025

Temp adding No New Tests to see if CI passes, will remove the label when I add test.

@nalind
Copy link
Member

nalind commented Feb 4, 2025

The "header-builtin" test does something similar, so I'd suggest

ARG FOREIGNARCH
FROM --platform=linux/$FOREIGNARCH busybox AS foreign
FROM busybox
COPY --from=foreign /bin/busybox /bin/busybox.foreign
RUN arch
RUN ls -l /bin/busybox /bin/busybox.foreign
RUN ! cmp /bin/busybox /bin/busybox.foreign

Define the FOREIGNARCH build arg by checking if $(go env GOARCH) is amd64 or arm64 or ppc64le or s390x, having preselected one or them as a default, and choosing a different one if that default happens to match the local architecture.

@flouthoc flouthoc force-pushed the reset-context-platform branch 3 times, most recently from ab73040 to cbc1002 Compare February 11, 2025 16:01
Every stage now has its own copy of systemcontext.

On processing of every stage platform spec in systemcontext must be
correctly reset.

Closes: containers#5968

Signed-off-by: flouthoc <[email protected]>
@flouthoc flouthoc force-pushed the reset-context-platform branch from cbc1002 to 4010772 Compare February 11, 2025 16:01
@flouthoc flouthoc removed the No New Tests Allow PR to proceed without adding regression tests label Feb 11, 2025
@flouthoc flouthoc requested a review from nalind February 11, 2025 16:42
@@ -59,6 +59,7 @@ import (
// name to the image that it produces.
type StageExecutor struct {
ctx context.Context
systemContext types.SystemContext
Copy link
Member

Choose a reason for hiding this comment

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

types.SystemContext values in structs are customarily pointers. This should be a pointer.

// In a multi-stage build where `FROM --platform=<>` was used then we must
// reset context for new stages so that new stages don't inherit unexpected
// `--platform` from prior stages.
if stage.Builder.Platform != "" || (stage.Position != 0 && builderSystemContext.ArchitectureChoice == "" && builderSystemContext.VariantChoice == "" && builderSystemContext.OSChoice == "") {
Copy link
Member

Choose a reason for hiding this comment

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

Would this be simpler if the builderSystemContext had its ...Choice fields cleared as part of initializing it?

@test "build must reset platform for stages if needed" {
otherarch="arm64"
# just make sure that other arch is not equivalent to host arch
if [[ "$otherarch" == "$myarch" ]]; then
Copy link
Member

Choose a reason for hiding this comment

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

$myarch has not been defined at this point, so the test is always false.

if [[ "$otherarch" == "$myarch" ]]; then
otherarch="amd64"
fi
run_buildah build $WITH_POLICY_JSON --build-arg FOREIGNARCH=$otherarch -f $BUDFILES/multiarch/Containerfile.reset-platform $BUDFILES/multiarch
Copy link
Member

Choose a reason for hiding this comment

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

This should also test a case where the the TARGETPLATFORM build-arg is set, so that we don't regress on that.

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.

--platform parameter spills out of its FROM clause
2 participants