Skip to content

Commit

Permalink
fix: log missing image name
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
  • Loading branch information
caarlos0 committed Nov 15, 2022
1 parent 096c6ba commit 1a9209e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
22 changes: 13 additions & 9 deletions internal/pipe/docker/docker_test.go
Expand Up @@ -1445,15 +1445,19 @@ func TestWithDigest(t *testing.T) {
Type: artifact.DockerImage,
})

t.Run("good", func(t *testing.T) {
require.Equal(t, "owner/img:t1@sha256:d1", withDigest("owner/img:t1", artifacts.List()))
})
for _, use := range []string{useDocker, useBuildx} {
t.Run(use, func(t *testing.T) {
t.Run("good", func(t *testing.T) {
require.Equal(t, "localhost:5050/owner/img:t1@sha256:d1", withDigest(use, "localhost:5050/owner/img:t1", artifacts.List()))
})

t.Run("no digest", func(t *testing.T) {
require.Equal(t, "owner/img:t3", withDigest("owner/img:t3", artifacts.List()))
})
t.Run("no digest", func(t *testing.T) {
require.Equal(t, "localhost:5050/owner/img:t3", withDigest(use, "localhost:5050/owner/img:t3", artifacts.List()))
})

t.Run("no match", func(t *testing.T) {
require.Equal(t, "owner/img:t4", withDigest("owner/img:t4", artifacts.List()))
})
t.Run("no match", func(t *testing.T) {
require.Equal(t, "localhost:5050/owner/img:t4", withDigest(use, "localhost:5050/owner/img:t4", artifacts.List()))
})
})
}
}
6 changes: 3 additions & 3 deletions internal/pipe/docker/manifest.go
Expand Up @@ -123,15 +123,15 @@ func manifestImages(ctx *context.Context, manifest config.DockerManifest) ([]str
if err != nil {
return []string{}, err
}
imgs = append(imgs, withDigest(str, artifacts))
imgs = append(imgs, withDigest(manifest.Use, str, artifacts))
}
if strings.TrimSpace(strings.Join(manifest.ImageTemplates, "")) == "" {
return imgs, pipe.Skip("manifest has no images")
}
return imgs, nil
}

func withDigest(name string, images []*artifact.Artifact) string {
func withDigest(use, name string, images []*artifact.Artifact) string {
for _, art := range images {
if art.Name == name {
if digest := artifact.ExtraOr(*art, artifact.ExtraDigest, ""); digest != "" {
Expand All @@ -140,6 +140,6 @@ func withDigest(name string, images []*artifact.Artifact) string {
break
}
}
log.Warnf("did not find the digest for %s, defaulting to insecure mode")
log.Warnf("did not find the digest for %s using %s, defaulting to insecure mode", name, use)
return name
}

0 comments on commit 1a9209e

Please sign in to comment.