Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7c3ab3

Browse files
committedMar 15, 2021
Allow loading image from standard input stream
1 parent ea1d023 commit c7c3ab3

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed
 

‎cmd/minikube/cmd/image.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package cmd
1818

1919
import (
20+
"io"
21+
"io/ioutil"
2022
"os"
2123
"strings"
2224

@@ -40,6 +42,22 @@ var (
4042
imgRemote bool
4143
)
4244

45+
func saveFile(r io.Reader) (string, error) {
46+
tmp, err := ioutil.TempFile("", "build.*.tar")
47+
if err != nil {
48+
return "", err
49+
}
50+
_, err = io.Copy(tmp, r)
51+
if err != nil {
52+
return "", err
53+
}
54+
err = tmp.Close()
55+
if err != nil {
56+
return "", err
57+
}
58+
return tmp.Name(), nil
59+
}
60+
4361
// loadImageCmd represents the image load command
4462
var loadImageCmd = &cobra.Command{
4563
Use: "load",
@@ -61,7 +79,11 @@ var loadImageCmd = &cobra.Command{
6179
local = false
6280
} else {
6381
for _, img := range args {
64-
if strings.HasPrefix(img, "/") || strings.HasPrefix(img, ".") {
82+
if img == "-" { // stdin
83+
local = true
84+
imgDaemon = false
85+
imgRemote = false
86+
} else if strings.HasPrefix(img, "/") || strings.HasPrefix(img, ".") {
6587
local = true
6688
imgDaemon = false
6789
imgRemote = false
@@ -78,6 +100,14 @@ var loadImageCmd = &cobra.Command{
78100
}
79101
}
80102

103+
if args[0] == "-" {
104+
tmp, err := saveFile(os.Stdin)
105+
if err != nil {
106+
exit.Error(reason.GuestImageLoad, "Failed to save stdin", err)
107+
}
108+
args = []string{tmp}
109+
}
110+
81111
// Currently "image.retrieveImage" always tries to load both from daemon and from remote
82112
// There is no way to skip daemon.Image or remote.Image, for the vague "ref" string given.
83113
if imgDaemon || imgRemote {

0 commit comments

Comments
 (0)
Please sign in to comment.