2014-08-05 00:50:25 -04:00
|
|
|
package graph
|
|
|
|
|
|
|
|
import (
|
2015-04-03 11:31:30 -04:00
|
|
|
"encoding/json"
|
2015-03-25 03:44:12 -04:00
|
|
|
"fmt"
|
2014-08-05 00:50:25 -04:00
|
|
|
"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/engine"
|
|
|
|
"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-03-25 03:44:12 -04:00
|
|
|
func (s *TagStore) CmdHistory(job *engine.Job) error {
|
2014-08-05 00:50:25 -04:00
|
|
|
if n := len(job.Args); n != 1 {
|
2015-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("Usage: %s IMAGE", job.Name)
|
2014-08-05 00:50:25 -04:00
|
|
|
}
|
|
|
|
name := job.Args[0]
|
|
|
|
foundImage, err := s.LookupImage(name)
|
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return 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-03 11:31:30 -04:00
|
|
|
history := []types.ImageHistory{}
|
|
|
|
|
2014-08-05 00:50:25 -04:00
|
|
|
err = foundImage.WalkHistory(func(img *image.Image) error {
|
2015-04-03 11:31:30 -04:00
|
|
|
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,
|
|
|
|
})
|
2014-08-05 00:50:25 -04:00
|
|
|
return nil
|
|
|
|
})
|
2015-04-03 11:31:30 -04:00
|
|
|
|
|
|
|
if err = json.NewEncoder(job.Stdout).Encode(history); err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-08-05 00:50:25 -04:00
|
|
|
}
|
2015-04-03 11:31:30 -04:00
|
|
|
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2014-08-05 00:50:25 -04:00
|
|
|
}
|