Decouple (skopeo inspect) output formatting from types.Image.Manifest

Does not change behavior.

This will allow us to move collecting some of the data to the (skopeo
inspect) code and to have a more focused types.Image API, where
types.Image.Manifest() does not return a grab bag of manifest-unrelated
data, eventually.

For how it actually makes the coupling more explicit by having
types.Image.Manifest() return a types.DockerImageManifest instead of the
too generic types.ImageManifest.  We will need to think about which
parts of DockerImageManifest are truly generic, later.
This commit is contained in:
Miloslav Trmač 2016-05-16 16:52:44 +02:00
parent c75f0f6780
commit e3d257e7b5
3 changed files with 31 additions and 10 deletions

View File

@ -3,11 +3,26 @@ package main
import (
"encoding/json"
"fmt"
"time"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
// inspectOutput is the output format of (skopeo inspect), primarily so that we can format it with a simple json.MarshalIndent.
type inspectOutput struct {
Name string
Tag string
Digest string
RepoTags []string
Created time.Time
DockerVersion string
Labels map[string]string
Architecture string
Os string
Layers []string
}
var inspectCmd = cli.Command{
Name: "inspect",
Usage: "inspect images on a registry",
@ -34,7 +49,19 @@ var inspectCmd = cli.Command{
if err != nil {
logrus.Fatal(err)
}
out, err := json.MarshalIndent(imgInspect, "", " ")
outputData := inspectOutput{
Name: imgInspect.Name,
Tag: imgInspect.Tag,
Digest: imgInspect.Digest,
RepoTags: imgInspect.RepoTags,
Created: imgInspect.Created,
DockerVersion: imgInspect.DockerVersion,
Labels: imgInspect.Labels,
Architecture: imgInspect.Architecture,
Os: imgInspect.Os,
Layers: imgInspect.Layers,
}
out, err := json.MarshalIndent(outputData, "", " ")
if err != nil {
logrus.Fatal(err)
}

View File

@ -62,7 +62,7 @@ func (i *dockerImage) Signatures() ([][]byte, error) {
return i.cachedSignatures, nil
}
func (i *dockerImage) Inspect() (types.ImageManifest, error) {
func (i *dockerImage) Inspect() (*types.DockerImageManifest, error) {
// TODO(runcom): unused version param for now, default to docker v2-1
m, err := i.getSchema1Manifest()
if err != nil {
@ -122,7 +122,7 @@ type v1Image struct {
OS string `json:"os,omitempty"`
}
func makeImageManifest(name string, m *manifestSchema1, dgst string, tagList []string) (types.ImageManifest, error) {
func makeImageManifest(name string, m *manifestSchema1, dgst string, tagList []string) (*types.DockerImageManifest, error) {
v1 := &v1Image{}
if err := json.Unmarshal([]byte(m.History[0].V1Compatibility), v1); err != nil {
return nil, err

View File

@ -62,16 +62,10 @@ 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() (ImageManifest, error)
Inspect() (*DockerImageManifest, error)
DockerTar() ([]byte, error) // ??? also, configure output directory
}
// ImageManifest is the interesting subset of metadata about an Image.
// TODO(runcom)
type ImageManifest interface {
String() string
}
// 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 {