summaryrefslogtreecommitdiff
path: root/cmd/podman/common.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/common.go')
-rw-r--r--cmd/podman/common.go105
1 files changed, 20 insertions, 85 deletions
diff --git a/cmd/podman/common.go b/cmd/podman/common.go
index 054b01247..1e9092bd6 100644
--- a/cmd/podman/common.go
+++ b/cmd/podman/common.go
@@ -4,14 +4,13 @@ import (
"context"
"fmt"
"os"
- "path/filepath"
"strings"
"github.com/containers/buildah"
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/cmd/podman/shared"
+ "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/rootless"
- "github.com/containers/storage"
"github.com/fatih/camelcase"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
@@ -19,8 +18,7 @@ import (
)
var (
- stores = make(map[storage.Store]struct{})
- json = jsoniter.ConfigCompatibleWithStandardLibrary
+ json = jsoniter.ConfigCompatibleWithStandardLibrary
)
const (
@@ -80,58 +78,6 @@ func commandRunE() func(*cobra.Command, []string) error {
}
}
-// getAllOrLatestContainers tries to return the correct list of containers
-// depending if --all, --latest or <container-id> is used.
-// It requires the Context (c) and the Runtime (runtime). As different
-// commands are using different container state for the --all option
-// the desired state has to be specified in filterState. If no filter
-// is desired a -1 can be used to get all containers. For a better
-// error message, if the filter fails, a corresponding verb can be
-// specified which will then appear in the error message.
-func getAllOrLatestContainers(c *cliconfig.PodmanCommand, runtime *libpod.Runtime, filterState libpod.ContainerStatus, verb string) ([]*libpod.Container, error) {
- var containers []*libpod.Container
- var lastError error
- var err error
- if c.Bool("all") {
- if filterState != -1 {
- var filterFuncs []libpod.ContainerFilter
- filterFuncs = append(filterFuncs, func(c *libpod.Container) bool {
- state, _ := c.State()
- return state == filterState
- })
- containers, err = runtime.GetContainers(filterFuncs...)
- } else {
- containers, err = runtime.GetContainers()
- }
- if err != nil {
- return nil, errors.Wrapf(err, "unable to get %s containers", verb)
- }
- } else if c.Bool("latest") {
- lastCtr, err := runtime.GetLatestContainer()
- if err != nil {
- return nil, errors.Wrapf(err, "unable to get latest container")
- }
- containers = append(containers, lastCtr)
- } else {
- args := c.InputArgs
- for _, i := range args {
- container, err := runtime.LookupContainer(i)
- if err != nil {
- if lastError != nil {
- fmt.Fprintln(os.Stderr, lastError)
- }
- lastError = errors.Wrapf(err, "unable to find container %s", i)
- }
- if container != nil {
- // This is here to make sure this does not return [<nil>] but only nil
- containers = append(containers, container)
- }
- }
- }
-
- return containers, lastError
-}
-
// getContext returns a non-nil, empty context
func getContext() context.Context {
if Ctx != nil {
@@ -164,7 +110,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"Attach to STDIN, STDOUT or STDERR (default [])",
)
createFlags.String(
- "authfile", getAuthFile(""),
+ "authfile", shared.GetAuthFile(""),
"Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override",
)
createFlags.String(
@@ -184,6 +130,10 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"Drop capabilities from the container",
)
createFlags.String(
+ "cgroupns", "host",
+ "cgroup namespace to use",
+ )
+ createFlags.String(
"cgroup-parent", "",
"Optional parent cgroup for the container",
)
@@ -233,7 +183,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
)
createFlags.String(
"detach-keys", "",
- "Override the key sequence for detaching a container. Format is a single character `[a-Z]` or `ctrl-<value>` where `<value>` is one of: `a-z`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`",
+ "Override the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-<value>`, where `<value>` is one of: `a-z`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`",
)
createFlags.StringSlice(
"device", []string{},
@@ -275,6 +225,9 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"env", "e", []string{},
"Set environment variables in container",
)
+ createFlags.Bool(
+ "env-host", false, "Use all current host environment variables in container",
+ )
createFlags.StringSlice(
"env-file", []string{},
"Read in a file of environment variables",
@@ -295,23 +248,23 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"help", false, "",
)
createFlags.String(
- "healthcheck-command", "",
+ "health-cmd", "",
"set a healthcheck command for the container ('none' disables the existing healthcheck)",
)
createFlags.String(
- "healthcheck-interval", cliconfig.DefaultHealthCheckInterval,
+ "health-interval", cliconfig.DefaultHealthCheckInterval,
"set an interval for the healthchecks (a value of disable results in no automatic timer setup)",
)
createFlags.Uint(
- "healthcheck-retries", cliconfig.DefaultHealthCheckRetries,
+ "health-retries", cliconfig.DefaultHealthCheckRetries,
"the number of retries allowed before a healthcheck is considered to be unhealthy",
)
createFlags.String(
- "healthcheck-start-period", cliconfig.DefaultHealthCheckStartPeriod,
+ "health-start-period", cliconfig.DefaultHealthCheckStartPeriod,
"the initialization time needed for a container to bootstrap",
)
createFlags.String(
- "healthcheck-timeout", cliconfig.DefaultHealthCheckTimeout,
+ "health-timeout", cliconfig.DefaultHealthCheckTimeout,
"the maximum time allowed to complete the healthcheck before an interval is considered failed",
)
createFlags.StringP(
@@ -333,7 +286,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
createFlags.String(
"init-path", "",
// Do not use the Value field for setting the default value to determine user input (i.e., non-empty string)
- fmt.Sprintf("Path to the container-init binary (default: %q)", libpod.DefaultInitPath),
+ fmt.Sprintf("Path to the container-init binary (default: %q)", define.DefaultInitPath),
)
createFlags.BoolP(
"interactive", "i", false,
@@ -472,7 +425,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"Signal to stop a container. Default is SIGTERM",
)
createFlags.Uint(
- "stop-timeout", libpod.CtrRemoveTimeout,
+ "stop-timeout", define.CtrRemoveTimeout,
"Timeout (in seconds) to stop a container. Default is 10",
)
createFlags.StringSlice(
@@ -496,7 +449,7 @@ func getCreateFlags(c *cliconfig.PodmanCommand) {
"systemd", cliconfig.DefaultSystemD,
"Run container in systemd mode if the command executable is systemd or init",
)
- createFlags.StringSlice(
+ createFlags.StringArray(
"tmpfs", []string{},
"Mount a temporary filesystem (`tmpfs`) into a container (default [])",
)
@@ -554,24 +507,6 @@ func getFormat(c *cliconfig.PodmanCommand) (string, error) {
return "", errors.Errorf("unrecognized image type %q", format)
}
-func getAuthFile(authfile string) string {
- if authfile != "" {
- return authfile
- }
- if remote {
- return ""
- }
- authfile = os.Getenv("REGISTRY_AUTH_FILE")
- if authfile != "" {
- return authfile
- }
- runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
- if runtimeDir != "" {
- return filepath.Join(runtimeDir, "containers/auth.json")
- }
- return ""
-}
-
// scrubServer removes 'http://' or 'https://' from the front of the
// server/registry string if either is there. This will be mostly used
// for user input from 'podman login' and 'podman logout'.