mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
get image name from tags if hash
This commit is contained in:
parent
9bb8991a76
commit
5b5805992e
1 changed files with 19 additions and 0 deletions
|
@ -2,6 +2,7 @@ package container
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -84,6 +85,24 @@ func (c Container) ImageName() string {
|
|||
imageName = c.containerInfo.Config.Image
|
||||
}
|
||||
|
||||
if strings.HasPrefix(imageName, "sha256:") {
|
||||
var tags []string
|
||||
if c.imageInfo != nil {
|
||||
tags = c.imageInfo.RepoTags
|
||||
}
|
||||
|
||||
if len(tags) == 1 {
|
||||
// image has a single repo tag
|
||||
return tags[0]
|
||||
} else if len(tags) < 1 {
|
||||
log.Warn("hash container image with no image info")
|
||||
return ""
|
||||
} else {
|
||||
log.WithField("tags", tags).Warn("hash container image with multiple tags in image info")
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
if !strings.Contains(imageName, ":") {
|
||||
imageName = fmt.Sprintf("%s:latest", imageName)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue