2022-03-24 21:51:50 +01:00
|
|
|
package events
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-03-25 12:17:05 +01:00
|
|
|
"log"
|
|
|
|
|
2022-03-24 21:51:50 +01:00
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
dockerEvents "github.com/docker/docker/api/types/events"
|
|
|
|
"github.com/docker/docker/client"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Container struct {
|
|
|
|
Action string
|
|
|
|
ID string
|
|
|
|
Container *types.ContainerJSON
|
|
|
|
}
|
|
|
|
|
|
|
|
//goland:noinspection ALL
|
|
|
|
func (c Container) __interface_event() {
|
|
|
|
panic("interface event guard")
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeContainer(message dockerEvents.Message, client *client.Client) Event {
|
|
|
|
var e Container
|
|
|
|
e.ID = message.Actor.ID
|
|
|
|
e.Action = message.Action
|
|
|
|
|
|
|
|
if message.Action != "destroy" {
|
|
|
|
container, err := client.ContainerInspect(context.TODO(), message.Actor.ID)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("error inspecting container %v: %v", message.Actor.ID, err)
|
|
|
|
} else {
|
|
|
|
e.Container = &container
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|