mirror of
https://github.com/containers/skopeo.git
synced 2025-09-16 23:09:01 +00:00
Make types.Image Docker-independent
The remaining uses of the dependencies, in (skopeo inspect), now check whether their types.Image is a docker.Image and call the docker.Image functions directly. This does not change behavior for Docker images. For non-Docker images (which can't happen yet), the Name field is removed; RepoTags remain and are reported as empty, because using json:",omitempty" would also omit an empty list for Docker images.
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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.
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user