summaryrefslogtreecommitdiff
path: root/cmd/podman/import.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-27 09:57:44 -0600
committerbaude <bbaude@redhat.com>2019-02-05 10:05:41 -0600
commit64c8fb7c2460eb561c8496f781f26d65443eea59 (patch)
tree19a7bae6cd3bc117fa7b2e9dfe44d3534b4f75ed /cmd/podman/import.go
parent3554bfce98bc643bd4724340bf2abbaa6373e70c (diff)
downloadpodman-64c8fb7c2460eb561c8496f781f26d65443eea59.tar.gz
podman-64c8fb7c2460eb561c8496f781f26d65443eea59.tar.bz2
podman-64c8fb7c2460eb561c8496f781f26d65443eea59.zip
podman-remote import|export
addition of import and export for the podman-remote client. This includes the ability to send and receive files between the remote-client and the "podman" host using an upgraded varlink connection. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/import.go')
-rw-r--r--cmd/podman/import.go77
1 files changed, 7 insertions, 70 deletions
diff --git a/cmd/podman/import.go b/cmd/podman/import.go
index 144354fa6..661bd5a65 100644
--- a/cmd/podman/import.go
+++ b/cmd/podman/import.go
@@ -2,16 +2,8 @@ package main
import (
"fmt"
- "io"
- "io/ioutil"
- "net/http"
- "net/url"
- "os"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
- "github.com/containers/libpod/libpod/image"
- "github.com/containers/libpod/pkg/util"
- "github.com/opencontainers/image-spec/specs-go/v1"
+ "github.com/containers/libpod/libpod/adapter"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@@ -51,7 +43,7 @@ func importCmd(c *cli.Context) error {
return err
}
- runtime, err := libpodruntime.GetRuntime(c)
+ runtime, err := adapter.GetRuntime(c)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
@@ -60,7 +52,6 @@ func importCmd(c *cli.Context) error {
var (
source string
reference string
- writer io.Writer
)
args := c.Args()
@@ -80,67 +71,13 @@ func importCmd(c *cli.Context) error {
return err
}
- changes := v1.ImageConfig{}
- if c.IsSet("change") || c.IsSet("c") {
- changes, err = util.GetImageConfig(c.StringSlice("change"))
- if err != nil {
- return errors.Wrapf(err, "error adding config changes to image %q", source)
- }
+ quiet := c.Bool("quiet")
+ if runtime.Remote {
+ quiet = false
}
-
- history := []v1.History{
- {Comment: c.String("message")},
- }
-
- config := v1.Image{
- Config: changes,
- History: history,
- }
-
- writer = nil
- if !c.Bool("quiet") {
- writer = os.Stderr
- }
-
- // if source is a url, download it and save to a temp file
- u, err := url.ParseRequestURI(source)
- if err == nil && u.Scheme != "" {
- file, err := downloadFromURL(source)
- if err != nil {
- return err
- }
- defer os.Remove(file)
- source = file
- }
-
- newImage, err := runtime.ImageRuntime().Import(getContext(), source, reference, writer, image.SigningOptions{}, config)
+ iid, err := runtime.Import(getContext(), source, reference, c.StringSlice("change"), c.String("message"), quiet)
if err == nil {
- fmt.Println(newImage.ID())
+ fmt.Println(iid)
}
return err
}
-
-// donwloadFromURL downloads an image in the format "https:/example.com/myimage.tar"
-// and temporarily saves in it /var/tmp/importxyz, which is deleted after the image is imported
-func downloadFromURL(source string) (string, error) {
- fmt.Printf("Downloading from %q\n", source)
-
- outFile, err := ioutil.TempFile("/var/tmp", "import")
- if err != nil {
- return "", errors.Wrap(err, "error creating file")
- }
- defer outFile.Close()
-
- response, err := http.Get(source)
- if err != nil {
- return "", errors.Wrapf(err, "error downloading %q", source)
- }
- defer response.Body.Close()
-
- _, err = io.Copy(outFile, response.Body)
- if err != nil {
- return "", errors.Wrapf(err, "error saving %s to %s", source, outFile.Name())
- }
-
- return outFile.Name(), nil
-}