feat: support https URLs for digest-file (#2811)

This feature allows one to specify an https URL for any of the
digest-file options, resulting in an HTTP PUT to the provided
URL. This could for example be a (pre-signed) URL to S3 or GCS.

Currently the final digest is only written to the local filesystem,
which disappears and is not accessible when Kaniko is run in a
managed container service like AWS ECS.

By supporting https a single implementation supports all storage
services, without the need for special code for S3, GCS, etc..
This commit is contained in:
Lio李歐
2023-11-10 11:05:36 -08:00
committed by GitHub
parent 5133ad83b1
commit e5395c7a21
2 changed files with 42 additions and 0 deletions
+12
View File
@@ -17,6 +17,7 @@ limitations under the License.
package executor
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
@@ -136,6 +137,17 @@ func getDigest(image v1.Image) ([]byte, error) {
}
func writeDigestFile(path string, digestByteArray []byte) error {
if strings.HasPrefix(path, "https://") {
// Do a HTTP PUT to the URL; this could be a pre-signed URL to S3 or GCS or Azure
req, err := http.NewRequest("PUT", path, bytes.NewReader(digestByteArray)) //nolint:noctx
if err != nil {
return err
}
req.Header.Set("Content-Type", "text/plain")
_, err = http.DefaultClient.Do(req)
return err
}
parentDir := filepath.Dir(path)
if _, err := os.Stat(parentDir); os.IsNotExist(err) {
if err := os.MkdirAll(parentDir, 0700); err != nil {