1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/graph/history.go
Doug Davis 0b2fa9c707 Remove engine.Table from docker history and docker rmi
Signed-off-by: Doug Davis <dug@us.ibm.com>
2015-04-03 08:31:30 -07:00

53 lines
1.2 KiB
Go

package graph
import (
"encoding/json"
"fmt"
"strings"
"github.com/docker/docker/api/types"
"github.com/docker/docker/engine"
"github.com/docker/docker/image"
"github.com/docker/docker/utils"
)
func (s *TagStore) CmdHistory(job *engine.Job) error {
if n := len(job.Args); n != 1 {
return fmt.Errorf("Usage: %s IMAGE", job.Name)
}
name := job.Args[0]
foundImage, err := s.LookupImage(name)
if err != nil {
return 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.Unix(),
CreatedBy: strings.Join(img.ContainerConfig.Cmd, " "),
Tags: lookupMap[img.ID],
Size: img.Size,
})
return nil
})
if err = json.NewEncoder(job.Stdout).Encode(history); err != nil {
return err
}
return nil
}