diff --git a/api/types/image/image_inspect.go b/api/types/image/image_inspect.go index 102b20263f..66a277e557 100644 --- a/api/types/image/image_inspect.go +++ b/api/types/image/image_inspect.go @@ -42,15 +42,6 @@ type InspectResponse struct { // the manifest is generated and its digest calculated. RepoDigests []string - // Parent is the ID of the parent image. - // - // 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 omitted if the image was pulled from an image registry. - // - // Deprecated: this field is deprecated, and will be removed in the next release. - Parent string `json:",omitempty"` - // Comment is an optional message that can be set when committing or // importing the image. This field is omitted if not set. Comment string `json:",omitempty"` @@ -62,13 +53,6 @@ type InspectResponse struct { // and omitted otherwise. Created string `json:",omitempty"` - // DockerVersion is the version of Docker that was used to build the image. - // - // Depending on how the image was created, this field may be omitted. - // - // Deprecated: this field is deprecated, and will be removed in the next release. - 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. // This field is omitted if not set. diff --git a/daemon/containerd/image_inspect.go b/daemon/containerd/image_inspect.go index dfde50e1a3..d1fc1bcf34 100644 --- a/daemon/containerd/image_inspect.go +++ b/daemon/containerd/image_inspect.go @@ -91,13 +91,13 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, opts im RepoTags: repoTags, Descriptor: &target, RepoDigests: repoDigests, - Parent: parent, //nolint:staticcheck // ignore SA1019: field is deprecated, but still included in response when present. Size: size, Manifests: manifests, Metadata: imagetypes.Metadata{ LastTagTime: lastUpdated, }, }, + Parent: parent, // field is deprecated with the legacy builder, but returned by the API if present. } if multi.Best != nil { diff --git a/daemon/images/image_inspect.go b/daemon/images/image_inspect.go index 21bfa645a1..535bb594e2 100644 --- a/daemon/images/image_inspect.go +++ b/daemon/images/image_inspect.go @@ -56,20 +56,18 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, opts im imgConfig := containerConfigToDockerOCIImageConfig(img.Config) return &imagebackend.InspectData{ InspectResponse: imagetypes.InspectResponse{ - ID: img.ID().String(), - RepoTags: repoTags, - RepoDigests: repoDigests, - Parent: img.Parent.String(), //nolint:staticcheck // ignore SA1019: field is deprecated, but still included in response when present (built with legacy builder). - Comment: comment, - Created: created, - DockerVersion: img.DockerVersion, //nolint:staticcheck // ignore SA1019: field is deprecated, but still included in response when present. - Author: img.Author, - Config: &imgConfig, - Architecture: img.Architecture, - Variant: img.Variant, - Os: img.OperatingSystem(), - OsVersion: img.OSVersion, - Size: size, + ID: img.ID().String(), + RepoTags: repoTags, + RepoDigests: repoDigests, + Comment: comment, + Created: created, + Author: img.Author, + Config: &imgConfig, + Architecture: img.Architecture, + Variant: img.Variant, + Os: img.OperatingSystem(), + OsVersion: img.OSVersion, + Size: size, GraphDriver: &storage.DriverData{ Name: i.layerStore.DriverName(), Data: layerMetadata, @@ -82,6 +80,8 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, opts im LastTagTime: lastUpdated, }, }, + Parent: img.Parent.String(), // field is deprecated with the legacy builder, but still included in response when present (built with legacy builder). + DockerVersion: img.DockerVersion, // field is deprecated with the legacy builder, but still included in response when present. Container: img.Container, // field is deprecated, but still set on API < v1.45. ContainerConfig: &img.ContainerConfig, // field is deprecated, but still set on API < v1.45. }, nil diff --git a/daemon/server/imagebackend/image.go b/daemon/server/imagebackend/image.go index 22e46e6e76..b3992c44c2 100644 --- a/daemon/server/imagebackend/image.go +++ b/daemon/server/imagebackend/image.go @@ -61,6 +61,22 @@ type ImageInspectOpts struct { type InspectData struct { imagetypes.InspectResponse + // Parent is the ID of the parent image. + // + // 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 omitted if the image was pulled from an image registry. + // + // This field is deprecated with the legacy builder, but returned by the API if present. + Parent string `json:",omitempty"` + + // DockerVersion is the version of Docker that was used to build the image. + // + // Depending on how the image was created, this field may be omitted. + // + // This field is deprecated with the legacy builder, but returned by the API if present. + DockerVersion string `json:",omitempty"` + // Container is the ID of the container that was used to create the image. // // Depending on how the image was created, this field may be empty. diff --git a/daemon/server/router/image/image_routes.go b/daemon/server/router/image/image_routes.go index 18b1d76436..094f484f93 100644 --- a/daemon/server/router/image/image_routes.go +++ b/daemon/server/router/image/image_routes.go @@ -423,9 +423,9 @@ func (ir *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWrite // 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": inspectData.Parent, //nolint:staticcheck // ignore SA1019: field is deprecated, but still included in response when present (built with legacy builder). + "Parent": inspectData.Parent, // field is deprecated, but still included in response when present (built with legacy builder). "Comment": inspectData.Comment, - "DockerVersion": inspectData.DockerVersion, //nolint:staticcheck // ignore SA1019: field is deprecated, but still included in response when present. + "DockerVersion": inspectData.DockerVersion, // field is deprecated, but still included in response when present. "Author": inspectData.Author, })) @@ -440,6 +440,15 @@ func (ir *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWrite "Config": legacyConfigFields["v1.50-v1.51"], })) } + } else { + if inspectData.Parent != "" { + // field is deprecated, but still included in response when present (built with legacy builder). + legacyOptions = append(legacyOptions, compat.WithExtraFields(map[string]any{"Parent": inspectData.Parent})) + } + if inspectData.DockerVersion != "" { + // field is deprecated, but still included in response when present. + legacyOptions = append(legacyOptions, compat.WithExtraFields(map[string]any{"DockerVersion": inspectData.DockerVersion})) + } } if len(legacyOptions) > 0 { diff --git a/integration-cli/docker_api_build_test.go b/integration-cli/docker_api_build_test.go index 506de2ca23..a0be189eef 100644 --- a/integration-cli/docker_api_build_test.go +++ b/integration-cli/docker_api_build_test.go @@ -319,10 +319,22 @@ func (s *DockerAPISuite) TestBuildOnBuildCache(c *testing.T) { // check parentID is correct // Parent is graphdriver-only if !testEnv.UsingSnapshotter() { - image, err := apiClient.ImageInspect(ctx, childID) + var buf bytes.Buffer + _, err := apiClient.ImageInspect(ctx, childID, client.ImageInspectWithRawResponse(&buf)) assert.NilError(c, err) - assert.Check(c, is.Equal(parentID, image.Parent)) //nolint:staticcheck // ignore SA1019: field is deprecated, but still included in response when present. + var image struct { + // Parent is the ID of the parent image. + // + // 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 omitted if the image was pulled from an image registry. + Parent string `json:",omitempty"` + } + rawResponse := buf.Bytes() + err = json.Unmarshal(rawResponse, &image) + assert.NilError(c, err, string(rawResponse)) + assert.Check(c, is.Equal(parentID, image.Parent), string(rawResponse)) } } 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 102b20263f..66a277e557 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 @@ -42,15 +42,6 @@ type InspectResponse struct { // the manifest is generated and its digest calculated. RepoDigests []string - // Parent is the ID of the parent image. - // - // 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 omitted if the image was pulled from an image registry. - // - // Deprecated: this field is deprecated, and will be removed in the next release. - Parent string `json:",omitempty"` - // Comment is an optional message that can be set when committing or // importing the image. This field is omitted if not set. Comment string `json:",omitempty"` @@ -62,13 +53,6 @@ type InspectResponse struct { // and omitted otherwise. Created string `json:",omitempty"` - // DockerVersion is the version of Docker that was used to build the image. - // - // Depending on how the image was created, this field may be omitted. - // - // Deprecated: this field is deprecated, and will be removed in the next release. - 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. // This field is omitted if not set.