2016-05-21 16:36:11 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2017-05-16 19:56:56 -04:00
|
|
|
"runtime"
|
2016-05-21 16:36:11 -04:00
|
|
|
"time"
|
|
|
|
|
2017-01-25 19:54:18 -05:00
|
|
|
"github.com/docker/distribution/reference"
|
2016-09-06 14:18:12 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2016-05-21 16:36:11 -04:00
|
|
|
"github.com/docker/docker/layer"
|
2016-12-10 03:03:38 -05:00
|
|
|
"github.com/pkg/errors"
|
2016-05-21 16:36:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// LookupImage looks up an image by name and returns it as an ImageInspect
|
|
|
|
// structure.
|
|
|
|
func (daemon *Daemon) LookupImage(name string) (*types.ImageInspect, error) {
|
|
|
|
img, err := daemon.GetImage(name)
|
|
|
|
if err != nil {
|
2016-12-10 03:03:38 -05:00
|
|
|
return nil, errors.Wrapf(err, "no such image: %s", name)
|
2016-05-21 16:36:11 -04:00
|
|
|
}
|
|
|
|
|
2017-05-16 19:56:56 -04:00
|
|
|
// If the image OS isn't set, assume it's the host OS
|
|
|
|
platform := img.OS
|
|
|
|
if platform == "" {
|
|
|
|
platform = runtime.GOOS
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:43:36 -04:00
|
|
|
refs := daemon.referenceStore.References(img.ID().Digest())
|
2016-05-21 16:36:11 -04:00
|
|
|
repoTags := []string{}
|
|
|
|
repoDigests := []string{}
|
|
|
|
for _, ref := range refs {
|
|
|
|
switch ref.(type) {
|
|
|
|
case reference.NamedTagged:
|
2017-01-25 19:54:18 -05:00
|
|
|
repoTags = append(repoTags, reference.FamiliarString(ref))
|
2016-05-21 16:36:11 -04:00
|
|
|
case reference.Canonical:
|
2017-01-25 19:54:18 -05:00
|
|
|
repoDigests = append(repoDigests, reference.FamiliarString(ref))
|
2016-05-21 16:36:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var size int64
|
|
|
|
var layerMetadata map[string]string
|
|
|
|
layerID := img.RootFS.ChainID()
|
|
|
|
if layerID != "" {
|
2017-05-16 19:56:56 -04:00
|
|
|
l, err := daemon.stores[platform].layerStore.Get(layerID)
|
2016-05-21 16:36:11 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-05-16 19:56:56 -04:00
|
|
|
defer layer.ReleaseAndLog(daemon.stores[platform].layerStore, l)
|
2016-05-21 16:36:11 -04:00
|
|
|
size, err = l.Size()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
layerMetadata, err = l.Metadata()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
comment := img.Comment
|
|
|
|
if len(comment) == 0 && len(img.History) > 0 {
|
|
|
|
comment = img.History[len(img.History)-1].Comment
|
|
|
|
}
|
|
|
|
|
2017-03-02 15:47:02 -05:00
|
|
|
lastUpdated, err := daemon.stores[platform].imageStore.GetLastUpdated(img.ID())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-05-21 16:36:11 -04:00
|
|
|
imageInspect := &types.ImageInspect{
|
|
|
|
ID: img.ID().String(),
|
|
|
|
RepoTags: repoTags,
|
|
|
|
RepoDigests: repoDigests,
|
|
|
|
Parent: img.Parent.String(),
|
|
|
|
Comment: comment,
|
|
|
|
Created: img.Created.Format(time.RFC3339Nano),
|
|
|
|
Container: img.Container,
|
|
|
|
ContainerConfig: &img.ContainerConfig,
|
|
|
|
DockerVersion: img.DockerVersion,
|
|
|
|
Author: img.Author,
|
|
|
|
Config: img.Config,
|
|
|
|
Architecture: img.Architecture,
|
2017-05-16 19:56:56 -04:00
|
|
|
Os: platform,
|
2016-09-28 18:02:28 -04:00
|
|
|
OsVersion: img.OSVersion,
|
2016-05-21 16:36:11 -04:00
|
|
|
Size: size,
|
|
|
|
VirtualSize: size, // TODO: field unused, deprecate
|
|
|
|
RootFS: rootFSToAPIType(img.RootFS),
|
2017-03-02 15:47:02 -05:00
|
|
|
Metadata: types.ImageMetadata{
|
|
|
|
LastTagTime: lastUpdated,
|
|
|
|
},
|
2016-05-21 16:36:11 -04:00
|
|
|
}
|
|
|
|
|
2017-05-16 19:56:56 -04:00
|
|
|
imageInspect.GraphDriver.Name = daemon.GraphDriverName(platform)
|
2016-05-21 16:36:11 -04:00
|
|
|
imageInspect.GraphDriver.Data = layerMetadata
|
|
|
|
|
|
|
|
return imageInspect, nil
|
|
|
|
}
|