Add --digestfile flag to output built digest to file.

This flag, when set, takes a file in the container and writes the image digest to it. This can be used to extract the exact digest of the built image by surrounding tooling without having to parse the logs from Kaniko, for example by pointing the file to a mounted volume or to a file used durint exit status, such as with Kubernetes' [Termination message policy](https://kubernetes.io/docs/tasks/debug-application-cluster/determine-reason-pod-failure/)]

When the flag is not set, the digest is not written to file and the executor behaves as before. The digest is also written to file in case of a tarball or a `--no-push`.

Closes #654
This commit is contained in:
Gijs
2019-05-02 14:57:44 +02:00
parent 404af20f7c
commit a6e3ddfc79
4 changed files with 29 additions and 0 deletions
+14
View File
@@ -19,6 +19,7 @@ package executor
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"time"
@@ -74,6 +75,19 @@ func CheckPushPermissions(opts *config.KanikoOptions) 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 image != nil && opts.DigestFile != "" {
digest, err := image.Digest()
if err != nil {
return errors.Wrap(err, "error fetching digest")
}
digestByteArray := []byte(digest.String())
err = ioutil.WriteFile(opts.DigestFile, digestByteArray, 0644)
if err != nil {
return errors.Wrap(err, "writing digest to file failed")
}
}
destRefs := []name.Tag{}
for _, destination := range opts.Destinations {
destRef, err := name.NewTag(destination, name.WeakValidation)