full diff: https://github.com/docker/docker/compare/b6684a403c99aaf6be5b8ce0bef3c6650fcdcd12...a09e6e323e55e1a9b21df9c2c555f5668df3ac9b relevant changes: - moby/moby#39995 Update containerd binary to v1.2.10 - moby/moby#40001 Update runc to v1.0.0-rc8-92-g84373aaa (CVE-2019-16884) - moby/moby#39999 bump golang 1.13.1 (CVE-2019-16276) - moby/moby#40102 bump golang 1.13.3 (CVE-2019-17596) - moby/moby#40134 Revert "homedir: add cgo or osusergo buildtag constraints for unix" - reverts moby/moby#39994 homedir: add cgo or osusergo buildtag constraints for unix, in favor of documenting when to set the `osusergo` build tag. The `osusergo` build-flag must be used when compiling a static binary with `cgo` enabled, and linking against `glibc`. - moby/moby#39983 builder: remove legacy build's session handling This feature was used by docker build --stream and it was kept experimental. Users of this endpoint should enable BuildKit anyway by setting Version to BuilderBuildKit. - Related: #2105 build: remove --stream (was experimental) - moby/moby #40045 Bump logrus 1.4.2, go-shellwords, mergo, flock, creack/pty, golang/gddo, gorilla/mux - moby/moby#39713 bump containerd and dependencies to v1.3.0 - moby/moby#39987 Add ability to handle index acknowledgment with splunk log driver - moby/moby#40070 Use ocischema package instead of custom handler - relates to moby/moby#39727 Docker 19.03 doesn't support OCI image - relates to docker/hub-feedback#1871 - relates to docker/distribution#3024 - moby/moby#39231 Add support for sending down service Running and Desired task counts - moby/moby#39822 daemon: Use short libnetwork ID in exec-root - moby/moby#39100 Use Microsoft/hcsshim constants and deprecate pkg/system.GetOsVersion() - updates/requires Microsoft/hscshim@2226e083fc Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
103 lines
2.3 KiB
Go
103 lines
2.3 KiB
Go
package client // import "github.com/docker/docker/client"
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/url"
|
|
"time"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/events"
|
|
"github.com/docker/docker/api/types/filters"
|
|
timetypes "github.com/docker/docker/api/types/time"
|
|
)
|
|
|
|
// Events returns a stream of events in the daemon. It's up to the caller to close the stream
|
|
// by cancelling the context. Once the stream has been completely read an io.EOF error will
|
|
// be sent over the error channel. If an error is sent all processing will be stopped. It's up
|
|
// to the caller to reopen the stream in the event of an error by reinvoking this method.
|
|
func (cli *Client) Events(ctx context.Context, options types.EventsOptions) (<-chan events.Message, <-chan error) {
|
|
|
|
messages := make(chan events.Message)
|
|
errs := make(chan error, 1)
|
|
|
|
started := make(chan struct{})
|
|
go func() {
|
|
defer close(errs)
|
|
|
|
query, err := buildEventsQueryParams(cli.version, options)
|
|
if err != nil {
|
|
close(started)
|
|
errs <- err
|
|
return
|
|
}
|
|
|
|
resp, err := cli.get(ctx, "/events", query, nil)
|
|
if err != nil {
|
|
close(started)
|
|
errs <- err
|
|
return
|
|
}
|
|
defer resp.body.Close()
|
|
|
|
decoder := json.NewDecoder(resp.body)
|
|
|
|
close(started)
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
errs <- ctx.Err()
|
|
return
|
|
default:
|
|
var event events.Message
|
|
if err := decoder.Decode(&event); err != nil {
|
|
errs <- err
|
|
return
|
|
}
|
|
|
|
select {
|
|
case messages <- event:
|
|
case <-ctx.Done():
|
|
errs <- ctx.Err()
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}()
|
|
<-started
|
|
|
|
return messages, errs
|
|
}
|
|
|
|
func buildEventsQueryParams(cliVersion string, options types.EventsOptions) (url.Values, error) {
|
|
query := url.Values{}
|
|
ref := time.Now()
|
|
|
|
if options.Since != "" {
|
|
ts, err := timetypes.GetTimestamp(options.Since, ref)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
query.Set("since", ts)
|
|
}
|
|
|
|
if options.Until != "" {
|
|
ts, err := timetypes.GetTimestamp(options.Until, ref)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
query.Set("until", ts)
|
|
}
|
|
|
|
if options.Filters.Len() > 0 {
|
|
//nolint:staticcheck // ignore SA1019 for old code
|
|
filterJSON, err := filters.ToParamWithVersion(cliVersion, options.Filters)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
query.Set("filters", filterJSON)
|
|
}
|
|
|
|
return query, nil
|
|
}
|