GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — api: image inspect: add back fields that did not omitempty by thaJeztah · Pull Request #50135 · moby/moby

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Jun 3, 2025 •
edited by vvoland
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • relates to image-inspect: remove Config fields that are not part of the image #48457
  • fixes /images/{name}/json does not return image Entrypoint if null #50134
  • fixes panic when pulling an image with docker compose #50165

commit 4dc961d removed deprecated fields from the image inspect response for API v1.50 and up. As part of that change, it changed the type used for the Config field to use the docker image spect structs, which embeds the OCI image spec structs.

While the OCI image spect struct contains the same fields as we used before, those fields also have "omitempty" set, which means they are now omitted when empty.

We should probably consider deprecating that behavior in the API, and call out that these fields are omitted if not set, but in the meantime, we can add them back with their default (zero) value.

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

Fix `docker image inspect inspect` omitting empty fields.

- A picture of a cute animal (not mandatory but encouraged)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thaJeztah thaJeztah added area/api API status/2-code-review kind/bugfix PR's that fix bugs labels Jun 3, 2025
@thaJeztah thaJeztah mentioned this pull request Jun 3, 2025
/images/{name}/json does not return image Entrypoint if null #50134
Closed
vvoland
vvoland approved these changes Jun 3, 2025
View reviewed changes

@vvoland vvoland left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, but we should remove that in v1.51+

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread api/server/router/image/inspect_response_test.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

@thaJeztah

thaJeztah commented Jun 3, 2025

Copy link
Copy Markdown
Member Author

but we should remove that in v1.51+

Probably; I also just came to the conclusion that we can combine the existing fallback with the new one, and (AFAICS) that would also mean we can drop the dockerOCIImageConfigToContainerConfig function that we copied, so simplifying other things as well.

I have a commit doing so; let me push that, and I can squash it iafter that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thaJeztah

thaJeztah commented Jun 3, 2025

Copy link
Copy Markdown
Member Author

OK; pushed a commit; let me know what you think, then I can squash.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thaJeztah

thaJeztah commented Jun 3, 2025

Copy link
Copy Markdown
Member Author

Looks like I broke something in that last commit; will have a look tomorrow

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thaJeztah
thaJeztah force-pushed the inspect_no_omitempty branch 3 times, most recently from 585aadb to 4ff4fa2 Compare June 3, 2025 22:52
thaJeztah
thaJeztah commented Jun 4, 2025
View reviewed changes
Comment thread api/server/router/image/inspect_response.go
Comment on lines +83 to +84
// prevent mutating legacyConfigFields.
cfg := maps.Clone(ir.legacyConfig)

@thaJeztah thaJeztah Jun 4, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This was the problem; I added the legacyConfigFields the router assigns legacyConfig from that, and we didn't de-reference.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
thaJeztah
thaJeztah commented Jun 4, 2025
View reviewed changes
Comment thread api/server/router/image/image_routes.go
Comment on lines +381 to +384
imageInspect := &inspectCompatResponse{
InspectResponse: resp,
legacyConfig: legacyConfigFields["current"],
}

@thaJeztah thaJeztah Jun 4, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

FWIW; I started to look if adding a constructor for this would be cleaner, and possibly it could be, but rewriting took me down the rabbit hole, so I'm gonna leave that for a future refactor; possibly combining all the version-related changes below 🤔

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
vvoland
vvoland reviewed Jun 4, 2025
View reviewed changes
Comment thread api/server/router/image/inspect_response.go
Comment on lines +37 to +49
// Legacy fields for current API versions (v1.50 and up). These fields
// did not have an "omitempty" and were always included in the response,
// even if not set; see https://github.com/moby/moby/issues/50134
"current": {
"Cmd": nil,
"Entrypoint": nil,
"Env": nil,
"Labels": nil,
"OnBuild": nil,
"User": "",
"Volumes": nil,
"WorkingDir": "",
},

@vvoland vvoland Jun 4, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think we can avoid this one and just marshal the base InspectResponse instead?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thaJeztah thaJeztah Jun 4, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

These were the ones that had an omit empty, so were not included #50134

So I think using the base would then result in them disappearing again.

But for api v1.51 we can consider doing so, but we'd have to deprecate that behavior first (can do that in a separate PR)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vvoland vvoland Jun 4, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Right...

I think what confused me is that the caller is responsible for passing the correct value of legacyConfigFields.

Could we just pass the API version the response should be adapted to?

So

imageInspect := &inspectCompatResponse{
		InspectResponse: resp,
}

would mean the "current"/"latest" and

imageInspect := &inspectCompatResponse{
		InspectResponse: resp,
        version: "1.49"
}

would mean the 1.49 compatible response..

Although that's probably what you meant in https://github.com/moby/moby/pull/50135/files#r2126024062?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vvoland vvoland Jun 4, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Btw, I think it would be slightly easier to understand if we declared a copy-pasted, unexported versions of the "legacy" Config struct and just explicitly filled and marshalled them inside inspectCompatResponse.MarshalJSON.
While more verbose, I think it would be much clearer and easier to understand.

