fix: 🐛 fix exec_die actions interpreted as die
This commit is contained in:
16
main.go
16
main.go
@@ -195,7 +195,8 @@ type dockerEvent struct {
|
|||||||
Type string `json:"Type"`
|
Type string `json:"Type"`
|
||||||
Action string `json:"Action"`
|
Action string `json:"Action"`
|
||||||
Actor struct {
|
Actor struct {
|
||||||
ID string `json:"ID"`
|
ID string `json:"ID"`
|
||||||
|
Attributes map[string]string `json:"Attributes"`
|
||||||
} `json:"Actor"`
|
} `json:"Actor"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +210,7 @@ func runDockerEventLoop(ctx context.Context, trigger func()) error {
|
|||||||
return fmt.Errorf("build docker HTTP client: %w", err)
|
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)
|
eventsURL := baseURL + "/events?filters=" + url.QueryEscape(filterVal)
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, eventsURL, nil)
|
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" {
|
if evt.Type != "container" {
|
||||||
continue
|
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":
|
case "start", "stop", "die", "destroy":
|
||||||
actorID := evt.Actor.ID
|
actorID := evt.Actor.ID
|
||||||
if len(actorID) > 12 {
|
if len(actorID) > 12 {
|
||||||
actorID = 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()
|
trigger()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user