emit a "tag" event when building image with "-t" parameter

This is useful for cluster systems such as swarm to sync the image
state when new images are successfully built.

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
Upstream-commit: 2968fa44eb2a53c121ad2b27c519ae47ca7653c3
Component: engine
This commit is contained in:
Shijiang Wei
2015-10-16 23:54:05 +08:00
parent 0425a13d99
commit 12d92cfae8
4 changed files with 47 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
"path/filepath"
@ -6223,3 +6224,37 @@ func (s *DockerSuite) TestBuildNoNamedVolume(c *check.C) {
_, err := buildImage("test", dockerFile, false)
c.Assert(err, check.NotNil, check.Commentf("image build should have failed"))
}
func (s *DockerSuite) TestBuildTagEvent(c *check.C) {
testRequires(c, DaemonIsLinux)
resp, rc, err := sockRequestRaw("GET", `/events?filters={"event":["tag"]}`, nil, "application/json")
c.Assert(err, check.IsNil)
defer rc.Close()
c.Assert(resp.StatusCode, check.Equals, http.StatusOK)
type event struct {
Status string `json:"status"`
ID string `json:"id"`
}
ch := make(chan event)
go func() {
ev := event{}
if err := json.NewDecoder(rc).Decode(&ev); err == nil {
ch <- ev
}
}()
dockerFile := `FROM busybox
RUN echo events
`
_, err = buildImage("test", dockerFile, false)
c.Assert(err, check.IsNil)
select {
case ev := <-ch:
c.Assert(ev.Status, check.Equals, "tag")
c.Assert(ev.ID, check.Equals, "test:")
case <-time.After(time.Second):
c.Fatal("The 'tag' event not heard from the server")
}
}