diff --git a/api/docs/CHANGELOG.md b/api/docs/CHANGELOG.md index f2312ff5d2..6e4acac89f 100644 --- a/api/docs/CHANGELOG.md +++ b/api/docs/CHANGELOG.md @@ -34,6 +34,12 @@ keywords: "API, Docker, rcli, REST, documentation" * `GET /images/{name}/json` now omits the following `Config` fields when 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) `Cmd`, `Entrypoint`, `Env`, `Labels`, `OnBuild`, `User`, `Volumes`, and `WorkingDir`. +* `GET /images/{name}/json` now omits the following fields if their value + is empty: `Parent`, `Comment`, `DockerVersion`, `Author`. The `Parent` + and `DockerVersion` fields were set by the legacy builder, and are no + longer set when using BuildKit. The `Author` field is set through the + `MAINTAINER` Dockerfile instruction, which is deprecated, and the `Comment` + field is option, and may not be set depending on how the image was created. * `GET /containers/{id}/json`: the `NetworkSettings` no longer returns the deprecated `Bridge`, `HairpinMode`, `LinkLocalIPv6Address`, `LinkLocalIPv6PrefixLen`, `SecondaryIPAddresses`, `SecondaryIPv6Addresses`, `EndpointID`, `Gateway`, diff --git a/api/docs/v1.52.yaml b/api/docs/v1.52.yaml index 9d5c72514e..8d702be5d1 100644 --- a/api/docs/v1.52.yaml +++ b/api/docs/v1.52.yaml @@ -1839,13 +1839,13 @@ definitions: is only set for images that were built/created locally. This field is empty if the image was pulled from an image registry. type: "string" - x-nullable: false + x-nullable: true example: "" Comment: description: | Optional message that was set when committing or importing the image. type: "string" - x-nullable: false + x-nullable: true example: "" Created: description: | @@ -1864,14 +1864,14 @@ definitions: Depending on how the image was created, this field may be empty. type: "string" - x-nullable: false + x-nullable: true example: "27.0.1" Author: description: | Name of the author that was specified when committing the image, or as specified through MAINTAINER (deprecated) in the Dockerfile. type: "string" - x-nullable: false + x-nullable: true example: "" Config: $ref: "#/definitions/ImageConfig" diff --git a/api/swagger.yaml b/api/swagger.yaml index 9d5c72514e..8d702be5d1 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -1839,13 +1839,13 @@ definitions: is only set for images that were built/created locally. This field is empty if the image was pulled from an image registry. type: "string" - x-nullable: false + x-nullable: true example: "" Comment: description: | Optional message that was set when committing or importing the image. type: "string" - x-nullable: false + x-nullable: true example: "" Created: description: | @@ -1864,14 +1864,14 @@ definitions: Depending on how the image was created, this field may be empty. type: "string" - x-nullable: false + x-nullable: true example: "27.0.1" Author: description: | Name of the author that was specified when committing the image, or as specified through MAINTAINER (deprecated) in the Dockerfile. type: "string" - x-nullable: false + x-nullable: true example: "" Config: $ref: "#/definitions/ImageConfig" diff --git a/api/types/image/image_inspect.go b/api/types/image/image_inspect.go index 69a2637563..ab7b54fd0b 100644 --- a/api/types/image/image_inspect.go +++ b/api/types/image/image_inspect.go @@ -47,12 +47,12 @@ type InspectResponse struct { // // Depending on how the image was created, this field may be empty and // is only set for images that were built/created locally. This field - // is empty if the image was pulled from an image registry. - Parent string + // is omitted if the image was pulled from an image registry. + Parent string `json:",omitempty"` // Comment is an optional message that can be set when committing or - // importing the image. - Comment string + // importing the image. This field is omitted if not set. + Comment string `json:",omitempty"` // Created is the date and time at which the image was created, formatted in // RFC 3339 nano-seconds (time.RFC3339Nano). @@ -79,12 +79,13 @@ type InspectResponse struct { // DockerVersion is the version of Docker that was used to build the image. // - // Depending on how the image was created, this field may be empty. - DockerVersion string + // Depending on how the image was created, this field may be omitted. + DockerVersion string `json:",omitempty"` // Author is the name of the author that was specified when committing the // image, or as specified through MAINTAINER (deprecated) in the Dockerfile. - Author string + // This field is omitted if not set. + Author string `json:",omitempty"` Config *dockerspec.DockerOCIImageConfig // Architecture is the hardware CPU architecture that the image runs on. diff --git a/daemon/server/router/image/image_routes.go b/daemon/server/router/image/image_routes.go index ebb2dc7fd6..e35f5b4bda 100644 --- a/daemon/server/router/image/image_routes.go +++ b/daemon/server/router/image/image_routes.go @@ -418,6 +418,14 @@ func (ir *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWrite imageInspect.Descriptor = nil } if versions.LessThan(version, "1.52") { + // These fields have "omitempty" on API v1.52 and higher, + // but older API versions returned them unconditionally. + legacyOptions = append(legacyOptions, compat.WithExtraFields(map[string]any{ + "Parent": imageInspect.Parent, + "Comment": imageInspect.Comment, + "DockerVersion": imageInspect.DockerVersion, + "Author": imageInspect.Author, + })) if versions.LessThan(version, "1.50") { legacyOptions = append(legacyOptions, compat.WithExtraFields(legacyConfigFields["v1.49"])) } else { diff --git a/vendor/github.com/moby/moby/api/types/image/image_inspect.go b/vendor/github.com/moby/moby/api/types/image/image_inspect.go index 69a2637563..ab7b54fd0b 100644 --- a/vendor/github.com/moby/moby/api/types/image/image_inspect.go +++ b/vendor/github.com/moby/moby/api/types/image/image_inspect.go @@ -47,12 +47,12 @@ type InspectResponse struct { // // Depending on how the image was created, this field may be empty and // is only set for images that were built/created locally. This field - // is empty if the image was pulled from an image registry. - Parent string + // is omitted if the image was pulled from an image registry. + Parent string `json:",omitempty"` // Comment is an optional message that can be set when committing or - // importing the image. - Comment string + // importing the image. This field is omitted if not set. + Comment string `json:",omitempty"` // Created is the date and time at which the image was created, formatted in // RFC 3339 nano-seconds (time.RFC3339Nano). @@ -79,12 +79,13 @@ type InspectResponse struct { // DockerVersion is the version of Docker that was used to build the image. // - // Depending on how the image was created, this field may be empty. - DockerVersion string + // Depending on how the image was created, this field may be omitted. + DockerVersion string `json:",omitempty"` // Author is the name of the author that was specified when committing the // image, or as specified through MAINTAINER (deprecated) in the Dockerfile. - Author string + // This field is omitted if not set. + Author string `json:",omitempty"` Config *dockerspec.DockerOCIImageConfig // Architecture is the hardware CPU architecture that the image runs on.