fix: 🐛 fix exec_die actions interpreted as die

This commit is contained in:
2026-03-15 22:09:32 +03:00
parent 0533f23e3d
commit d044a50bd0

16
main.go
View File

@@ -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()
}
}