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

Support OS version in platform string #5614

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

cpuguy83
Copy link
Member

@cpuguy83 cpuguy83 commented Dec 27, 2024

This allows platforms following the new platforms.FormatAll function, which allows for setting the OSVersion field of the platform with <os>(<ver>)/<arch>.

Closes #5115


Note: In order to make FROM <img> match the correct OS version with the new platform format some changes need to be made to containerd/platforms (see vendor/ changes).

@cpuguy83 cpuguy83 force-pushed the platforms_format_all branch 5 times, most recently from a881f71 to 33ecd88 Compare January 7, 2025 18:15
@tonistiigi tonistiigi added this to the v0.19.0 milestone Jan 7, 2025
@tonistiigi
Copy link
Member

@cpuguy83 Added this to v0.19 , RC planned for 01/10

@cpuguy83
Copy link
Member Author

cpuguy83 commented Jan 8, 2025

Upstreaming those vendor changes at containerd/platforms#22

@cpuguy83 cpuguy83 force-pushed the platforms_format_all branch from 212a947 to 3713196 Compare January 13, 2025 19:55
@cpuguy83 cpuguy83 changed the title WIP: Support OS version in platform string Support OS version in platform string Jan 13, 2025
@cpuguy83 cpuguy83 force-pushed the platforms_format_all branch 2 times, most recently from 71274ac to eadb841 Compare January 13, 2025 20:28
@cpuguy83
Copy link
Member Author

I have updated this to use the new containerd/platforms module version which made the platform matchers for Windows available on non-Windows platforms so that the test can do the version comparisons.

This should be ready for a full review.

Short: []byte(fmt.Sprintf("Requested platform %q does not match result platform %q", req.Platforms[0], platforms.Format(pp))),
}}, nil
if _, ok := reqMap[platforms.FormatAll(pp)]; !ok {
// The requested platform will often not have an OSVersion on it, but the
Copy link
Member Author

Choose a reason for hiding this comment

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

This was a little janky.
When the platform string is not exactly what was requested (i.e. no OS version) then the returned result which has the OS Version will trigger a warning.

@cpuguy83
Copy link
Member Author

Looks like linter test is failing now with updated platforms package.

@tonistiigi
Copy link
Member

Error message change

        	Error:      	Error message not equal:
        	            	expected: "failed to solve: failed to parse platform linux/${MYARCH}: \"\" is an invalid component of \"linux/\": platform specifier component must match \"^[A-Za-z0-9_-]+$\": invalid argument (did you mean MY_ARCH?)"
        	            	actual  : "failed to solve: failed to parse platform linux/${MYARCH}: \"\" is an invalid component of \"linux/\": platform specifier component must match \"^[A-Za-z0-9_.-]+$\": invalid argument (did you mean MY_ARCH?)"

@cpuguy83 cpuguy83 force-pushed the platforms_format_all branch from 357fa67 to db512d6 Compare January 13, 2025 22:38

dockerfile := []byte(`
ARG TARGETOS TARGETOSVERSION TARGETARCH
FROM --platform=${TARGETOS}(${TARGETOSVERSION})/${TARGETARCH} ` + target + ` AS reg
Copy link
Member

Choose a reason for hiding this comment

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

This platform flag in here shouldn't be needed for functionality as the default should work the same. FROM --platform=$TARGETPLATFORM should also work the same.

If you want to check that the parser works in these cases then maybe add other stages for different variants (reg1, reg2, reg3) and build all in a loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

Your right no need for setting anything here.

Since you brought it up, I did not change TARGETPLATFORM or BUILDPLATFORM to use FormatAll for fear of breaking things.
I guess TARGETPLATFORM shouldn't be a big deal since it'd just be what the user specified.
BUILDPLATFORM would be different... at least on Windows... which maybe isn't a big deal since its experimental?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think TARGETPLATFORM is fine. BUILDPLATFORM maybe indeed shouldn't set OSVersion. This would be different if there would be "default" osversion and different DefaultSpec() and MaximumSpec(). Eg. in linux/amd64, DefaultSpec() variant is always v1, doesn't matter if the machine actually supports higher versions. In OSVersion this concept doesn't seem to exist and it goes to syscall https://github.com/containerd/platforms/blob/main/defaults_windows.go#L29C33-L29C55 . It's possible we need to define our own DefaultSpec in the follow-up.


dt, err = os.ReadFile(filepath.Join(destDir, "osversion"))
require.NoError(t, err)
require.Equal(t, p2.OSVersion+"\n", string(dt))
Copy link
Member

Choose a reason for hiding this comment

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

Should we check that the correct OSVersion is set in the image config, or is this already covered somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

As a note: We discussed this on Slack and will follow-up with this after merge.

@tonistiigi
Copy link
Member

@cpuguy83 Containerd v2 was merged so this needs rebase for the platforms pkg vendor.

This allows platforms following the new `platforms.FormatAll` function,
which allows for setting the `OSVersion` field of the platform with
`<os>(<ver>)/<arch>`.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@cpuguy83 cpuguy83 force-pushed the platforms_format_all branch from db512d6 to 94ddeb7 Compare January 14, 2025 17:27
@github-actions github-actions bot removed the area/dependencies Pull requests that update a dependency file label Jan 14, 2025
@tonistiigi tonistiigi merged commit e8c26b8 into moby:master Jan 14, 2025
96 checks passed
@cpuguy83 cpuguy83 deleted the platforms_format_all branch January 17, 2025 03:10
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.

Add test using windows OSVersion
3 participants