diff --git a/pkg/executor/push.go b/pkg/executor/push.go index bf3158a06c..bfdacaa039 100644 --- a/pkg/executor/push.go +++ b/pkg/executor/push.go @@ -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") } diff --git a/pkg/executor/push_test.go b/pkg/executor/push_test.go index f771e400ed..6bc5dcbef0 100644 --- a/pkg/executor/push_test.go +++ b/pkg/executor/push_test.go @@ -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) + +}