Cleanup messages on podman load

If user does not specify file or redirect for stdin, then
throw an error

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh 2019-03-16 06:46:35 -04:00
parent ea54a1c2f5
commit d0ee203986
No known key found for this signature in database
GPG key ID: A2DF901DABE2C028
6 changed files with 49 additions and 52 deletions

View file

@ -12,7 +12,7 @@ popularized by Kubernetes. Libpod also contains the Pod Manager tool `(Podman)`
At a high level, the scope of libpod and podman is the following:
* Support multiple image formats including the existing Docker/OCI image formats.
* Support multiple image formats including the OCI and Docker image formats.
* Support for multiple means to download images including trust & image verification.
* Container image management (managing image layers, overlay filesystems, etc).
* Full management of container lifecycle

View file

@ -5,21 +5,24 @@ import (
"io"
"io/ioutil"
"os"
"strings"
"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/shared/parse"
"github.com/containers/libpod/pkg/adapter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)
var (
loadCommand cliconfig.LoadValues
loadDescription = "Loads the image from docker-archive stored on the local machine."
_loadCommand = &cobra.Command{
Use: "load [flags] [PATH]",
Short: "Load an image from docker archive",
loadDescription = "Loads an image from a locally stored archive (tar file) into container storage."
_loadCommand = &cobra.Command{
Use: "load [flags] [NAME[:TAG]]",
Short: "Load an image from container archive",
Long: loadDescription,
RunE: func(cmd *cobra.Command, args []string) error {
loadCommand.InputArgs = args
@ -60,49 +63,43 @@ func loadCmd(c *cliconfig.LoadValues) error {
}
defer runtime.Shutdown(false)
input := c.Input
if runtime.Remote && len(input) == 0 {
return errors.New("the remote client requires you to load via -i and a tarball")
}
if len(input) == 0 {
input = "/dev/stdin"
c.Input = input
fi, err := os.Stdin.Stat()
if err != nil {
if len(c.Input) > 0 {
if err := parse.ValidateFileName(c.Input); err != nil {
return err
}
// checking if loading from pipe
if !fi.Mode().IsRegular() {
outFile, err := ioutil.TempFile("/var/tmp", "podman")
if err != nil {
return errors.Errorf("error creating file %v", err)
}
defer os.Remove(outFile.Name())
defer outFile.Close()
inFile, err := os.OpenFile(input, 0, 0666)
if err != nil {
return errors.Errorf("error reading file %v", err)
}
defer inFile.Close()
_, err = io.Copy(outFile, inFile)
if err != nil {
return errors.Errorf("error copying file %v", err)
}
input = outFile.Name()
} else {
if terminal.IsTerminal(int(os.Stdin.Fd())) {
return errors.Errorf("cannot read from terminal. Use command-line redirection or the --input flag.")
}
}
if err := parse.ValidateFileName(input); err != nil {
return err
outFile, err := ioutil.TempFile("/var/tmp", "podman")
if err != nil {
return errors.Errorf("error creating file %v", err)
}
defer os.Remove(outFile.Name())
defer outFile.Close()
_, err = io.Copy(outFile, os.Stdin)
if err != nil {
return errors.Errorf("error copying file %v", err)
}
c.Input = outFile.Name()
}
names, err := runtime.LoadImage(getContext(), imageName, c)
if err != nil {
return err
}
if len(imageName) > 0 {
split := strings.Split(names, ",")
newImage, err := runtime.NewImageFromLocal(split[0])
if err != nil {
return err
}
if err := newImage.TagImage(imageName); err != nil {
return errors.Wrapf(err, "error adding '%s' to image %q", imageName, newImage.InputName)
}
}
fmt.Println("Loaded image(s): " + names)
return nil
}

View file

@ -34,7 +34,7 @@
| [podman-info(1)](/docs/podman-info.1.md) | Display system information |[![...](/docs/play.png)](https://asciinema.org/a/yKbi5fQ89y5TJ8e1RfJd4ivTD)|
| [podman-inspect(1)](/docs/podman-inspect.1.md) | Display the configuration of a container or image |[![...](/docs/play.png)](https://asciinema.org/a/133418)|
| [podman-kill(1)](/docs/podman-kill.1.md) | Kill the main process in one or more running containers |[![...](/docs/play.png)](https://asciinema.org/a/3jNos0A5yzO4hChu7ddKkUPw7)|
| [podman-load(1)](/docs/podman-load.1.md) | Load an image from docker archive or oci |[![...](/docs/play.png)](https://asciinema.org/a/kp8kOaexEhEa20P1KLZ3L5X4g)|
| [podman-load(1)](/docs/podman-load.1.md) | Load an image from a container image archive |[![...](/docs/play.png)](https://asciinema.org/a/kp8kOaexEhEa20P1KLZ3L5X4g)|
| [podman-login(1)](/docs/podman-login.1.md) | Login to a container registry |[![...](/docs/play.png)](https://asciinema.org/a/oNiPgmfo1FjV2YdesiLpvihtV)|
| [podman-logout(1)](/docs/podman-logout.1.md) | Logout of a container registry |[![...](/docs/play.png)](https://asciinema.org/a/oNiPgmfo1FjV2YdesiLpvihtV)|
| [podman-logs(1)](/docs/podman-logs.1.md) | Display the logs of a container |[![...](/docs/play.png)](https://asciinema.org/a/MZPTWD5CVs3dMREkBxQBY9C5z)|

View file

@ -1,22 +1,24 @@
% podman-load(1)
## NAME
podman\-load - Load an image from docker archive
podman\-load - Load an image from a container image archive into container storage
## SYNOPSIS
**podman load** [ARCHIVE]
**podman load** [*name*[:*tag*]]
## DESCRIPTION
**podman load** copies an image from either **docker-archive** or **oci-archive** stored
on the local machine. **podman load** reads from stdin by default or a file if the **input** flag is set.
The **quiet** flag suppresses the output when set.
**podman load** loads an image from either an **oci-archive** or **docker-archive** stored on the local machine into container storage. **podman load** reads from stdin by default or a file if the **input** option is set.
You can also specify a name for the image if the archive does not contain a named reference, of if you want an additonal name for the local image.
The **quiet** option suppresses the progress output when set.
Note: `:` is a restricted character and cannot be part of the file name.
**podman [GLOBAL OPTIONS]**
**podman load [GLOBAL OPTIONS]**
**podman load [OPTIONS] NAME[:TAG|@DIGEST]**
**podman load [OPTIONS] NAME[:TAG]**
## OPTIONS
@ -28,7 +30,7 @@ The remote client requires the use of this option.
**--quiet, -q**
Suppress the output
Suppress the progress output
**--signature-policy="PATHNAME"**
@ -75,7 +77,7 @@ Loaded image: registry.fedoraproject.org/fedora:latest
```
## SEE ALSO
podman(1), podman-save(1), crio(8)
podman(1), podman-save(1), podman-tag(1), crio(8)
## HISTORY
July 2017, Originally compiled by Urvashi Mohnani <umohnani@redhat.com>

View file

@ -1,14 +1,13 @@
% podman-save(1)
## NAME
podman\-save - Save an image to docker-archive or oci-archive
podman\-save - Save an image to a container archive
## SYNOPSIS
**podman save** [*options*] *name*[:*tag*]
## DESCRIPTION
**podman save** saves an image to either **docker-archive**, **oci-archive**, **oci-dir** (directory
with oci manifest type), or **docker-dir** (directory with v2s2 manifest type) on the local machine,
**podman save** saves an image to either **docker-archive**, **oci-archive**, **oci-dir** (directory with oci manifest type), or **docker-dir** (directory with v2s2 manifest type) on the local machine,
default is **docker-archive**. **podman save** writes to STDOUT by default and can be redirected to a
file using the **output** flag. The **quiet** flag suppresses the output when set.
Note: `:` is a restricted character and cannot be part of the file name.

View file

@ -268,7 +268,6 @@ registries = []
# If you need to block pull access from a registry, uncomment the section below
# and add the registries fully-qualified name.
#
# Docker only
[registries.block]
registries = []
```