diff options
author | umohnani8 <umohnani@redhat.com> | 2017-11-29 16:56:18 -0500 |
---|---|---|
committer | umohnani8 <umohnani@redhat.com> | 2017-12-12 09:46:23 -0500 |
commit | 74ee579375654c79fa710f13b7c2ee3810366f82 (patch) | |
tree | 36f1b98582875e497b7e76457cb969d85cef6426 /libpod/image_inspect.go | |
parent | 88121e0747c03084c233d22fadfd3c227e73a885 (diff) | |
download | podman-74ee579375654c79fa710f13b7c2ee3810366f82.tar.gz podman-74ee579375654c79fa710f13b7c2ee3810366f82.tar.bz2 podman-74ee579375654c79fa710f13b7c2ee3810366f82.zip |
Update kpod inspect to use the new container state
kpod inspect now uses the new libpod container state
and closely matches the output of docker inspect
some aspects of it are still WIP as the libpod container state
is still being worked on
Signed-off-by: umohnani8 <umohnani@redhat.com>
Diffstat (limited to 'libpod/image_inspect.go')
-rw-r--r-- | libpod/image_inspect.go | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/libpod/image_inspect.go b/libpod/image_inspect.go new file mode 100644 index 000000000..a08665434 --- /dev/null +++ b/libpod/image_inspect.go @@ -0,0 +1,81 @@ +package libpod + +import ( + "encoding/json" + "strings" + + "github.com/containers/image/types" + "github.com/containers/storage" + digest "github.com/opencontainers/go-digest" + ociv1 "github.com/opencontainers/image-spec/specs-go/v1" + "github.com/pkg/errors" + "github.com/projectatomic/libpod/libpod/driver" +) + +func getImageData(img storage.Image, imgRef types.Image, size int64, driver *driver.Data) (*ImageData, error) { + imgSize, err := imgRef.Size() + if err != nil { + return nil, errors.Wrapf(err, "error reading size of image %q", img.ID) + } + manifest, manifestType, err := imgRef.Manifest() + if err != nil { + return nil, errors.Wrapf(err, "error reading manifest for image %q", img.ID) + } + imgDigest := digest.Digest("") + if len(manifest) > 0 { + imgDigest = digest.Canonical.FromBytes(manifest) + } + annotations := annotations(manifest, manifestType) + + ociv1Img, err := imgRef.OCIConfig() + if err != nil { + return nil, errors.Wrapf(err, "error getting oci image info %q", img.ID) + } + info, err := imgRef.Inspect() + if err != nil { + return nil, errors.Wrapf(err, "error getting image info %q", img.ID) + } + + var repoDigests []string + for _, name := range img.Names { + repoDigests = append(repoDigests, strings.SplitN(name, ":", 2)[0]+"@"+imgDigest.String()) + } + + data := &ImageData{ + ID: img.ID, + RepoTags: img.Names, + RepoDigests: repoDigests, + Comment: ociv1Img.History[0].Comment, + Created: ociv1Img.Created, + Author: ociv1Img.History[0].Author, + Architecture: ociv1Img.Architecture, + Os: ociv1Img.OS, + Config: &ociv1Img.Config, + Version: info.DockerVersion, + Size: size, + VirtualSize: size + imgSize, + Annotations: annotations, + Digest: imgDigest, + Labels: info.Labels, + RootFS: &RootFS{ + Type: ociv1Img.RootFS.Type, + Layers: ociv1Img.RootFS.DiffIDs, + }, + GraphDriver: driver, + } + return data, nil +} + +func annotations(manifest []byte, manifestType string) map[string]string { + annotations := make(map[string]string) + switch manifestType { + case ociv1.MediaTypeImageManifest: + var m ociv1.Manifest + if err := json.Unmarshal(manifest, &m); err == nil { + for k, v := range m.Annotations { + annotations[k] = v + } + } + } + return annotations +} |