Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add open container version to log messages #2001

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions pkg/container/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down