Skip to content

Commit 183f151

Browse files
authored
Merge pull request moby#50915 from thaJeztah/omit_empty_config
api: image inspect: remove temporary backfill for Config fields
2 parents a11005b + 0525ae2 commit 183f151

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

api/docs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ keywords: "API, Docker, rcli, REST, documentation"
2626
a PortBinding with an empty HostIP and HostPort when calling `POST /containers/{id}/start`.
2727
This behavior is now deprecated, and a warning is returned by `POST /containers/create`.
2828
The next API version will drop empty `PortBindings` list altogether.
29+
* `GET /images/{name}/json` now omits the following `Config` fields when
30+
not set, to closer align with the implementation of the [OCI Image Specification](https://github.com/opencontainers/image-spec/blob/v1.1.1/specs-go/v1/config.go#L23-L62)
31+
`Cmd`, `Entrypoint`, `Env`, `Labels`, `OnBuild`, `User`, `Volumes`, and `WorkingDir`.
2932

3033
## v1.51 API changes
3134

daemon/server/router/image/image_routes.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,8 @@ func (ir *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWrite
372372
return err
373373
}
374374

375-
// inspectResponse preserves fields in the response that have an
376-
// "omitempty" in the OCI spec, but didn't omit such fields in
377-
// legacy responses before API v1.50.
378375
imageInspect := &inspectCompatResponse{
379376
InspectResponse: resp,
380-
legacyConfig: legacyConfigFields["current"],
381377
}
382378

383379
// Make sure we output empty arrays instead of nil. While Go nil slice is functionally equivalent to an empty slice,
@@ -406,8 +402,15 @@ func (ir *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWrite
406402
if versions.LessThan(version, "1.48") {
407403
imageInspect.Descriptor = nil
408404
}
409-
if versions.LessThan(version, "1.50") {
410-
imageInspect.legacyConfig = legacyConfigFields["v1.49"]
405+
if versions.LessThan(version, "1.52") {
406+
if versions.LessThan(version, "1.50") {
407+
imageInspect.legacyConfig = legacyConfigFields["v1.49"]
408+
} else {
409+
// inspectResponse preserves fields in the response that have an
410+
// "omitempty" in the OCI spec, but didn't omit such fields in
411+
// legacy responses before API v1.50.
412+
imageInspect.legacyConfig = legacyConfigFields["v1.50-v1.51"]
413+
}
411414
}
412415

413416
return httputils.WriteJSON(w, http.StatusOK, imageInspect)

daemon/server/router/image/inspect_response.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ var legacyConfigFields = map[string]map[string]any{
3131
"Volumes": nil,
3232
"WorkingDir": "",
3333
},
34-
// Legacy fields for current API versions (v1.50 and up). These fields
34+
// Legacy fields for current API versions (v1.50 and v1.52). These fields
3535
// did not have an "omitempty" and were always included in the response,
3636
// even if not set; see https://github.com/moby/moby/issues/50134
37-
"current": {
37+
"v1.50-v1.51": {
3838
"Cmd": nil,
3939
"Entrypoint": nil,
4040
"Env": nil,

daemon/server/router/image/inspect_response_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ func TestInspectResponse(t *testing.T) {
4040
expected: `{"AttachStderr":false,"AttachStdin":false,"AttachStdout":false,"Cmd":["/bin/sh"],"Domainname":"","Entrypoint":null,"Env":null,"Hostname":"","Image":"","Labels":null,"OnBuild":null,"OpenStdin":false,"StdinOnce":false,"StopSignal":"SIGQUIT","Tty":false,"User":"","Volumes":null,"WorkingDir":""}`,
4141
},
4242
{
43-
doc: "api >= v1.50",
43+
doc: "api v1.50 - v1.51",
4444
cfg: &ocispec.ImageConfig{
4545
Cmd: []string{"/bin/sh"},
4646
StopSignal: "SIGQUIT",
4747
},
48-
legacyConfig: legacyConfigFields["current"],
48+
legacyConfig: legacyConfigFields["v1.50-v1.51"],
4949
expected: `{"Cmd":["/bin/sh"],"Entrypoint":null,"Env":null,"Labels":null,"OnBuild":null,"StopSignal":"SIGQUIT","User":"","Volumes":null,"WorkingDir":""}`,
5050
},
5151
}

0 commit comments

Comments
 (0)