mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #22137 from HackToday/addevents
Add load/save image event support
This commit is contained in:
commit
d6176bb03a
8 changed files with 71 additions and 14 deletions
|
@ -980,7 +980,7 @@ func isBrokenPipe(e error) bool {
|
|||
// the same tag are exported. names is the set of tags to export, and
|
||||
// outStream is the writer which the images are written to.
|
||||
func (daemon *Daemon) ExportImage(names []string, outStream io.Writer) error {
|
||||
imageExporter := tarexport.NewTarExporter(daemon.imageStore, daemon.layerStore, daemon.referenceStore)
|
||||
imageExporter := tarexport.NewTarExporter(daemon.imageStore, daemon.layerStore, daemon.referenceStore, daemon)
|
||||
return imageExporter.Save(names, outStream)
|
||||
}
|
||||
|
||||
|
@ -1059,7 +1059,7 @@ func (daemon *Daemon) LookupImage(name string) (*types.ImageInspect, error) {
|
|||
// complement of ImageExport. The input stream is an uncompressed tar
|
||||
// ball containing images and metadata.
|
||||
func (daemon *Daemon) LoadImage(inTar io.ReadCloser, outStream io.Writer, quiet bool) error {
|
||||
imageExporter := tarexport.NewTarExporter(daemon.imageStore, daemon.layerStore, daemon.referenceStore)
|
||||
imageExporter := tarexport.NewTarExporter(daemon.imageStore, daemon.layerStore, daemon.referenceStore, daemon)
|
||||
return imageExporter.Load(inTar, outStream, quiet)
|
||||
}
|
||||
|
||||
|
|
|
@ -2404,7 +2404,7 @@ Docker containers report the following events:
|
|||
|
||||
Docker images report the following events:
|
||||
|
||||
delete, import, pull, push, tag, untag
|
||||
delete, import, load, pull, push, save, tag, untag
|
||||
|
||||
Docker volumes report the following events:
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ Docker containers report the following events:
|
|||
|
||||
Docker images report the following events:
|
||||
|
||||
delete, import, pull, push, tag, untag
|
||||
delete, import, load, pull, push, save, tag, untag
|
||||
|
||||
Docker volumes report the following events:
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ func (l *tarexporter) Load(inTar io.ReadCloser, outStream io.Writer, quiet bool)
|
|||
}
|
||||
|
||||
parentLinks = append(parentLinks, parentLink{imgID, m.Parent})
|
||||
l.loggerImgEvent.LogImageEvent(imgID.String(), imgID.String(), "load")
|
||||
}
|
||||
|
||||
for _, p := range validatedParentLinks(parentLinks) {
|
||||
|
|
|
@ -158,6 +158,7 @@ func (s *saveSession) save(outStream io.Writer) error {
|
|||
|
||||
parentID, _ := s.is.GetParent(id)
|
||||
parentLinks = append(parentLinks, parentLink{id, parentID})
|
||||
s.tarexporter.loggerImgEvent.LogImageEvent(id.String(), id.String(), "save")
|
||||
}
|
||||
|
||||
for i, p := range validatedParentLinks(parentLinks) {
|
||||
|
|
|
@ -22,16 +22,24 @@ type manifestItem struct {
|
|||
}
|
||||
|
||||
type tarexporter struct {
|
||||
is image.Store
|
||||
ls layer.Store
|
||||
rs reference.Store
|
||||
is image.Store
|
||||
ls layer.Store
|
||||
rs reference.Store
|
||||
loggerImgEvent LogImageEvent
|
||||
}
|
||||
|
||||
// LogImageEvent defines interface for event generation related to image tar(load and save) operations
|
||||
type LogImageEvent interface {
|
||||
//LogImageEvent generates an event related to an image operation
|
||||
LogImageEvent(imageID, refName, action string)
|
||||
}
|
||||
|
||||
// NewTarExporter returns new ImageExporter for tar packages
|
||||
func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store) image.Exporter {
|
||||
func NewTarExporter(is image.Store, ls layer.Store, rs reference.Store, loggerImgEvent LogImageEvent) image.Exporter {
|
||||
return &tarexporter{
|
||||
is: is,
|
||||
ls: ls,
|
||||
rs: rs,
|
||||
is: is,
|
||||
ls: ls,
|
||||
rs: rs,
|
||||
loggerImgEvent: loggerImgEvent,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -258,6 +258,45 @@ func (s *DockerSuite) TestEventsImageImport(c *check.C) {
|
|||
c.Assert(matches["action"], checker.Equals, "import", check.Commentf("matches: %v\nout:\n%s\n", matches, out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsImageLoad(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
myImageName := "footest:v1"
|
||||
dockerCmd(c, "tag", "busybox", myImageName)
|
||||
since := daemonUnixTime(c)
|
||||
|
||||
out, _ := dockerCmd(c, "images", "-q", "--no-trunc", myImageName)
|
||||
longImageID := strings.TrimSpace(out)
|
||||
c.Assert(longImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty"))
|
||||
|
||||
dockerCmd(c, "save", "-o", "saveimg.tar", myImageName)
|
||||
dockerCmd(c, "rmi", myImageName)
|
||||
out, _ = dockerCmd(c, "images", "-q", myImageName)
|
||||
noImageID := strings.TrimSpace(out)
|
||||
c.Assert(noImageID, checker.Equals, "", check.Commentf("Should not have any image"))
|
||||
dockerCmd(c, "load", "-i", "saveimg.tar")
|
||||
|
||||
cmd := exec.Command("rm", "-rf", "saveimg.tar")
|
||||
runCommand(cmd)
|
||||
|
||||
out, _ = dockerCmd(c, "images", "-q", "--no-trunc", myImageName)
|
||||
imageID := strings.TrimSpace(out)
|
||||
c.Assert(imageID, checker.Equals, longImageID, check.Commentf("Should have same image id as before"))
|
||||
|
||||
out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=load")
|
||||
events := strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(events, checker.HasLen, 1)
|
||||
matches := eventstestutils.ScanMap(events[0])
|
||||
c.Assert(matches["id"], checker.Equals, imageID, check.Commentf("matches: %v\nout:\n%s\n", matches, out))
|
||||
c.Assert(matches["action"], checker.Equals, "load", check.Commentf("matches: %v\nout:\n%s\n", matches, out))
|
||||
|
||||
out, _ = dockerCmd(c, "events", "--since", since, "--until", daemonUnixTime(c), "--filter", "event=save")
|
||||
events = strings.Split(strings.TrimSpace(out), "\n")
|
||||
c.Assert(events, checker.HasLen, 1)
|
||||
matches = eventstestutils.ScanMap(events[0])
|
||||
c.Assert(matches["id"], checker.Equals, imageID, check.Commentf("matches: %v\nout:\n%s\n", matches, out))
|
||||
c.Assert(matches["action"], checker.Equals, "save", check.Commentf("matches: %v\nout:\n%s\n", matches, out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestEventsFilters(c *check.C) {
|
||||
since := daemonUnixTime(c)
|
||||
dockerCmd(c, "run", "--rm", "busybox", "true")
|
||||
|
|
|
@ -18,11 +18,19 @@ information and real-time information.
|
|||
|
||||
Docker containers will report the following events:
|
||||
|
||||
attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause
|
||||
attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause, update
|
||||
|
||||
and Docker images will report:
|
||||
Docker images report the following events:
|
||||
|
||||
delete, import, pull, push, tag, untag
|
||||
delete, import, load, pull, push, save, tag, untag
|
||||
|
||||
Docker volumes report the following events:
|
||||
|
||||
create, mount, unmount, destroy
|
||||
|
||||
Docker networks report the following events:
|
||||
|
||||
create, connect, disconnect, destroy
|
||||
|
||||
# OPTIONS
|
||||
**--help**
|
||||
|
|
Loading…
Reference in a new issue