mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
945fc9d882
Prior to this patch, the response of - GET /images/json - GET /containers/json - GET /images/(name)/history display the Created Time as UNIX format which doesn't make sense. These should be more readable as CLI command `docker inspect` shows. Due to the case that an older client with a newer version daemon, we need the version check for now. Signed-off-by: Hu Keping <hukeping@huawei.com>
43 lines
1 KiB
Go
43 lines
1 KiB
Go
package graph
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/image"
|
|
"github.com/docker/docker/utils"
|
|
)
|
|
|
|
func (s *TagStore) History(name string) ([]*types.ImageHistory, error) {
|
|
foundImage, err := s.LookupImage(name)
|
|
if err != nil {
|
|
return nil, 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], utils.ImageReference(name, tag))
|
|
}
|
|
}
|
|
|
|
history := []*types.ImageHistory{}
|
|
|
|
err = foundImage.WalkHistory(func(img *image.Image) error {
|
|
history = append(history, &types.ImageHistory{
|
|
ID: img.ID,
|
|
Created: img.Created.UTC(),
|
|
CreatedBy: strings.Join(img.ContainerConfig.Cmd.Slice(), " "),
|
|
Tags: lookupMap[img.ID],
|
|
Size: img.Size,
|
|
Comment: img.Comment,
|
|
})
|
|
return nil
|
|
})
|
|
|
|
return history, err
|
|
}
|