mirror of
https://github.com/containers/skopeo.git
synced 2025-07-06 19:29:18 +00:00
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:
parent
c75f0f6780
commit
e3d257e7b5
@ -3,11 +3,26 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/codegangsta/cli"
|
"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{
|
var inspectCmd = cli.Command{
|
||||||
Name: "inspect",
|
Name: "inspect",
|
||||||
Usage: "inspect images on a registry",
|
Usage: "inspect images on a registry",
|
||||||
@ -34,7 +49,19 @@ var inspectCmd = cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
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 {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func (i *dockerImage) Signatures() ([][]byte, error) {
|
|||||||
return i.cachedSignatures, nil
|
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
|
// TODO(runcom): unused version param for now, default to docker v2-1
|
||||||
m, err := i.getSchema1Manifest()
|
m, err := i.getSchema1Manifest()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -122,7 +122,7 @@ type v1Image struct {
|
|||||||
OS string `json:"os,omitempty"`
|
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{}
|
v1 := &v1Image{}
|
||||||
if err := json.Unmarshal([]byte(m.History[0].V1Compatibility), v1); err != nil {
|
if err := json.Unmarshal([]byte(m.History[0].V1Compatibility), v1); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -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 is like ImageSource.GetSignatures, but the result is cached; it is OK to call this however often you need.
|
||||||
Signatures() ([][]byte, error)
|
Signatures() ([][]byte, error)
|
||||||
Layers(layers ...string) error // configure download directory? Call it DownloadLayers?
|
Layers(layers ...string) error // configure download directory? Call it DownloadLayers?
|
||||||
Inspect() (ImageManifest, error)
|
Inspect() (*DockerImageManifest, error)
|
||||||
DockerTar() ([]byte, error) // ??? also, configure output directory
|
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.
|
// 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.
|
// Note that this is not exactly manifest.json, e.g. some fields have been added.
|
||||||
type DockerImageManifest struct {
|
type DockerImageManifest struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user