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

Setting --arch should set the TARGETARCH build arg #5478

Merged
merged 1 commit into from May 15, 2024

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Apr 16, 2024

Also fix a long standing FIXME in the test framework.

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?

--arch option now causes the TARGETARCH and TARGETPLATFORM  build args to get modified

@nalind nalind self-assigned this Apr 16, 2024
Copy link

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

tests/bud.bats Outdated
fi

assert "$output" =~ "image platform .* does not match the expected platform" \
"With explicit --platform, buildah should warn about no variant"
Copy link
Member

Choose a reason for hiding this comment

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

This error description doesn't seem to match the error message it's checking against.

tests/bud.bats Outdated
assert "$output" !~ "missing .* build argument" \
"With explicit --platform, buildah should not warn"
assert "$output" =~ "image platform .* does not match the expected platform" \
"With explicit --platform, buildah should warn about no variant"
Copy link
Member

Choose a reason for hiding this comment

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

This error description doesn't seem to match the error message it's checking against.

@@ -555,7 +564,7 @@ func PlatformsFromOptions(c *cobra.Command) (platforms []struct{ OS, Arch, Varia
if err != nil {
return nil, fmt.Errorf("unable to parse platform: %w", err)
}
if os != "" || arch != "" || variant != "" {
if os != runtime.GOOS || arch != runtime.GOARCH || variant != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Do the changes in this function affect test results?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are now defaulting the OS and ARCH and only care if the user changes the value to something different then the default

before on an linux/amd64 machine --platform=linux/amd64 --os=linux --arch=amd64 blue up, now it is allowed since it ultimately does what the user wanted.

If the user does
--platform=linux/amd64 --os=linux --arch=arm64 then the command will fail

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't check that the --platform and --arch/--os values agree. And what's the benefit of allowing some combinations of the flags? Why encourage people with "well, sometimes, it's allowed, in newer versions"?

Copy link
Member Author

Choose a reason for hiding this comment

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

It checks if the --arch or --os changed values from the default.
Similar to --arch="" and --os="" in the old version would have been ignored.

I think we are arguing about a nothing burger, and will relent to make you happy, even though this is the corner case of all corner cases.


run_buildah build $WITH_POLICY_JSON --arch amd64 -t source -f $containerfile
assert "$output" !~ "WARNING" \
"With explicit --os (but no arch/variant), buildah should not warn about TARGETOS"
Copy link
Member

Choose a reason for hiding this comment

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

This error description doesn't seem to match the error message it's checking against.

@rhatdan rhatdan force-pushed the arch branch 6 times, most recently from 1b80d3e to bf4ada5 Compare April 22, 2024 10:05
@@ -218,6 +218,7 @@ func TestSystemContextFromFlagSet(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, sc, &types.SystemContext{
BigFilesTemporaryDir: GetTempDir(),
OSChoice: "linux",
Copy link
Member

Choose a reason for hiding this comment

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

Should this be runtime.GOOS, too?

@@ -3566,6 +3566,7 @@ func TestCommit(t *testing.T) {
derivedBuilder, err := buildah.NewBuilder(ctx, store, buildah.BuilderOptions{
FromImage: buildahID,
})
assert.NoErrorf(t, err, "creating a new Builder")
Copy link
Member

Choose a reason for hiding this comment

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

Ah, good catch. The require.NoErrorf() after the defer can be removed.

"With explicit --platform, buildah should warn about pulling difference in platform"
assert "$output" =~ "TARGETOS=linux" " --platform TARGETOS set correctly"
assert "$output" =~ "TARGETARCH=amd64" " --platform TARGETARCH set correctly"
assert "$output" =~ "TARGETVARIANT=" " --platform TARGETVARIANT set correctly"
Copy link
Member

Choose a reason for hiding this comment

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

Is TARGETVARIANT not being set to "v2", per "--platform"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this reveals the fix just not being correct — the core issue is that the buildDockerfilesOnce code setting TARGET* expects SystemContext.*Choice to never be "", and that’s not how the values are set.

Compare more in #5543 (review)

tests/bud.bats Outdated
assert "$output" =~ "TARGETOS=linux" "--os TARGETOS set correctly"
assert "$output" =~ "TARGETARCH=amd64" "--os TARGETARCH set correctly"
assert "$output" =~ "TARGETVARIANT=" "--os TARGETVARIANT set correctly"
assert "$output" =~ "TARGETPLATFORM=linux/amd64" "--os TARGETPLATFORM set correctly"
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 always going to be "amd64", or would "$(go env GOARCH)" be a better match?

@TomSweeneyRedHat
Copy link
Member

Looks like this needs a refresh and test help @rhatdan

@rhatdan
Copy link
Member Author

rhatdan commented May 4, 2024

@TomSweeneyRedHat @nalind @flouthoc @giuseppe @vrothberg PTAL this finally passes, and is a pretty ugly bug

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

openshift-ci bot commented May 4, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: flouthoc, rhatdan

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

The pull request process is described 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

Also fix a long standing FIXME in the test framework.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@TomSweeneyRedHat
Copy link
Member

LGTM
However, the branch is out of date, so I triggered a rebase of the branch.

@rhatdan rhatdan added the lgtm label May 15, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit b255971 into containers:main May 15, 2024
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants