Made changes to --image-name-with-digest-file to support multiple destinations
@@ -107,17 +107,18 @@ func getDigest(image v1.Image) ([]byte, error){
// DoPush is responsible for pushing image to the destinations specified in opts
func DoPush(image v1.Image, opts *config.KanikoOptions) error {
t := timing.Start("Total Push Time")
-
- if opts.DigestFile != "" {
- // digest, err := image.Digest()
- // if err != nil {
- // return errors.Wrap(err, "error fetching digest")
- // }
- digestByteArray, err := getDigest(image)
+ var digestByteArray []byte
+ var builder strings.Builder
+ if opts.DigestFile != "" || opts.ImageNameDigestFile != "" {
+ var err error
+ digestByteArray, err = getDigest(image)
if err != nil {
return errors.Wrap(err, "error fetching digest")
}
- err = ioutil.WriteFile(opts.DigestFile, digestByteArray, 0644)
+ }
+
+ if opts.DigestFile != "" {
+ err := ioutil.WriteFile(opts.DigestFile, digestByteArray, 0644)
if err != nil {
return errors.Wrap(err, "writing digest to file failed")
}
@@ -140,18 +141,19 @@ func DoPush(image v1.Image, opts *config.KanikoOptions) error {
return errors.Wrap(err, "getting tag for destination")
}
if opts.ImageNameDigestFile != "" {
- digestByteArray, err := getDigest(image)
- if err != nil {
- return errors.Wrap(err, "error fetching digest")
- }
imageName := []byte(destination + "@")
- err = ioutil.WriteFile(opts.ImageNameDigestFile, append(imageName, digestByteArray...), 0644)
+ builder.Write(append(imageName, digestByteArray...))
+ builder.WriteString("\n")
+ }
+ destRefs = append(destRefs, destRef)
+ }
+
+ if opts.ImageNameDigestFile != "" {
+ err := ioutil.WriteFile(opts.ImageNameDigestFile, []byte(builder.String()), 0644)
if err != nil {
return errors.Wrap(err, "writing digest to file failed")
}
}
- destRefs = append(destRefs, destRef)
- }
if opts.TarPath != "" {
tagToImage := map[name.Tag]v1.Image{}
