From 5b5805992ed3f6ce1236ba4f6016be490431268d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nils=20m=C3=A5s=C3=A9n?= Date: Sun, 25 Jul 2021 12:27:06 +0200 Subject: [PATCH] get image name from tags if hash --- pkg/container/container.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkg/container/container.go b/pkg/container/container.go index 4ea3e9f..67d30aa 100644 --- a/pkg/container/container.go +++ b/pkg/container/container.go @@ -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) }