github.com/jandre/docker@v1.7.0/graph/history.go (about) 1 package graph 2 3 import ( 4 "strings" 5 6 "github.com/docker/docker/api/types" 7 "github.com/docker/docker/image" 8 "github.com/docker/docker/utils" 9 ) 10 11 func (s *TagStore) History(name string) ([]*types.ImageHistory, error) { 12 foundImage, err := s.LookupImage(name) 13 if err != nil { 14 return nil, err 15 } 16 17 lookupMap := make(map[string][]string) 18 for name, repository := range s.Repositories { 19 for tag, id := range repository { 20 // If the ID already has a reverse lookup, do not update it unless for "latest" 21 if _, exists := lookupMap[id]; !exists { 22 lookupMap[id] = []string{} 23 } 24 lookupMap[id] = append(lookupMap[id], utils.ImageReference(name, tag)) 25 } 26 } 27 28 history := []*types.ImageHistory{} 29 30 err = foundImage.WalkHistory(func(img *image.Image) error { 31 history = append(history, &types.ImageHistory{ 32 ID: img.ID, 33 Created: img.Created.Unix(), 34 CreatedBy: strings.Join(img.ContainerConfig.Cmd.Slice(), " "), 35 Tags: lookupMap[img.ID], 36 Size: img.Size, 37 Comment: img.Comment, 38 }) 39 return nil 40 }) 41 42 return history, err 43 }