Skip to content

[WIP] add platform selection to image inspect#47114

Draft
thaJeztah wants to merge 2 commits intomoby:masterfrom
thaJeztah:image_inspect_platform
Draft

[WIP] add platform selection to image inspect#47114
thaJeztah wants to merge 2 commits intomoby:masterfrom
thaJeztah:image_inspect_platform

Conversation

@thaJeztah
Copy link
Member

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

- 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)

@thaJeztah thaJeztah self-assigned this Jan 19, 2024
@thaJeztah thaJeztah force-pushed the image_inspect_platform branch from c60f6e5 to e236526 Compare January 19, 2024 11:10
Comment on lines 43 to 44
log.G(ctx).WithField("platform", cplatforms.Format(*options.Platform)).Debug("filtering by platform")
platform = cplatforms.OnlyStrict(*options.Platform)
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 looks like we're only using the matcher for sorting the results, not filtering / matching?

Comment on lines +71 to +75

if options.Platform != nil && !platform.Match(ociimage.Platform) {
log.G(ctx).WithField("platform", cplatforms.Format(ociimage.Platform)).Info("no match")
return nil
}

Copy link
Member Author

Choose a reason for hiding this comment

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

So I added this, but not sure if that's correct (or if the current behavior was intentional for some reason 🤔)

Copy link
Contributor

Choose a reason for hiding this comment

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

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).

Copy link
Contributor

Choose a reason for hiding this comment

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

The sorting is still needed though, specifically for matchers (like AllPlatformsWithPreference) which have some preferences about the platform that should be chosen.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup; sorting looked ok indeed.

Thanks for looking! I'll split these changes to a separate branch and PR 👍

@thaJeztah
Copy link
Member Author

One failure looks related;

=== Failed
=== FAIL: amd64.integration.image TestRemoveImageGarbageCollector (3.28s)
time="2024-01-19T11:18:48Z" level=info msg="[graphdriver] trying configured driver: overlay2"
    remove_unix_test.go:112: assertion failed: expression is false: os.IsNotExist(err)

@thaJeztah thaJeztah force-pushed the image_inspect_platform branch 2 times, most recently from e25f53d to 41577ba Compare January 19, 2024 16:35
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>
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.

2 participants