From 7598aab52114389a464a502744e7b1ab9924fb5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 16 May 2016 19:16:52 +0200 Subject: [PATCH] Clean up Image.Inspect This does not change behavior. Rename types.DockerImageManifest to types.ImageInspectInfo. This naming more accurately reflects what the function does and how it is expected to be used. (The only outstanding non-inspection piece is the Name field, which is kind of a subset of GetIntendedDockerReference() right now. Not sure whether that is intentional.) Also fold makeImageManifest into its only user. --- docker/docker_image.go | 34 +++++++++++++--------------------- types/types.go | 9 ++++----- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/docker/docker_image.go b/docker/docker_image.go index b7c1ce47..517d6d3d 100644 --- a/docker/docker_image.go +++ b/docker/docker_image.go @@ -65,7 +65,7 @@ func (i *dockerImage) Signatures() ([][]byte, error) { return i.cachedSignatures, nil } -func (i *dockerImage) Inspect() (*types.DockerImageManifest, error) { +func (i *dockerImage) Inspect() (*types.ImageInspectInfo, error) { // TODO(runcom): unused version param for now, default to docker v2-1 m, err := i.getSchema1Manifest() if err != nil { @@ -75,11 +75,20 @@ func (i *dockerImage) Inspect() (*types.DockerImageManifest, error) { if !ok { return nil, fmt.Errorf("error retrivieng manifest schema1") } - imgManifest, err := makeImageManifest(i.src.ref.FullName(), ms1) - if err != nil { + v1 := &v1Image{} + if err := json.Unmarshal([]byte(ms1.History[0].V1Compatibility), v1); err != nil { return nil, err } - return imgManifest, nil + return &types.ImageInspectInfo{ + Name: i.src.ref.FullName(), + Tag: ms1.Tag, + DockerVersion: v1.DockerVersion, + Created: v1.Created, + Labels: v1.Config.Labels, + Architecture: v1.Architecture, + Os: v1.OS, + Layers: ms1.GetLayers(), + }, nil } // GetRepositoryTags list all tags available in the repository. Note that this has no connection with the tag(s) used for this specific image, if any. @@ -122,23 +131,6 @@ type v1Image struct { OS string `json:"os,omitempty"` } -func makeImageManifest(name string, m *manifestSchema1) (*types.DockerImageManifest, error) { - v1 := &v1Image{} - if err := json.Unmarshal([]byte(m.History[0].V1Compatibility), v1); err != nil { - return nil, err - } - return &types.DockerImageManifest{ - Name: name, - Tag: m.Tag, - DockerVersion: v1.DockerVersion, - Created: v1.Created, - Labels: v1.Config.Labels, - Architecture: v1.Architecture, - Os: v1.OS, - Layers: m.GetLayers(), - }, nil -} - // TODO(runcom) func (i *dockerImage) DockerTar() ([]byte, error) { return nil, nil diff --git a/types/types.go b/types/types.go index 20bd6dce..5273ce7f 100644 --- a/types/types.go +++ b/types/types.go @@ -62,15 +62,14 @@ type Image interface { // Signatures is like ImageSource.GetSignatures, but the result is cached; it is OK to call this however often you need. Signatures() ([][]byte, error) Layers(layers ...string) error // configure download directory? Call it DownloadLayers? - Inspect() (*DockerImageManifest, error) + Inspect() (*ImageInspectInfo, error) DockerTar() ([]byte, error) // ??? also, configure output directory // GetRepositoryTags list all tags available in the repository. Note that this has no connection with the tag(s) used for this specific image, if any. GetRepositoryTags() ([]string, error) } -// DockerImageManifest is a set of metadata describing Docker images and their manifest.json files. -// Note that this is not exactly manifest.json, e.g. some fields have been added. -type DockerImageManifest struct { +// ImageInspectInfo is a set of metadata describing Docker images, primarily their manifest and configuration. +type ImageInspectInfo struct { Name string Tag string Created time.Time @@ -81,6 +80,6 @@ type DockerImageManifest struct { Layers []string } -func (m *DockerImageManifest) String() string { +func (m *ImageInspectInfo) String() string { return fmt.Sprintf("%s:%s", m.Name, m.Tag) }