Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions api/server/router/system/system_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,18 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
buffered, l := s.backend.SubscribeToEvents(since, until, ef)
defer s.backend.UnsubscribeFromEvents(l)

shouldSkip := func(ev events.Message) bool { return false }
if versions.LessThan(httputils.VersionFromContext(ctx), "1.46") {
// Image create events were added in API 1.46
shouldSkip = func(ev events.Message) bool {
return ev.Type == "image" && ev.Action == "create"
}
}
Comment on lines +276 to +282
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this slightly from your original approach so that we don't have to do the version compare in each iteration, but instead set up a filter function once.


for _, ev := range buffered {
if shouldSkip(ev) {
continue
}
if err := enc.Encode(ev); err != nil {
return err
}
Expand All @@ -291,6 +302,9 @@ func (s *systemRouter) getEvents(ctx context.Context, w http.ResponseWriter, r *
log.G(ctx).Warnf("unexpected event message: %q", ev)
continue
}
if shouldSkip(jev) {
continue
}
if err := enc.Encode(jev); err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion integration-cli/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli // import "github.com/docker/docker/integration-cli/cli"
import (
"fmt"
"io"
"os"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -161,7 +162,10 @@ func WithTimeout(timeout time.Duration) func(cmd *icmd.Cmd) func() {
// WithEnvironmentVariables sets the specified environment variables for the command to run
func WithEnvironmentVariables(envs ...string) func(cmd *icmd.Cmd) func() {
return func(cmd *icmd.Cmd) func() {
cmd.Env = envs
if cmd.Env == nil {
cmd.Env = os.Environ()
}
cmd.Env = append(cmd.Env, envs...)
return nil
}
}
Expand Down
12 changes: 8 additions & 4 deletions integration-cli/docker_cli_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6215,10 +6215,14 @@ func (s *DockerCLIBuildSuite) TestBuildEmitsImageCreateEvent(t *testing.T) {
t.Log(b.Stdout())
t.Log(b.Stderr())

cmd := cli.Docker(cli.Args("events",
"--filter", "action=create,type=image",
"--since", before.Format(time.RFC3339),
), cli.WithTimeout(time.Millisecond*300))
cmd := cli.Docker(
cli.Args("events",
"--filter", "action=create,type=image",
"--since", before.Format(time.RFC3339),
),
cli.WithTimeout(time.Millisecond*300),
cli.WithEnvironmentVariables("DOCKER_API_VERSION=v1.46"), // FIXME(thaJeztah): integration-cli runs docker CLI 17.06; we're "upgrading" the API version to a version it doesn't support here ;)
)

t.Log(cmd.Stdout())

Expand Down