mirror of
https://github.com/GoogleContainerTools/kaniko
synced 2026-10-18 07:19:55 +02:00
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:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user