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.
This commit is contained in:
Miloslav Trmač
2016-05-16 19:16:52 +02:00
parent 9766f72760
commit 7598aab521
2 changed files with 17 additions and 26 deletions

View File

@@ -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

View File

@@ -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)
}