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