2014-08-05 00:50:25 -04:00
|
|
|
package graph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
"github.com/docker/docker/image"
|
2015-02-26 21:23:50 -05:00
|
|
|
"github.com/docker/docker/utils"
|
2014-08-05 00:50:25 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *TagStore) CmdHistory(job *engine.Job) engine.Status {
|
|
|
|
if n := len(job.Args); n != 1 {
|
|
|
|
return job.Errorf("Usage: %s IMAGE", job.Name)
|
|
|
|
}
|
|
|
|
name := job.Args[0]
|
|
|
|
foundImage, err := s.LookupImage(name)
|
|
|
|
if err != nil {
|
|
|
|
return job.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
lookupMap := make(map[string][]string)
|
|
|
|
for name, repository := range s.Repositories {
|
|
|
|
for tag, id := range repository {
|
|
|
|
// If the ID already has a reverse lookup, do not update it unless for "latest"
|
|
|
|
if _, exists := lookupMap[id]; !exists {
|
|
|
|
lookupMap[id] = []string{}
|
|
|
|
}
|
2015-02-26 21:23:50 -05:00
|
|
|
lookupMap[id] = append(lookupMap[id], utils.ImageReference(name, tag))
|
2014-08-05 00:50:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
outs := engine.NewTable("Created", 0)
|
|
|
|
err = foundImage.WalkHistory(func(img *image.Image) error {
|
|
|
|
out := &engine.Env{}
|
2014-12-11 07:56:21 -05:00
|
|
|
out.SetJson("Id", img.ID)
|
2014-08-05 00:50:25 -04:00
|
|
|
out.SetInt64("Created", img.Created.Unix())
|
|
|
|
out.Set("CreatedBy", strings.Join(img.ContainerConfig.Cmd, " "))
|
|
|
|
out.SetList("Tags", lookupMap[img.ID])
|
|
|
|
out.SetInt64("Size", img.Size)
|
|
|
|
outs.Add(out)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if _, err := outs.WriteListTo(job.Stdout); err != nil {
|
|
|
|
return job.Error(err)
|
|
|
|
}
|
|
|
|
return engine.StatusOK
|
|
|
|
}
|