github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/daemon/images/image_events.go (about) 1 package images // import "github.com/docker/docker/daemon/images" 2 3 import ( 4 "github.com/docker/docker/api/types/events" 5 ) 6 7 // LogImageEvent generates an event related to an image with only the default attributes. 8 func (i *ImageService) LogImageEvent(imageID, refName, action string) { 9 i.LogImageEventWithAttributes(imageID, refName, action, map[string]string{}) 10 } 11 12 // LogImageEventWithAttributes generates an event related to an image with specific given attributes. 13 func (i *ImageService) LogImageEventWithAttributes(imageID, refName, action string, attributes map[string]string) { 14 img, err := i.GetImage(imageID, nil) 15 if err == nil && img.Config != nil { 16 // image has not been removed yet. 17 // it could be missing if the event is `delete`. 18 copyAttributes(attributes, img.Config.Labels) 19 } 20 if refName != "" { 21 attributes["name"] = refName 22 } 23 actor := events.Actor{ 24 ID: imageID, 25 Attributes: attributes, 26 } 27 28 i.eventsService.Log(action, events.ImageEventType, actor) 29 } 30 31 // copyAttributes guarantees that labels are not mutated by event triggers. 32 func copyAttributes(attributes, labels map[string]string) { 33 if labels == nil { 34 return 35 } 36 for k, v := range labels { 37 attributes[k] = v 38 } 39 }