1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Introduce daemon event 'tag' upon image tagging

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
This commit is contained in:
Ahmet Alp Balkan 2015-05-15 00:01:06 +00:00
parent e4855eebf2
commit 1630ed97ac
2 changed files with 31 additions and 3 deletions

View file

@ -35,6 +35,7 @@ import (
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/docker/pkg/version"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/utils"
)
type ServerConfig struct {
@ -701,9 +702,11 @@ func (s *Server) postImagesTag(version version.Version, w http.ResponseWriter, r
repo := r.Form.Get("repo")
tag := r.Form.Get("tag")
force := boolValue(r, "force")
if err := s.daemon.Repositories().Tag(repo, tag, vars["name"], force); err != nil {
name := vars["name"]
if err := s.daemon.Repositories().Tag(repo, tag, name, force); err != nil {
return err
}
s.daemon.EventsService.Log("tag", utils.ImageReference(repo, tag), "")
w.WriteHeader(http.StatusCreated)
return nil
}

View file

@ -38,8 +38,8 @@ func (s *DockerSuite) TestEventsTimestampFormats(c *check.C) {
c.Fatalf("docker events cmd failed: %v\nout=%s", err, out)
}
events := strings.Split(strings.TrimSpace(out), "\n")
if len(events) != 1 {
c.Fatalf("unexpected events, was expecting only 1 (since=%s, until=%s) out=%s", since, until, out)
if len(events) != 2 {
c.Fatalf("unexpected events, was expecting only 2 events tag/untag (since=%s, until=%s) out=%s", since, until, out)
}
if !strings.Contains(out, "untag") {
c.Fatalf("expected 'untag' event not found (since=%s, until=%s) out=%s", since, until, out)
@ -230,6 +230,31 @@ func (s *DockerSuite) TestEventsImageUntagDelete(c *check.C) {
}
}
func (s *DockerSuite) TestEventsImageTag(c *check.C) {
time.Sleep(time.Second * 2) // because API has seconds granularity
since := daemonTime(c).Unix()
image := "testimageevents:tag"
dockerCmd(c, "tag", "busybox", image)
eventsCmd := exec.Command(dockerBinary, "events",
fmt.Sprintf("--since=%d", since),
fmt.Sprintf("--until=%d", daemonTime(c).Unix()))
out, _, err := runCommandWithOutput(eventsCmd)
c.Assert(err, check.IsNil)
events := strings.Split(strings.TrimSpace(out), "\n")
if len(events) != 1 {
c.Fatalf("was expecting 1 event. out=%s", out)
}
event := strings.TrimSpace(events[0])
expectedStr := image + ": tag"
if !strings.HasSuffix(event, expectedStr) {
c.Fatalf("wrong event format. expected='%s' got=%s", expectedStr, event)
}
}
func (s *DockerSuite) TestEventsImagePull(c *check.C) {
since := daemonTime(c).Unix()
testRequires(c, Network)