From 4a1e6b24fd045430901a1b22d97cf615bd1be923 Mon Sep 17 00:00:00 2001 From: Aaron U'Ren Date: Sat, 13 Jul 2024 19:28:29 -0500 Subject: [PATCH] feat: add open container version to log messages --- pkg/container/client.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/container/client.go b/pkg/container/client.go index c6c37deb3..cecd0d434 100644 --- a/pkg/container/client.go +++ b/pkg/container/client.go @@ -20,7 +20,10 @@ import ( t "github.com/containrrr/watchtower/pkg/types" ) -const defaultStopSignal = "SIGTERM" +const ( + defaultStopSignal = "SIGTERM" + openContainerVersion = "org.opencontainers.image.version" +) // A Client is the interface through which watchtower interacts with the // Docker API. @@ -192,6 +195,10 @@ func (client dockerClient) StopContainer(c t.Container, timeout time.Duration) e shortID := c.ID().ShortID() if c.IsRunning() { + openVer, ok := c.ContainerInfo().Config.Labels[openContainerVersion] + if ok { + shortID = fmt.Sprintf("%s - %s", shortID, openVer) + } log.Infof("Stopping %s (%s) with %s", c.Name(), shortID, signal) if err := client.api.ContainerKill(bg, idStr, signal); err != nil { return err @@ -343,7 +350,13 @@ func (client dockerClient) HasNewImage(ctx context.Context, container t.Containe return false, currentImageID, nil } - log.Infof("Found new %s image (%s)", imageName, newImageID.ShortID()) + imageID := newImageID.ShortID() + openImageVer, ok := newImageInfo.Config.Labels[openContainerVersion] + if ok { + imageID = fmt.Sprintf("%s - %s", imageID, openImageVer) + } + + log.Infof("Found new %s image (%s)", imageName, imageID) return true, newImageID, nil }