aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common/specgen.go20
-rw-r--r--cmd/podman/containers/ps.go1
-rw-r--r--cmd/podman/images/list.go18
-rw-r--r--cmd/podman/images/save.go31
-rw-r--r--cmd/podman/images/utils_linux.go47
-rw-r--r--cmd/podman/images/utils_unsupported.go7
-rw-r--r--cmd/podman/registry/remote.go26
-rw-r--r--cmd/podman/root.go11
-rw-r--r--cmd/podman/system/connection/add.go13
-rw-r--r--cmd/podman/validate/args.go32
-rw-r--r--cmd/podman/validate/latest.go7
11 files changed, 145 insertions, 68 deletions
diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go
index 0b6897d3a..bf50bb56b 100644
--- a/cmd/podman/common/specgen.go
+++ b/cmd/podman/common/specgen.go
@@ -387,8 +387,6 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
s.Annotations = annotations
s.WorkDir = c.Workdir
- userCommand := []string{}
- var command []string
if c.Entrypoint != nil {
entrypoint := []string{}
if ep := *c.Entrypoint; len(ep) > 0 {
@@ -398,27 +396,13 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
}
}
s.Entrypoint = entrypoint
- // Build the command
- // If we have an entry point, it goes first
- command = entrypoint
}
// Include the command used to create the container.
s.ContainerCreateCommand = os.Args
if len(inputCommand) > 0 {
- // User command overrides data CMD
- command = append(command, inputCommand...)
- userCommand = append(userCommand, inputCommand...)
- }
-
- switch {
- case len(inputCommand) > 0:
- s.Command = userCommand
- case c.Entrypoint != nil:
- s.Command = []string{}
- default:
- s.Command = command
+ s.Command = inputCommand
}
// SHM Size
@@ -527,6 +511,8 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
}
switch con[0] {
+ case "proc-opts":
+ s.ProcOpts = strings.Split(con[1], ",")
case "label":
// TODO selinux opts and label opts are the same thing
s.ContainerSecurityConfig.SelinuxOpts = append(s.ContainerSecurityConfig.SelinuxOpts, con[1])
diff --git a/cmd/podman/containers/ps.go b/cmd/podman/containers/ps.go
index 64271031d..ebb6ed98f 100644
--- a/cmd/podman/containers/ps.go
+++ b/cmd/podman/containers/ps.go
@@ -109,6 +109,7 @@ func jsonOut(responses []entities.ListContainer) error {
r := make([]entities.ListContainer, 0)
for _, con := range responses {
con.CreatedAt = units.HumanDuration(time.Since(time.Unix(con.Created, 0))) + " ago"
+ con.Status = psReporter{con}.Status()
r = append(r, con)
}
b, err := json.MarshalIndent(r, "", " ")
diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go
index ee0f64d99..043871a8c 100644
--- a/cmd/podman/images/list.go
+++ b/cmd/podman/images/list.go
@@ -195,6 +195,7 @@ func sortImages(imageS []*entities.ImageSummary) ([]imageReporter, error) {
} else {
h.ImageSummary = *e
h.Repository = "<none>"
+ h.Tag = "<none>"
imgs = append(imgs, h)
}
listFlag.readOnly = e.IsReadOnly()
@@ -205,27 +206,34 @@ func sortImages(imageS []*entities.ImageSummary) ([]imageReporter, error) {
}
func tokenRepoTag(ref string) (string, string, error) {
-
if ref == "<none>:<none>" {
return "<none>", "<none>", nil
}
repo, err := reference.Parse(ref)
if err != nil {
- return "", "", err
+ return "<none>", "<none>", err
}
named, ok := repo.(reference.Named)
if !ok {
- return ref, "", nil
+ return ref, "<none>", nil
+ }
+ name := named.Name()
+ if name == "" {
+ name = "<none>"
}
tagged, ok := repo.(reference.Tagged)
if !ok {
- return named.Name(), "", nil
+ return name, "<none>", nil
+ }
+ tag := tagged.Tag()
+ if tag == "" {
+ tag = "<none>"
}
- return named.Name(), tagged.Tag(), nil
+ return name, tag, nil
}
diff --git a/cmd/podman/images/save.go b/cmd/podman/images/save.go
index 024045b9d..82a3513f5 100644
--- a/cmd/podman/images/save.go
+++ b/cmd/podman/images/save.go
@@ -5,10 +5,9 @@ import (
"os"
"strings"
- "github.com/containers/podman/v2/libpod/define"
-
"github.com/containers/podman/v2/cmd/podman/parse"
"github.com/containers/podman/v2/cmd/podman/registry"
+ "github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/containers/podman/v2/pkg/util"
"github.com/pkg/errors"
@@ -83,9 +82,10 @@ func saveFlags(flags *pflag.FlagSet) {
}
-func save(cmd *cobra.Command, args []string) error {
+func save(cmd *cobra.Command, args []string) (finalErr error) {
var (
- tags []string
+ tags []string
+ succeeded = false
)
if cmd.Flag("compress").Changed && (saveOpts.Format != define.OCIManifestDir && saveOpts.Format != define.V2s2ManifestDir && saveOpts.Format == "") {
return errors.Errorf("--compress can only be set when --format is either 'oci-dir' or 'docker-dir'")
@@ -95,7 +95,22 @@ func save(cmd *cobra.Command, args []string) error {
if terminal.IsTerminal(int(fi.Fd())) {
return errors.Errorf("refusing to save to terminal. Use -o flag or redirect")
}
- saveOpts.Output = "/dev/stdout"
+ pipePath, cleanup, err := setupPipe()
+ if err != nil {
+ return err
+ }
+ if cleanup != nil {
+ defer func() {
+ errc := cleanup()
+ if succeeded {
+ writeErr := <-errc
+ if writeErr != nil && finalErr == nil {
+ finalErr = writeErr
+ }
+ }
+ }()
+ }
+ saveOpts.Output = pipePath
}
if err := parse.ValidateFileName(saveOpts.Output); err != nil {
return err
@@ -103,5 +118,9 @@ func save(cmd *cobra.Command, args []string) error {
if len(args) > 1 {
tags = args[1:]
}
- return registry.ImageEngine().Save(context.Background(), args[0], tags, saveOpts)
+ err := registry.ImageEngine().Save(context.Background(), args[0], tags, saveOpts)
+ if err == nil {
+ succeeded = true
+ }
+ return err
}
diff --git a/cmd/podman/images/utils_linux.go b/cmd/podman/images/utils_linux.go
new file mode 100644
index 000000000..5521abab4
--- /dev/null
+++ b/cmd/podman/images/utils_linux.go
@@ -0,0 +1,47 @@
+package images
+
+import (
+ "io"
+ "io/ioutil"
+ "os"
+ "path/filepath"
+
+ "github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
+ "golang.org/x/sys/unix"
+)
+
+// setupPipe for fixing https://github.com/containers/podman/issues/7017
+// uses named pipe since containers/image EvalSymlinks fails with /dev/stdout
+// the caller should use the returned function to clean up the pipeDir
+func setupPipe() (string, func() <-chan error, error) {
+ errc := make(chan error)
+ pipeDir, err := ioutil.TempDir(os.TempDir(), "pipeDir")
+ if err != nil {
+ return "", nil, err
+ }
+ pipePath := filepath.Join(pipeDir, "saveio")
+ err = unix.Mkfifo(pipePath, 0600)
+ if err != nil {
+ if e := os.RemoveAll(pipeDir); e != nil {
+ logrus.Errorf("error removing named pipe: %q", e)
+ }
+ return "", nil, errors.Wrapf(err, "error creating named pipe")
+ }
+ go func() {
+ fpipe, err := os.Open(pipePath)
+ if err != nil {
+ errc <- err
+ return
+ }
+ _, err = io.Copy(os.Stdout, fpipe)
+ fpipe.Close()
+ errc <- err
+ }()
+ return pipePath, func() <-chan error {
+ if e := os.RemoveAll(pipeDir); e != nil {
+ logrus.Errorf("error removing named pipe: %q", e)
+ }
+ return errc
+ }, nil
+}
diff --git a/cmd/podman/images/utils_unsupported.go b/cmd/podman/images/utils_unsupported.go
new file mode 100644
index 000000000..69d1df786
--- /dev/null
+++ b/cmd/podman/images/utils_unsupported.go
@@ -0,0 +1,7 @@
+// +build !linux
+
+package images
+
+func setupPipe() (string, func() <-chan error, error) {
+ return "/dev/stdout", nil, nil
+}
diff --git a/cmd/podman/registry/remote.go b/cmd/podman/registry/remote.go
index 7dbdd3824..9b7523ac0 100644
--- a/cmd/podman/registry/remote.go
+++ b/cmd/podman/registry/remote.go
@@ -5,22 +5,24 @@ import (
"sync"
"github.com/containers/podman/v2/pkg/domain/entities"
- "github.com/spf13/cobra"
+ "github.com/spf13/pflag"
)
-var (
- // Was --remote given on command line
- remoteOverride bool
- remoteSync sync.Once
-)
+// Value for --remote given on command line
+var remoteFromCLI = struct {
+ Value bool
+ sync sync.Once
+}{}
-// IsRemote returns true if podman was built to run remote
+// IsRemote returns true if podman was built to run remote or --remote flag given on CLI
// Use in init() functions as a initialization check
func IsRemote() bool {
- remoteSync.Do(func() {
- remote := &cobra.Command{}
- remote.Flags().BoolVarP(&remoteOverride, "remote", "r", false, "")
- _ = remote.ParseFlags(os.Args)
+ remoteFromCLI.sync.Do(func() {
+ fs := pflag.NewFlagSet("remote", pflag.ContinueOnError)
+ fs.BoolVarP(&remoteFromCLI.Value, "remote", "r", false, "")
+ fs.ParseErrorsWhitelist.UnknownFlags = true
+ fs.SetInterspersed(false)
+ _ = fs.Parse(os.Args[1:])
})
- return podmanOptions.EngineMode == entities.TunnelMode || remoteOverride
+ return podmanOptions.EngineMode == entities.TunnelMode || remoteFromCLI.Value
}
diff --git a/cmd/podman/root.go b/cmd/podman/root.go
index 9e9011dc9..dd9c75ece 100644
--- a/cmd/podman/root.go
+++ b/cmd/podman/root.go
@@ -6,7 +6,6 @@ import (
"path"
"runtime"
"runtime/pprof"
- "strconv"
"strings"
"github.com/containers/common/pkg/config"
@@ -112,15 +111,6 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
cfg := registry.PodmanConfig()
- // Validate --remote and --latest not given on same command
- latest := cmd.Flags().Lookup("latest")
- if latest != nil {
- value, _ := strconv.ParseBool(latest.Value.String())
- if cfg.Remote && value {
- return errors.Errorf("For %s \"--remote\" and \"--latest\", are mutually exclusive flags", cmd.CommandPath())
- }
- }
-
// Prep the engines
if _, err := registry.NewImageEngine(cmd, args); err != nil {
return err
@@ -300,6 +290,7 @@ func resolveDestination() (string, string) {
cfg, err := config.ReadCustomConfig()
if err != nil {
+ logrus.Warning(errors.Wrap(err, "unable to read local containers.conf"))
return registry.DefaultAPIAddress(), ""
}
diff --git a/cmd/podman/system/connection/add.go b/cmd/podman/system/connection/add.go
index 89cea10ca..af13b970c 100644
--- a/cmd/podman/system/connection/add.go
+++ b/cmd/podman/system/connection/add.go
@@ -124,6 +124,7 @@ func add(cmd *cobra.Command, args []string) error {
cfg.Engine.ServiceDestinations = map[string]config.Destination{
args[0]: dst,
}
+ cfg.Engine.ActiveService = args[0]
} else {
cfg.Engine.ServiceDestinations[args[0]] = dst
}
@@ -181,12 +182,20 @@ func getUDS(cmd *cobra.Command, uri *url.URL) (string, error) {
authMethods = append(authMethods, ssh.PublicKeysCallback(a.Signers))
}
- config := &ssh.ClientConfig{
+ if len(authMethods) == 0 {
+ pass, err := terminal.ReadPassword(fmt.Sprintf("%s's login password:", uri.User.Username()))
+ if err != nil {
+ return "", err
+ }
+ authMethods = append(authMethods, ssh.Password(string(pass)))
+ }
+
+ cfg := &ssh.ClientConfig{
User: uri.User.Username(),
Auth: authMethods,
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
- dial, err := ssh.Dial("tcp", uri.Host, config)
+ dial, err := ssh.Dial("tcp", uri.Host, cfg)
if err != nil {
return "", errors.Wrapf(err, "failed to connect to %q", uri.Host)
}
diff --git a/cmd/podman/validate/args.go b/cmd/podman/validate/args.go
index a33f47959..aacb41e69 100644
--- a/cmd/podman/validate/args.go
+++ b/cmd/podman/validate/args.go
@@ -4,6 +4,7 @@ import (
"fmt"
"strconv"
+ "github.com/containers/podman/v2/cmd/podman/registry"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@@ -47,17 +48,20 @@ func IDOrLatestArgs(cmd *cobra.Command, args []string) error {
// CheckAllLatestAndCIDFile checks that --all and --latest are used correctly.
// If cidfile is set, also check for the --cidfile flag.
func CheckAllLatestAndCIDFile(c *cobra.Command, args []string, ignoreArgLen bool, cidfile bool) error {
+ var specifiedLatest bool
argLen := len(args)
- if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil {
- if !cidfile {
- return errors.New("unable to lookup values for 'latest' or 'all'")
- } else if c.Flags().Lookup("cidfile") == nil {
- return errors.New("unable to lookup values for 'latest', 'all' or 'cidfile'")
+ if !registry.IsRemote() {
+ specifiedLatest, _ = c.Flags().GetBool("latest")
+ if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil {
+ if !cidfile {
+ return errors.New("unable to lookup values for 'latest' or 'all'")
+ } else if c.Flags().Lookup("cidfile") == nil {
+ return errors.New("unable to lookup values for 'latest', 'all' or 'cidfile'")
+ }
}
}
specifiedAll, _ := c.Flags().GetBool("all")
- specifiedLatest, _ := c.Flags().GetBool("latest")
specifiedCIDFile := false
if cid, _ := c.Flags().GetStringArray("cidfile"); len(cid) > 0 {
specifiedCIDFile = true
@@ -98,17 +102,21 @@ func CheckAllLatestAndCIDFile(c *cobra.Command, args []string, ignoreArgLen bool
// CheckAllLatestAndPodIDFile checks that --all and --latest are used correctly.
// If withIDFile is set, also check for the --pod-id-file flag.
func CheckAllLatestAndPodIDFile(c *cobra.Command, args []string, ignoreArgLen bool, withIDFile bool) error {
+ var specifiedLatest bool
argLen := len(args)
- if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil {
- if !withIDFile {
- return errors.New("unable to lookup values for 'latest' or 'all'")
- } else if c.Flags().Lookup("pod-id-file") == nil {
- return errors.New("unable to lookup values for 'latest', 'all' or 'pod-id-file'")
+ if !registry.IsRemote() {
+ // remote clients have no latest flag
+ specifiedLatest, _ = c.Flags().GetBool("latest")
+ if c.Flags().Lookup("all") == nil || c.Flags().Lookup("latest") == nil {
+ if !withIDFile {
+ return errors.New("unable to lookup values for 'latest' or 'all'")
+ } else if c.Flags().Lookup("pod-id-file") == nil {
+ return errors.New("unable to lookup values for 'latest', 'all' or 'pod-id-file'")
+ }
}
}
specifiedAll, _ := c.Flags().GetBool("all")
- specifiedLatest, _ := c.Flags().GetBool("latest")
specifiedPodIDFile := false
if pid, _ := c.Flags().GetStringArray("pod-id-file"); len(pid) > 0 {
specifiedPodIDFile = true
diff --git a/cmd/podman/validate/latest.go b/cmd/podman/validate/latest.go
index 5c76fe847..c9bff798a 100644
--- a/cmd/podman/validate/latest.go
+++ b/cmd/podman/validate/latest.go
@@ -7,9 +7,8 @@ import (
func AddLatestFlag(cmd *cobra.Command, b *bool) {
// Initialization flag verification
- cmd.Flags().BoolVarP(b, "latest", "l", false,
- "Act on the latest container podman is aware of\nNot supported with the \"--remote\" flag")
- if registry.IsRemote() {
- _ = cmd.Flags().MarkHidden("latest")
+ if !registry.IsRemote() {
+ cmd.Flags().BoolVarP(b, "latest", "l", false,
+ "Act on the latest container podman is aware of\nNot supported with the \"--remote\" flag")
}
}