[WIP] add platform selection to image inspect#47114
[WIP] add platform selection to image inspect#47114thaJeztah wants to merge 2 commits intomoby:masterfrom
Conversation
c60f6e5 to
e236526
Compare
daemon/containerd/image.go
Outdated
| log.G(ctx).WithField("platform", cplatforms.Format(*options.Platform)).Debug("filtering by platform") | ||
| platform = cplatforms.OnlyStrict(*options.Platform) |
There was a problem hiding this comment.
It looks like we're only using the matcher for sorting the results, not filtering / matching?
|
|
||
| if options.Platform != nil && !platform.Match(ociimage.Platform) { | ||
| log.G(ctx).WithField("platform", cplatforms.Format(ociimage.Platform)).Info("no match") | ||
| return nil | ||
| } | ||
|
|
There was a problem hiding this comment.
So I added this, but not sure if that's correct (or if the current behavior was intentional for some reason 🤔)
There was a problem hiding this comment.
Yep, its correct.
Lack of Match was an oversight that didn't really had any visible effect because without overriding the platform, the default was to pick the default host platform, or "whatever comes first" if its no present (AllPlatformsWithPreference).
There was a problem hiding this comment.
The sorting is still needed though, specifically for matchers (like AllPlatformsWithPreference) which have some preferences about the platform that should be chosen.
There was a problem hiding this comment.
Yup; sorting looked ok indeed.
Thanks for looking! I'll split these changes to a separate branch and PR 👍
|
One failure looks related; |
e25f53d to
41577ba
Compare
If an image has multiple platforms in the local image store, we default to
the host's default platform when inspecting the image.
With this patch applied, the inspect endpoint now allows a platform
query-parameter to be passed to select the variant to inspect;
hack/make.sh binary && make install
TEST_INTEGRATION_USE_SNAPSHOTTER=1 dockerd --debug --storage-driver=overlayfs
docker pull --platform=linux/arm64 alpine
docker pull --platform=linux/amd64 alpine
curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.44/images/alpine:latest/json?platform=linux/arm64' | jq .Architecture
"arm64"
curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.44/images/alpine:latest/json?platform=linux/amd64' | jq .Architecture
"amd64"
Still to fix: when passing a platform for which no images are present, all images
are found, and it returns the first image (or the old default: "linux/amd64");
curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.44/images/alpine:latest/json?platform=windows/s390x' | jq .Architecture
"amd64"
Daemon logs:
INFO[2024-01-19T09:51:13.692119375Z] API listen on /var/run/docker.sock
DEBU[2024-01-19T09:51:15.421193584Z] Calling GET /v1.44/images/alpine:latest/json?platform=windows/s390x
INFO[2024-01-19T09:51:15.422053417Z] filtering by platform platform=windows/s390x
INFO[2024-01-19T09:51:15.429996542Z] found images images=2
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Before this patch, when passing a platform for which no images are present,
all images are found, and it returns the first image (or the old default:
"linux/amd64");
curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.44/images/alpine:latest/json?platform=windows/s390x' | jq .Architecture
"amd64"
With this patch, an error is returned:
curl -s --unix-socket /var/run/docker.sock 'http://localhost/v1.44/images/alpine:latest/json?platform=windows/s390x'
{"message":"No such image: alpine:latest for platform: windows/s390x"}
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
41577ba to
252e881
Compare
If an image has multiple platforms in the local image store, we default to the host's default platform when inspecting the image.
With this patch applied, the inspect endpoint now allows a platform query-parameter to be passed to select the variant to inspect;
Still to fix: when passing a platform for which no images are present, all images
are found, and it returns the first image (or the old default: "linux/amd64");
Daemon logs:
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)