Skip to content

Commit cbeefdc

Browse files
authored
Avoid adding image digest twice to tag on render (#5958)
This can happen when reading tags from file (--build-artifacts) where the tag already has a digest.
1 parent 9136544 commit cbeefdc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

pkg/skaffold/build/util.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package build
1818

1919
import (
2020
"context"
21+
"strings"
2122

2223
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
2324
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
@@ -54,7 +55,11 @@ func MergeWithPreviousBuilds(builds, previous []graph.Artifact) []graph.Artifact
5455
}
5556

5657
func TagWithDigest(tag, digest string) string {
57-
return tag + "@" + digest
58+
digestSuffix := "@" + digest
59+
if strings.HasSuffix(tag, digestSuffix) {
60+
return tag
61+
}
62+
return tag + digestSuffix
5863
}
5964

6065
func TagWithImageID(ctx context.Context, tag string, imageID string, localDocker docker.LocalDaemon) (string, error) {

pkg/skaffold/build/util_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ func TestMergeWithPreviousBuilds(t *testing.T) {
3939
testutil.CheckDeepEqual(t, "img1:tag1_3,img2:tag2_3", tags(builds))
4040
}
4141

42+
func TestTagWithDigest(t *testing.T) {
43+
tag := TagWithDigest("some-tag", "sha256:abcd1234")
44+
testutil.CheckDeepEqual(t, "some-tag@sha256:abcd1234", tag)
45+
tag = TagWithDigest("some-tag@sha256:abcd1234", "sha256:abcd1234")
46+
testutil.CheckDeepEqual(t, "some-tag@sha256:abcd1234", tag)
47+
}
48+
4249
func artifact(image, tag string) graph.Artifact {
4350
return graph.Artifact{
4451
ImageName: image,

0 commit comments

Comments
 (0)