зеркало из https://github.com/microsoft/docker.git
Move "image_history" to graph/history.go
Signed-off-by: Solomon Hykes <solomon@docker.com>
This commit is contained in:
Родитель
6e28d11d1f
Коммит
55235e121e
|
@ -0,0 +1,46 @@
|
|||
package graph
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/image"
|
||||
)
|
||||
|
||||
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{}
|
||||
}
|
||||
lookupMap[id] = append(lookupMap[id], name+":"+tag)
|
||||
}
|
||||
}
|
||||
|
||||
outs := engine.NewTable("Created", 0)
|
||||
err = foundImage.WalkHistory(func(img *image.Image) error {
|
||||
out := &engine.Env{}
|
||||
out.Set("Id", img.ID)
|
||||
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
|
||||
}
|
|
@ -16,6 +16,7 @@ func (s *TagStore) Install(eng *engine.Engine) error {
|
|||
eng.Register("image_inspect", s.CmdLookup)
|
||||
eng.Register("image_tarlayer", s.CmdTarLayer)
|
||||
eng.Register("image_export", s.CmdImageExport)
|
||||
eng.Register("history", s.CmdHistory)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -335,43 +335,6 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
|
|||
return engine.StatusOK
|
||||
}
|
||||
|
||||
func (srv *Server) ImageHistory(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 := srv.daemon.Repositories().LookupImage(name)
|
||||
if err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
|
||||
lookupMap := make(map[string][]string)
|
||||
for name, repository := range srv.daemon.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 {
|
||||
lookupMap[id] = []string{}
|
||||
}
|
||||
lookupMap[id] = append(lookupMap[id], name+":"+tag)
|
||||
}
|
||||
}
|
||||
|
||||
outs := engine.NewTable("Created", 0)
|
||||
err = foundImage.WalkHistory(func(img *image.Image) error {
|
||||
out := &engine.Env{}
|
||||
out.Set("Id", img.ID)
|
||||
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
|
||||
}
|
||||
func (srv *Server) ImageTag(job *engine.Job) engine.Status {
|
||||
if len(job.Args) != 2 && len(job.Args) != 3 {
|
||||
return job.Errorf("Usage: %s IMAGE REPOSITORY [TAG]\n", job.Name)
|
||||
|
|
|
@ -89,7 +89,6 @@ func InitServer(job *engine.Job) engine.Status {
|
|||
"tag": srv.ImageTag, // FIXME merge with "image_tag"
|
||||
"info": srv.DockerInfo,
|
||||
"images": srv.Images,
|
||||
"history": srv.ImageHistory,
|
||||
"viz": srv.ImagesViz,
|
||||
"log": srv.Log,
|
||||
"load": srv.ImageLoad,
|
||||
|
|
Загрузка…
Ссылка в новой задаче