Just a thought though, not a blocker

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@thaJeztah thaJeztah Jun 4, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Could we just pass the API version the response should be adapted to?

Yeah, that's something I was considering, and mostly had written, then threw it away thinking to KISS for now. I can still have a look at that though.

I think it would be slightly easier to understand if we declared a copy-pasted, unexported versions of the "legacy" Config struct

Ah, gotcha. Hm.. yes, possibly could work. My goal at least was to avoid having to depend on legacy types or fields if that meant we'd have to continue maintaining the fields (as "deprecated") purely for the old responses (but with empty / zero values).

Having a (non-exported) copy of such structs purely for that purpose is indeed slightly better; what I slightly tried to avoid though was to (in some cases) that potentially requiring to also use legacy indirect types, such as the nat.Port mapping in the code we had;

moby/api/server/router/image/image_routes.go

Lines 604 to 609 in 9663b36

exposedPorts := make(nat.PortSet, len(cfg.ExposedPorts))
for k, v := range cfg.ExposedPorts {
exposedPorts[nat.Port(k)] = v
}
return &container.Config{

I recall we used to have these "versioned" legacy types, which I guess is a bit of that approach; some of those started to become quite involved though;
https://github.com/moby/moby/blob/v19.03.0/api/types/versions/v1p19/types.go
https://github.com/moby/moby/blob/v19.03.0/api/types/versions/v1p20/types.go
https://github.com/moby/moby/blob/v19.03.0/daemon/inspect.go#L22-L30

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@thaJeztah
api: image inspect: add back fields that did not omitempty
f85394d
commit 4dc961d removed deprecated
fields from the image inspect response for API v1.50 and up. As
part of that change, it changed the type used for the Config field
to use the docker image spect structs, which embeds the OCI image
spec structs.

While the OCI image spect struct contains the same fields as we
used before, those fields also have "omitempty" set, which means
they are now omitted when empty.

We should probably consider deprecating that behavior in the API,
and call out that these fields are omitted if not set, but in the
meantime, we can add them back with their default (zero) value.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
thaJeztah force-pushed the inspect_no_omitempty branch from 4ff4fa2 to f85394d Compare June 4, 2025 16:02
@thaJeztah

thaJeztah commented Jun 4, 2025

Copy link
Copy Markdown
Member Author

Squashed the commits, but happy to make additional changes related to #50135 (comment)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thaJeztah
thaJeztah marked this pull request as ready for review June 10, 2025 11:04
@thaJeztah thaJeztah mentioned this pull request Jun 10, 2025
panic when pulling an image with docker compose #50165
Closed
robmry
robmry approved these changes Jun 10, 2025
View reviewed changes
@vvoland vvoland added this to the 28.2.3 milestone Jun 11, 2025
@vvoland
vvoland merged commit e84353e into moby:master Jun 11, 2025
@vvoland vvoland modified the milestones: 28.2.3, 28.3.0 Jun 11, 2025
@thaJeztah
thaJeztah deleted the inspect_no_omitempty branch June 11, 2025 09:59
@thaJeztah thaJeztah mentioned this pull request Jun 11, 2025
image-inspect: remove Config fields that are not part of the image #48457
Merged
@vvoland vvoland added the impact/changelog label Jun 13, 2025
@vvoland vvoland mentioned this pull request Jun 13, 2025
docs: deprecate empty Config fields in image inspect API docker/cli#6129
Merged
@MattyMay MattyMay mentioned this pull request Jul 8, 2025
Don't raise KeyError on missing docker inspect config fields eecs-autograder/autograder-server#712
Merged
@dmcgowan dmcgowan mentioned this pull request Aug 4, 2025
Prepare release notes for v1.52.0-alpha.0 #50625
Merged
@dmcgowan dmcgowan mentioned this pull request Aug 6, 2025
Prepare release notes for v2.0.0-alpha.0 #50651
Closed
@dmcgowan dmcgowan mentioned this pull request Sep 5, 2025
Prepare release notes for api/v1.52.0-beta.0 #50904
Merged
@thaJeztah thaJeztah mentioned this pull request Sep 5, 2025
api: image inspect: remove temporary backfill for Config fields #50915
Merged
@dmcgowan dmcgowan mentioned this pull request Sep 5, 2025
Prepare release notes for v2.0.0-beta.0 #50918
Merged
@dmcgowan dmcgowan mentioned this pull request Sep 24, 2025
Prepare release notes for api/v1.52.0-rc.0 #51030
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vvoland vvoland vvoland approved these changes
@robmry robmry robmry approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area/api API impact/changelog kind/bugfix PR's that fix bugs status/2-code-review

Projects

None yet

Milestone

28.3.0

Development

Successfully merging this pull request may close these issues.

panic when pulling an image with docker compose /images/{name}/json does not return image Entrypoint if null

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@thaJeztah @vvoland @robmry
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.