diff options
author | Daniel J Walsh <dwalsh@redhat.com> | 2020-04-19 06:55:59 -0400 |
---|---|---|
committer | Daniel J Walsh <dwalsh@redhat.com> | 2020-04-20 06:13:43 -0400 |
commit | 28c336e996e8f3e192df0f81a94b4f291488094f (patch) | |
tree | add55793a9d97fec873a604311d224fcfcb71ede /cmd | |
parent | e4e42b28dfef0ffd12f2087048dec61f9cb03976 (diff) | |
download | podman-28c336e996e8f3e192df0f81a94b4f291488094f.tar.gz podman-28c336e996e8f3e192df0f81a94b4f291488094f.tar.bz2 podman-28c336e996e8f3e192df0f81a94b4f291488094f.zip |
Pull images when doing podman create
Currently podman create does not pull images if they don't
exist. It should follow the pull policy specified by the
user.
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/containers/create.go | 30 | ||||
-rw-r--r-- | cmd/podman/containers/run.go | 21 |
2 files changed, 32 insertions, 19 deletions
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index 292d5c1ad..0843789eb 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -3,6 +3,7 @@ package containers import ( "fmt" + "github.com/containers/common/pkg/config" "github.com/containers/libpod/cmd/podman/common" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" @@ -61,6 +62,11 @@ func create(cmd *cobra.Command, args []string) error { if err := createInit(cmd); err != nil { return err } + + if err := pullImage(args[0]); err != nil { + return err + } + //TODO rootfs still s := specgen.NewSpecGenerator(rawImageInput) if err := common.FillOutSpecGen(s, &cliVals, args); err != nil { @@ -100,3 +106,27 @@ func createInit(c *cobra.Command) error { return nil } + +func pullImage(imageName string) error { + br, err := registry.ImageEngine().Exists(registry.GetContext(), imageName) + if err != nil { + return err + } + pullPolicy, err := config.ValidatePullPolicy(cliVals.Pull) + if err != nil { + return err + } + if !br.Value || pullPolicy == config.PullImageAlways { + if pullPolicy == config.PullImageNever { + return errors.New("unable to find a name and tag match for busybox in repotags: no such image") + } + _, pullErr := registry.ImageEngine().Pull(registry.GetContext(), imageName, entities.ImagePullOptions{ + Authfile: cliVals.Authfile, + Quiet: cliVals.Quiet, + }) + if pullErr != nil { + return pullErr + } + } + return nil +} diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go index 151f71885..9d222e44d 100644 --- a/cmd/podman/containers/run.go +++ b/cmd/podman/containers/run.go @@ -5,7 +5,6 @@ import ( "os" "strings" - "github.com/containers/common/pkg/config" "github.com/containers/libpod/cmd/podman/common" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/libpod/define" @@ -72,26 +71,10 @@ func run(cmd *cobra.Command, args []string) error { return err } - br, err := registry.ImageEngine().Exists(registry.GetContext(), args[0]) - if err != nil { - return err - } - pullPolicy, err := config.ValidatePullPolicy(cliVals.Pull) - if err != nil { + if err := pullImage(args[0]); err != nil { return err } - if !br.Value || pullPolicy == config.PullImageAlways { - if pullPolicy == config.PullImageNever { - return errors.New("unable to find a name and tag match for busybox in repotags: no such image") - } - _, pullErr := registry.ImageEngine().Pull(registry.GetContext(), args[0], entities.ImagePullOptions{ - Authfile: cliVals.Authfile, - Quiet: cliVals.Quiet, - }) - if pullErr != nil { - return pullErr - } - } + // If -i is not set, clear stdin if !cliVals.Interactive { runOpts.InputStream = nil |