Skip to content

Commit 7053007

Browse files
committed
api/types: move ImageInspect and RootFS to api/types/image
This moves the `ImageInspect` and `RootFS` types to the image package, and deprecates the old location. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent da039ca commit 7053007

10 files changed

Lines changed: 152 additions & 136 deletions

File tree

api/server/router/image/image_routes.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/distribution/reference"
1515
"github.com/docker/docker/api"
1616
"github.com/docker/docker/api/server/httputils"
17-
"github.com/docker/docker/api/types"
1817
"github.com/docker/docker/api/types/backend"
1918
"github.com/docker/docker/api/types/filters"
2019
imagetypes "github.com/docker/docker/api/types/image"
@@ -331,7 +330,7 @@ func (ir *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWrite
331330
return httputils.WriteJSON(w, http.StatusOK, imageInspect)
332331
}
333332

334-
func (ir *imageRouter) toImageInspect(img *image.Image) (*types.ImageInspect, error) {
333+
func (ir *imageRouter) toImageInspect(img *image.Image) (*imagetypes.InspectResponse, error) {
335334
var repoTags, repoDigests []string
336335
for _, ref := range img.Details.References {
337336
switch ref.(type) {
@@ -360,7 +359,7 @@ func (ir *imageRouter) toImageInspect(img *image.Image) (*types.ImageInspect, er
360359
created = img.Created.Format(time.RFC3339Nano)
361360
}
362361

363-
return &types.ImageInspect{
362+
return &imagetypes.InspectResponse{
364363
ID: img.ID().String(),
365364
RepoTags: repoTags,
366365
RepoDigests: repoDigests,
@@ -388,12 +387,12 @@ func (ir *imageRouter) toImageInspect(img *image.Image) (*types.ImageInspect, er
388387
}, nil
389388
}
390389

391-
func rootFSToAPIType(rootfs *image.RootFS) types.RootFS {
390+
func rootFSToAPIType(rootfs *image.RootFS) imagetypes.RootFS {
392391
var layers []string
393392
for _, l := range rootfs.DiffIDs {
394393
layers = append(layers, l.String())
395394
}
396-
return types.RootFS{
395+
return imagetypes.RootFS{
397396
Type: rootfs.Type,
398397
Layers: layers,
399398
}

api/types/image/image_inspect.go

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package image
2+
3+
import (
4+
"github.com/docker/docker/api/types/container"
5+
"github.com/docker/docker/api/types/storage"
6+
)
7+
8+
// RootFS returns Image's RootFS description including the layer IDs.
9+
type RootFS struct {
10+
Type string `json:",omitempty"`
11+
Layers []string `json:",omitempty"`
12+
}
13+
14+
// InspectResponse contains response of Engine API:
15+
// GET "/images/{name:.*}/json"
16+
type InspectResponse struct {
17+
// ID is the content-addressable ID of an image.
18+
//
19+
// This identifier is a content-addressable digest calculated from the
20+
// image's configuration (which includes the digests of layers used by
21+
// the image).
22+
//
23+
// Note that this digest differs from the `RepoDigests` below, which
24+
// holds digests of image manifests that reference the image.
25+
ID string `json:"Id"`
26+
27+
// RepoTags is a list of image names/tags in the local image cache that
28+
// reference this image.
29+
//
30+
// Multiple image tags can refer to the same image, and this list may be
31+
// empty if no tags reference the image, in which case the image is
32+
// "untagged", in which case it can still be referenced by its ID.
33+
RepoTags []string
34+
35+
// RepoDigests is a list of content-addressable digests of locally available
36+
// image manifests that the image is referenced from. Multiple manifests can
37+
// refer to the same image.
38+
//
39+
// These digests are usually only available if the image was either pulled
40+
// from a registry, or if the image was pushed to a registry, which is when
41+
// the manifest is generated and its digest calculated.
42+
RepoDigests []string
43+
44+
// Parent is the ID of the parent image.
45+
//
46+
// Depending on how the image was created, this field may be empty and
47+
// is only set for images that were built/created locally. This field
48+
// is empty if the image was pulled from an image registry.
49+
Parent string
50+
51+
// Comment is an optional message that can be set when committing or
52+
// importing the image.
53+
Comment string
54+
55+
// Created is the date and time at which the image was created, formatted in
56+
// RFC 3339 nano-seconds (time.RFC3339Nano).
57+
//
58+
// This information is only available if present in the image,
59+
// and omitted otherwise.
60+
Created string `json:",omitempty"`
61+
62+
// Container is the ID of the container that was used to create the image.
63+
//
64+
// Depending on how the image was created, this field may be empty.
65+
//
66+
// Deprecated: this field is omitted in API v1.45, but kept for backward compatibility.
67+
Container string `json:",omitempty"`
68+
69+
// ContainerConfig is an optional field containing the configuration of the
70+
// container that was last committed when creating the image.
71+
//
72+
// Previous versions of Docker builder used this field to store build cache,
73+
// and it is not in active use anymore.
74+
//
75+
// Deprecated: this field is omitted in API v1.45, but kept for backward compatibility.
76+
ContainerConfig *container.Config `json:",omitempty"`
77+
78+
// DockerVersion is the version of Docker that was used to build the image.
79+
//
80+
// Depending on how the image was created, this field may be empty.
81+
DockerVersion string
82+
83+
// Author is the name of the author that was specified when committing the
84+
// image, or as specified through MAINTAINER (deprecated) in the Dockerfile.
85+
Author string
86+
Config *container.Config
87+
88+
// Architecture is the hardware CPU architecture that the image runs on.
89+
Architecture string
90+
91+
// Variant is the CPU architecture variant (presently ARM-only).
92+
Variant string `json:",omitempty"`
93+
94+
// OS is the Operating System the image is built to run on.
95+
Os string
96+
97+
// OsVersion is the version of the Operating System the image is built to
98+
// run on (especially for Windows).
99+
OsVersion string `json:",omitempty"`
100+
101+
// Size is the total size of the image including all layers it is composed of.
102+
Size int64
103+
104+
// VirtualSize is the total size of the image including all layers it is
105+
// composed of.
106+
//
107+
// Deprecated: this field is omitted in API v1.44, but kept for backward compatibility. Use Size instead.
108+
VirtualSize int64 `json:"VirtualSize,omitempty"`
109+
110+
// GraphDriver holds information about the storage driver used to store the
111+
// container's and image's filesystem.
112+
GraphDriver storage.DriverData
113+
114+
// RootFS contains information about the image's RootFS, including the
115+
// layer IDs.
116+
RootFS RootFS
117+
118+
// Metadata of the image in the local cache.
119+
//
120+
// This information is local to the daemon, and not part of the image itself.
121+
Metadata Metadata
122+
}

api/types/types.go

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -19,122 +19,6 @@ const (
1919
MediaTypeMultiplexedStream = "application/vnd.docker.multiplexed-stream"
2020
)
2121

22-
// RootFS returns Image's RootFS description including the layer IDs.
23-
type RootFS struct {
24-
Type string `json:",omitempty"`
25-
Layers []string `json:",omitempty"`
26-
}
27-
28-
// ImageInspect contains response of Engine API:
29-
// GET "/images/{name:.*}/json"
30-
type ImageInspect struct {
31-
// ID is the content-addressable ID of an image.
32-
//
33-
// This identifier is a content-addressable digest calculated from the
34-
// image's configuration (which includes the digests of layers used by
35-
// the image).
36-
//
37-
// Note that this digest differs from the `RepoDigests` below, which
38-
// holds digests of image manifests that reference the image.
39-
ID string `json:"Id"`
40-
41-
// RepoTags is a list of image names/tags in the local image cache that
42-
// reference this image.
43-
//
44-
// Multiple image tags can refer to the same image, and this list may be
45-
// empty if no tags reference the image, in which case the image is
46-
// "untagged", in which case it can still be referenced by its ID.
47-
RepoTags []string
48-
49-
// RepoDigests is a list of content-addressable digests of locally available
50-
// image manifests that the image is referenced from. Multiple manifests can
51-
// refer to the same image.
52-
//
53-
// These digests are usually only available if the image was either pulled
54-
// from a registry, or if the image was pushed to a registry, which is when
55-
// the manifest is generated and its digest calculated.
56-
RepoDigests []string
57-
58-
// Parent is the ID of the parent image.
59-
//
60-
// Depending on how the image was created, this field may be empty and
61-
// is only set for images that were built/created locally. This field
62-
// is empty if the image was pulled from an image registry.
63-
Parent string
64-
65-
// Comment is an optional message that can be set when committing or
66-
// importing the image.
67-
Comment string
68-
69-
// Created is the date and time at which the image was created, formatted in
70-
// RFC 3339 nano-seconds (time.RFC3339Nano).
71-
//
72-
// This information is only available if present in the image,
73-
// and omitted otherwise.
74-
Created string `json:",omitempty"`
75-
76-
// Container is the ID of the container that was used to create the image.
77-
//
78-
// Depending on how the image was created, this field may be empty.
79-
//
80-
// Deprecated: this field is omitted in API v1.45, but kept for backward compatibility.
81-
Container string `json:",omitempty"`
82-
83-
// ContainerConfig is an optional field containing the configuration of the
84-
// container that was last committed when creating the image.
85-
//
86-
// Previous versions of Docker builder used this field to store build cache,
87-
// and it is not in active use anymore.
88-
//
89-
// Deprecated: this field is omitted in API v1.45, but kept for backward compatibility.
90-
ContainerConfig *container.Config `json:",omitempty"`
91-
92-
// DockerVersion is the version of Docker that was used to build the image.
93-
//
94-
// Depending on how the image was created, this field may be empty.
95-
DockerVersion string
96-
97-
// Author is the name of the author that was specified when committing the
98-
// image, or as specified through MAINTAINER (deprecated) in the Dockerfile.
99-
Author string
100-
Config *container.Config
101-
102-
// Architecture is the hardware CPU architecture that the image runs on.
103-
Architecture string
104-
105-
// Variant is the CPU architecture variant (presently ARM-only).
106-
Variant string `json:",omitempty"`
107-
108-
// OS is the Operating System the image is built to run on.
109-
Os string
110-
111-
// OsVersion is the version of the Operating System the image is built to
112-
// run on (especially for Windows).
113-
OsVersion string `json:",omitempty"`
114-
115-
// Size is the total size of the image including all layers it is composed of.
116-
Size int64
117-
118-
// VirtualSize is the total size of the image including all layers it is
119-
// composed of.
120-
//
121-
// Deprecated: this field is omitted in API v1.44, but kept for backward compatibility. Use Size instead.
122-
VirtualSize int64 `json:"VirtualSize,omitempty"`
123-
124-
// GraphDriver holds information about the storage driver used to store the
125-
// container's and image's filesystem.
126-
GraphDriver storage.DriverData
127-
128-
// RootFS contains information about the image's RootFS, including the
129-
// layer IDs.
130-
RootFS RootFS
131-
132-
// Metadata of the image in the local cache.
133-
//
134-
// This information is local to the daemon, and not part of the image itself.
135-
Metadata image.Metadata
136-
}
137-
13822
// Container contains response of Engine API:
13923
// GET "/containers/json"
14024
type Container struct {

api/types/types_deprecated.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,14 @@ type Port = container.Port
267267
//
268268
// Deprecated: use [storage.DriverData].
269269
type GraphDriverData = storage.DriverData
270+
271+
// RootFS returns Image's RootFS description including the layer IDs.
272+
//
273+
// Deprecated: use [image.RootFS].
274+
type RootFS = image.RootFS
275+
276+
// ImageInspect contains response of Engine API:
277+
// GET "/images/{name:.*}/json"
278+
//
279+
// Deprecated: use [image.InspectResponse].
280+
type ImageInspect = image.InspectResponse

client/image_inspect.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ import (
66
"encoding/json"
77
"io"
88

9-
"github.com/docker/docker/api/types"
9+
"github.com/docker/docker/api/types/image"
1010
)
1111

1212
// ImageInspectWithRaw returns the image information and its raw representation.
13-
func (cli *Client) ImageInspectWithRaw(ctx context.Context, imageID string) (types.ImageInspect, []byte, error) {
13+
func (cli *Client) ImageInspectWithRaw(ctx context.Context, imageID string) (image.InspectResponse, []byte, error) {
1414
if imageID == "" {
15-
return types.ImageInspect{}, nil, objectNotFoundError{object: "image", id: imageID}
15+
return image.InspectResponse{}, nil, objectNotFoundError{object: "image", id: imageID}
1616
}
1717
serverResp, err := cli.get(ctx, "/images/"+imageID+"/json", nil, nil)
1818
defer ensureReaderClosed(serverResp)
1919
if err != nil {
20-
return types.ImageInspect{}, nil, err
20+
return image.InspectResponse{}, nil, err
2121
}
2222

2323
body, err := io.ReadAll(serverResp.body)
2424
if err != nil {
25-
return types.ImageInspect{}, nil, err
25+
return image.InspectResponse{}, nil, err
2626
}
2727

28-
var response types.ImageInspect
28+
var response image.InspectResponse
2929
rdr := bytes.NewReader(body)
3030
err = json.NewDecoder(rdr).Decode(&response)
3131
return response, body, err

client/image_inspect_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"strings"
1212
"testing"
1313

14-
"github.com/docker/docker/api/types"
14+
"github.com/docker/docker/api/types/image"
1515
"github.com/docker/docker/errdefs"
1616
"github.com/pkg/errors"
1717
"gotest.tools/v3/assert"
@@ -54,7 +54,7 @@ func TestImageInspect(t *testing.T) {
5454
if !strings.HasPrefix(req.URL.Path, expectedURL) {
5555
return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
5656
}
57-
content, err := json.Marshal(types.ImageInspect{
57+
content, err := json.Marshal(image.InspectResponse{
5858
ID: "image_id",
5959
RepoTags: expectedTags,
6060
})

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ type ImageAPIClient interface {
9393
ImageCreate(ctx context.Context, parentReference string, options image.CreateOptions) (io.ReadCloser, error)
9494
ImageHistory(ctx context.Context, image string) ([]image.HistoryResponseItem, error)
9595
ImageImport(ctx context.Context, source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
96-
ImageInspectWithRaw(ctx context.Context, image string) (types.ImageInspect, []byte, error)
96+
ImageInspectWithRaw(ctx context.Context, image string) (image.InspectResponse, []byte, error)
9797
ImageList(ctx context.Context, options image.ListOptions) ([]image.Summary, error)
9898
ImageLoad(ctx context.Context, input io.Reader, quiet bool) (image.LoadResponse, error)
9999
ImagePull(ctx context.Context, ref string, options image.PullOptions) (io.ReadCloser, error)

integration-cli/docker_cli_by_digest_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/docker/distribution/manifest/schema1"
1313
"github.com/docker/distribution/manifest/schema2"
14-
"github.com/docker/docker/api/types"
14+
"github.com/docker/docker/api/types/image"
1515
"github.com/docker/docker/integration-cli/cli"
1616
"github.com/docker/docker/integration-cli/cli/build"
1717
"github.com/opencontainers/go-digest"
@@ -412,7 +412,7 @@ func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *testing.T) {
412412

413413
out := cli.DockerCmd(c, "inspect", imageReference).Stdout()
414414

415-
var imageJSON []types.ImageInspect
415+
var imageJSON []image.InspectResponse
416416
err = json.Unmarshal([]byte(out), &imageJSON)
417417
assert.NilError(c, err)
418418
assert.Equal(c, len(imageJSON), 1)

integration-cli/docker_cli_inspect_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"testing"
1111
"time"
1212

13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/container"
14+
"github.com/docker/docker/api/types/image"
1515
"github.com/docker/docker/integration-cli/cli"
1616
"github.com/docker/docker/internal/testutils/specialimage"
1717
"gotest.tools/v3/assert"
@@ -376,7 +376,7 @@ func (s *DockerCLIInspectSuite) TestInspectRootFS(c *testing.T) {
376376
out, _, err := dockerCmdWithError("inspect", "busybox")
377377
assert.NilError(c, err)
378378

379-
var imageJSON []types.ImageInspect
379+
var imageJSON []image.InspectResponse
380380
err = json.Unmarshal([]byte(out), &imageJSON)
381381
assert.NilError(c, err)
382382
assert.Assert(c, len(imageJSON[0].RootFS.Layers) >= 1)

0 commit comments

Comments
 (0)