From d044a50bd0727114ce0f85ca145e3db8892e8b89 Mon Sep 17 00:00:00 2001 From: Zeusina Date: Sun, 15 Mar 2026 22:09:32 +0300 Subject: [PATCH] fix: :bug: fix exec_die actions interpreted as die --- main.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 4d198b8..498eb94 100644 --- a/main.go +++ b/main.go @@ -195,7 +195,8 @@ type dockerEvent struct { Type string `json:"Type"` Action string `json:"Action"` Actor struct { - ID string `json:"ID"` + ID string `json:"ID"` + Attributes map[string]string `json:"Attributes"` } `json:"Actor"` } @@ -209,7 +210,7 @@ func runDockerEventLoop(ctx context.Context, trigger func()) error { return fmt.Errorf("build docker HTTP client: %w", err) } - filterVal := `{"type":["container"]}` + filterVal := `{"type":["container"],"event":["start","stop","die","destroy"]}` eventsURL := baseURL + "/events?filters=" + url.QueryEscape(filterVal) req, err := http.NewRequestWithContext(ctx, http.MethodGet, eventsURL, nil) @@ -243,13 +244,20 @@ func runDockerEventLoop(ctx context.Context, trigger func()) error { if evt.Type != "container" { continue } - switch evt.Action { + // Docker may append extra details after ":" for some event kinds. + // We only care about the base action token. + action := evt.Action + if idx := strings.Index(action, ":"); idx >= 0 { + action = strings.TrimSpace(action[:idx]) + } + + switch action { case "start", "stop", "die", "destroy": actorID := evt.Actor.ID if len(actorID) > 12 { actorID = actorID[:12] } - slog.Debug("docker event received", "action", evt.Action, "id", actorID) + slog.Debug("docker event received", "action", action, "id", actorID) trigger() } }