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

Avoid adding image digest twice to tag on render #5958

Merged
merged 1 commit into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion pkg/skaffold/build/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package build

import (
"context"
"strings"

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

func TagWithDigest(tag, digest string) string {
return tag + "@" + digest
digestSuffix := "@" + digest
if strings.HasSuffix(tag, digestSuffix) {
return tag
}
return tag + digestSuffix
}

func TagWithImageID(ctx context.Context, tag string, imageID string, localDocker docker.LocalDaemon) (string, error) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/skaffold/build/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ func TestMergeWithPreviousBuilds(t *testing.T) {
testutil.CheckDeepEqual(t, "img1:tag1_3,img2:tag2_3", tags(builds))
}

func TestTagWithDigest(t *testing.T) {
tag := TagWithDigest("some-tag", "sha256:abcd1234")
testutil.CheckDeepEqual(t, "some-tag@sha256:abcd1234", tag)
tag = TagWithDigest("some-tag@sha256:abcd1234", "sha256:abcd1234")
testutil.CheckDeepEqual(t, "some-tag@sha256:abcd1234", tag)
}

func artifact(image, tag string) graph.Artifact {
return graph.Artifact{
ImageName: image,
Expand Down