Skip to content

Commit

Permalink
fix(ko): Display correct tag
Browse files Browse the repository at this point in the history
Display the expected tag after successfully building a ko image, for
both sideloaded and published images.

Also handles the `tagPolicy.sha256` scenarios.

Fixes: GoogleContainerTools#6835
Tracking: GoogleContainerTools#6041
  • Loading branch information
halvards committed Nov 11, 2021
1 parent a9d7152 commit 8033e5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion integration/ko_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ func TestBuildAndPushKoImageProgrammatically(t *testing.T) {
Workspace: exampleAppDir,
}
imageName := fmt.Sprintf("%s/%s", registryAddr, "skaffold-ko")
digest, err := b.Build(context.Background(), &imageFullNameBuffer, artifact, imageName)
imageNameWithTag := fmt.Sprintf("%s:%s", imageName, "latest")
digest, err := b.Build(context.Background(), &imageFullNameBuffer, artifact, imageNameWithTag)
if err != nil {
t.Fatalf("b.Build(): %+v", err)
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/skaffold/build/ko/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact
if err != nil {
return "", fmt.Errorf("could not build and publish ko image %q: %w", a.ImageName, err)
}
fmt.Fprintln(out, imageRef.Name())

outputRef := ref
if strings.HasSuffix(ref, ":latest") {
// handle tagPolicy sha256
outputRef = imageRef.Name()
}
fmt.Fprintln(out, outputRef)

return b.getImageIdentifier(ctx, imageRef, ref)
}
Expand Down

0 comments on commit 8033e5a

Please sign in to comment.