* API: Add tag lookup to history command. Fixes #882
This commit is contained in:
parent
bd9bf9b646
commit
3bfc822578
3 changed files with 16 additions and 1 deletions
|
@ -2,6 +2,7 @@ package docker
|
|||
|
||||
type APIHistory struct {
|
||||
ID string `json:"Id"`
|
||||
Tag string `json:",omitempty"`
|
||||
Created int64
|
||||
CreatedBy string `json:",omitempty"`
|
||||
}
|
||||
|
|
|
@ -627,7 +627,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
|
|||
fmt.Fprintln(w, "ID\tCREATED\tCREATED BY")
|
||||
|
||||
for _, out := range outs {
|
||||
fmt.Fprintf(w, "%s\t%s ago\t%s\n", out.ID, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy)
|
||||
fmt.Fprintf(w, "%s (%s)\t%s ago\t%s\n", out.ID, out.Tag, utils.HumanDuration(time.Now().Sub(time.Unix(out.Created, 0))), out.CreatedBy)
|
||||
}
|
||||
w.Flush()
|
||||
return nil
|
||||
|
|
14
server.go
14
server.go
|
@ -218,12 +218,26 @@ func (srv *Server) ImageHistory(name string) ([]APIHistory, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
lookupMap := make(map[string]string)
|
||||
for name, repository := range srv.runtime.repositories.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 {
|
||||
if tag != "latest" {
|
||||
continue
|
||||
}
|
||||
}
|
||||
lookupMap[id] = name + ":" + tag
|
||||
}
|
||||
}
|
||||
|
||||
outs := []APIHistory{} //produce [] when empty instead of 'null'
|
||||
err = image.WalkHistory(func(img *Image) error {
|
||||
var out APIHistory
|
||||
out.ID = srv.runtime.repositories.ImageName(img.ShortID())
|
||||
out.Created = img.Created.Unix()
|
||||
out.CreatedBy = strings.Join(img.ContainerConfig.Cmd, " ")
|
||||
out.Tag = lookupMap[img.ID]
|
||||
outs = append(outs, out)
|
||||
return nil
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue