Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Commit d60d5bb

Browse files
committed
feat: add open container version to log messages
1 parent d6bb80a commit d60d5bb

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pkg/container/client.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import (
2020
t "github.com/beatkind/watchtower/pkg/types"
2121
)
2222

23-
const defaultStopSignal = "SIGTERM"
23+
const (
24+
defaultStopSignal = "SIGTERM"
25+
openContainerVersion = "org.opencontainers.image.version"
26+
)
2427

2528
// A Client is the interface through which watchtower interacts with the
2629
// Docker API.
@@ -193,6 +196,10 @@ func (client dockerClient) StopContainer(c t.Container, timeout time.Duration) e
193196
shortID := c.ID().ShortID()
194197

195198
if c.IsRunning() {
199+
openVer, ok := c.ContainerInfo().Config.Labels[openContainerVersion]
200+
if ok {
201+
shortID = fmt.Sprintf("%s - %s", shortID, openVer)
202+
}
196203
log.Infof("Stopping %s (%s) with %s", c.Name(), shortID, signal)
197204
if err := client.api.ContainerKill(bg, idStr, signal); err != nil {
198205
return err
@@ -349,7 +356,13 @@ func (client dockerClient) HasNewImage(ctx context.Context, container t.Containe
349356
return false, currentImageID, nil
350357
}
351358

352-
log.Infof("Found new %s image (%s)", imageName, newImageID.ShortID())
359+
imageID := newImageID.ShortID()
360+
openImageVer, ok := newImageInfo.Config.Labels[openContainerVersion]
361+
if ok {
362+
imageID = fmt.Sprintf("%s - %s", imageID, openImageVer)
363+
}
364+
365+
log.Infof("Found new %s image (%s)", imageName, imageID)
353366
return true, newImageID, nil
354367
}
355368

0 commit comments

Comments
 (0)