diff --git a/cmd/skopeo/inspect.go b/cmd/skopeo/inspect.go index d3513d9d..f1c32994 100644 --- a/cmd/skopeo/inspect.go +++ b/cmd/skopeo/inspect.go @@ -7,12 +7,13 @@ import ( "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" + "github.com/projectatomic/skopeo/docker" "github.com/projectatomic/skopeo/docker/utils" ) // 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 + Name string `json:",omitempty"` Tag string Digest string RepoTags []string @@ -51,10 +52,10 @@ var inspectCmd = cli.Command{ logrus.Fatal(err) } outputData := inspectOutput{ - // Name is set below. - Tag: imgInspect.Tag, + Name: "", // Possibly overridden for a docker.Image. + Tag: imgInspect.Tag, // Digest is set below. - // RepoTags are set below. + RepoTags: []string{}, // Possibly overriden for a docker.Image. Created: imgInspect.Created, DockerVersion: imgInspect.DockerVersion, Labels: imgInspect.Labels, @@ -66,13 +67,15 @@ var inspectCmd = cli.Command{ if err != nil { logrus.Fatalf("Error computing manifest digest: %s", err.Error()) } - outputData.Name, err = img.SourceRefFullName() - if err != nil { - logrus.Fatalf("Error getting expanded repository name: %s", err.Error()) - } - outputData.RepoTags, err = img.GetRepositoryTags() - if err != nil { - logrus.Fatalf("Error determining repository tags: %s", err.Error()) + if dockerImg, ok := img.(*docker.Image); ok { + outputData.Name, err = dockerImg.SourceRefFullName() + if err != nil { + logrus.Fatalf("Error getting expanded repository name: %s", err.Error()) + } + outputData.RepoTags, err = dockerImg.GetRepositoryTags() + if err != nil { + logrus.Fatalf("Error determining repository tags: %s", err.Error()) + } } out, err := json.MarshalIndent(outputData, "", " ") if err != nil { diff --git a/docker/image.go b/docker/image.go index 621fee39..91d9cb4c 100644 --- a/docker/image.go +++ b/docker/image.go @@ -26,6 +26,14 @@ type genericImage struct { cachedSignatures [][]byte // Private cache for Signatures(); nil if not yet known. } +// GenericImageFromSource returns a types.Image implementation for source. +// NOTE: This is currently an internal testing helper, do not rely on this as +// a stable API. There might be an ImageFromSource eventually, but it would not be +// in the skopeo/docker package. +func GenericImageFromSource(src types.ImageSource) types.Image { + return &genericImage{src: src} +} + // IntendedDockerReference returns the full, unambiguous, Docker reference for this image, _as specified by the user_ // (not as the image itself, or its underlying storage, claims). This can be used e.g. to determine which public keys are trusted for this image. // May be "" if unknown. diff --git a/types/types.go b/types/types.go index 8605a363..9667a00c 100644 --- a/types/types.go +++ b/types/types.go @@ -59,15 +59,9 @@ 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? - // SourceRefFullName returns a fully expanded name for the repository this image is in. - SourceRefFullName() (string, error) // Inspect returns various information for (skopeo inspect) parsed from the manifest and configuration. 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. - // Eventually we should move this away from the generic Image interface, and move it into a Docker-specific case within the (skopeo inspect) command, - // see https://github.com/projectatomic/skopeo/pull/58#discussion_r63411838 . - GetRepositoryTags() ([]string, error) } // ImageInspectInfo is a set of metadata describing Docker images, primarily their manifest and configuration.