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 ability to define original image id and image name used in custom images #1978

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion pkg/container/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,17 @@ func (client dockerClient) IsContainerStale(container t.Container, params t.Upda
}

func (client dockerClient) HasNewImage(ctx context.Context, container t.Container) (hasNew bool, latestImage t.ImageID, err error) {
currentImageID := t.ImageID(container.ContainerInfo().ContainerJSONBase.Image)
container_info := container.ContainerInfo()
currentImageID := t.ImageID(container_info.ContainerJSONBase.Image)
imageName := container.ImageName()

// If the original-image-id label is set, it overwrites the image id reported by docker
imageIDSetByLabel, ok := container_info.Config.Labels[originalImageIDLabel]
if ok {
currentImageID = t.ImageID(imageIDSetByLabel)
log.Infof("Original image id for %s found: (%s)", imageName, currentImageID.ShortID())
}

newImageInfo, _, err := client.api.ImageInspectWithRaw(ctx, imageName)
if err != nil {
return false, currentImageID, err
Expand Down
4 changes: 4 additions & 0 deletions pkg/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (c Container) SafeImageID() wt.ImageID {
func (c Container) ImageName() string {
// Compatibility w/ Zodiac deployments
imageName, ok := c.getLabelValue(zodiacLabel)
// If the original-image-name label is set, it overwrites the image name reported by docker
if !ok {
imageName, ok = c.getLabelValue(originalImageNameLabel)
}
if !ok {
imageName = c.containerInfo.Config.Image
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/container/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const (
noPullLabel = "com.centurylinklabs.watchtower.no-pull"
dependsOnLabel = "com.centurylinklabs.watchtower.depends-on"
zodiacLabel = "com.centurylinklabs.zodiac.original-image"
originalImageNameLabel = "com.centurylinklabs.watchtower.original-image"
originalImageIDLabel = "com.centurylinklabs.watchtower.original-image-id"
scope = "com.centurylinklabs.watchtower.scope"
preCheckLabel = "com.centurylinklabs.watchtower.lifecycle.pre-check"
postCheckLabel = "com.centurylinklabs.watchtower.lifecycle.post-check"
Expand Down