Skip to content

Commit

Permalink
Changed image name to be full image name minus tag. Also added test f…
Browse files Browse the repository at this point in the history
…or new ImageNameDigestFile flag
  • Loading branch information
wripley committed Oct 29, 2019
1 parent c2faa4e commit a065143
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/executor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func DoPush(image v1.Image, opts *config.KanikoOptions) error {
return errors.Wrap(err, "getting tag for destination")
}
if opts.ImageNameDigestFile != "" {
imageName := []byte(destination + "@")
imageName := []byte(destRef.Repository.Name() + "@")
builder.Write(append(imageName, digestByteArray...))
builder.WriteString("\n")
}
Expand Down
31 changes: 31 additions & 0 deletions pkg/executor/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,34 @@ func TestOCILayoutPath(t *testing.T) {
got, err := layoutImage.Manifest()
testutil.CheckErrorAndDeepEqual(t, false, err, want, got)
}

func TestImageNameDigestFile(t *testing.T) {
image, err := random.Image(1024, 4)
if err != nil {
t.Fatalf("could not create image: %s", err)
}

digest, err := image.Digest()
if err != nil {
t.Fatalf("could not get image digest: %s", err)
}

opts := config.KanikoOptions{
NoPush: true,
Destinations: []string{"gcr.io/foo/bar:latest", "bob/image"},
ImageNameDigestFile: "tmpFile",
}

defer os.Remove("tmpFile")

if err := DoPush(image, &opts); err != nil {
t.Fatalf("could not push image: %s", err)
}

want := []byte("gcr.io/foo/bar@" + digest.String() + "\nindex.docker.io/bob/image@" + digest.String() +"\n")

got, err := ioutil.ReadFile("tmpFile")

testutil.CheckErrorAndDeepEqual(t, false, err, want, got)

}

0 comments on commit a065143

Please sign in to comment.