2014-08-05 00:50:25 -04:00
|
|
|
package graph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2015-04-03 11:31:30 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
2014-08-05 00:50:25 -04:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
2015-04-10 06:55:07 -04:00
|
|
|
func (s *TagStore) History(name string) ([]*types.ImageHistory, error) {
|
2014-08-05 00:50:25 -04:00
|
|
|
foundImage, err := s.LookupImage(name)
|
|
|
|
if err != nil {
|
2015-04-10 06:55:07 -04:00
|
|
|
return nil, err
|
2014-08-05 00:50:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-10 06:55:07 -04:00
|
|
|
history := []*types.ImageHistory{}
|
2015-04-03 11:31:30 -04:00
|
|
|
|
2014-08-05 00:50:25 -04:00
|
|
|
err = foundImage.WalkHistory(func(img *image.Image) error {
|
2015-04-10 06:55:07 -04:00
|
|
|
history = append(history, &types.ImageHistory{
|
2015-04-03 11:31:30 -04:00
|
|
|
ID: img.ID,
|
2015-05-14 20:31:34 -04:00
|
|
|
Created: img.Created.Unix(),
|
2015-04-10 20:05:21 -04:00
|
|
|
CreatedBy: strings.Join(img.ContainerConfig.Cmd.Slice(), " "),
|
2015-04-03 11:31:30 -04:00
|
|
|
Tags: lookupMap[img.ID],
|
|
|
|
Size: img.Size,
|
2015-01-04 01:47:01 -05:00
|
|
|
Comment: img.Comment,
|
2015-04-03 11:31:30 -04:00
|
|
|
})
|
2014-08-05 00:50:25 -04:00
|
|
|
return nil
|
|
|
|
})
|
2015-04-03 11:31:30 -04:00
|
|
|
|
2015-04-10 06:55:07 -04:00
|
|
|
return history, err
|
2014-08-05 00:50:25 -04:00
|
|
|
}
|