Skip to content

Commit

Permalink
Merge pull request moby#13237 from ahmetalpbalkan/tag/event
Browse files Browse the repository at this point in the history
Introduce daemon event 'tag' upon image tagging
  • Loading branch information
LK4D4 committed May 16, 2015
2 parents 42cfc95 + 1630ed9 commit b5e932a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
5 changes: 4 additions & 1 deletion api/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -606,9 +607,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
}
Expand Down
29 changes: 27 additions & 2 deletions integration-cli/docker_cli_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b5e932a

Please sign in to comment.