summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/auto-update.go46
-rw-r--r--cmd/podman/containers/runlabel.go80
-rw-r--r--cmd/podman/pods/create.go47
3 files changed, 150 insertions, 23 deletions
diff --git a/cmd/podman/auto-update.go b/cmd/podman/auto-update.go
new file mode 100644
index 000000000..758cbbc6f
--- /dev/null
+++ b/cmd/podman/auto-update.go
@@ -0,0 +1,46 @@
+package main
+
+import (
+ "fmt"
+
+ "github.com/containers/libpod/cmd/podman/registry"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/containers/libpod/pkg/errorhandling"
+ "github.com/pkg/errors"
+ "github.com/spf13/cobra"
+)
+
+var (
+ autoUpdateDescription = `Auto update containers according to their auto-update policy.
+
+ Auto-update policies are specified with the "io.containers.autoupdate" label.
+ Note that this command is experimental.`
+ autoUpdateCommand = &cobra.Command{
+ Use: "auto-update [flags]",
+ Short: "Auto update containers according to their auto-update policy",
+ Long: autoUpdateDescription,
+ RunE: autoUpdate,
+ Example: `podman auto-update`,
+ }
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode},
+ Command: autoUpdateCommand,
+ })
+}
+
+func autoUpdate(cmd *cobra.Command, args []string) error {
+ if len(args) > 0 {
+ // Backwards compat. System tests expext this error string.
+ return errors.Errorf("`%s` takes no arguments", cmd.CommandPath())
+ }
+ report, failures := registry.ContainerEngine().AutoUpdate(registry.GetContext())
+ if report != nil {
+ for _, unit := range report.Units {
+ fmt.Println(unit)
+ }
+ }
+ return errorhandling.JoinErrors(failures)
+}
diff --git a/cmd/podman/containers/runlabel.go b/cmd/podman/containers/runlabel.go
new file mode 100644
index 000000000..11fa362b8
--- /dev/null
+++ b/cmd/podman/containers/runlabel.go
@@ -0,0 +1,80 @@
+package containers
+
+import (
+ "context"
+ "os"
+
+ "github.com/containers/common/pkg/auth"
+ "github.com/containers/image/v5/types"
+ "github.com/containers/libpod/cmd/podman/registry"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/cobra"
+)
+
+// runlabelOptionsWrapper allows for combining API-only with CLI-only options
+// and to convert between them.
+type runlabelOptionsWrapper struct {
+ entities.ContainerRunlabelOptions
+ TLSVerifyCLI bool
+}
+
+var (
+ runlabelOptions = runlabelOptionsWrapper{}
+ runlabelDescription = "Executes a command as described by a container image label."
+ runlabelCommand = &cobra.Command{
+ Use: "runlabel [flags] LABEL IMAGE [ARG...]",
+ Short: "Execute the command described by an image label",
+ Long: runlabelDescription,
+ RunE: runlabel,
+ Args: cobra.MinimumNArgs(2),
+ Example: `podman container runlabel run imageID
+ podman container runlabel --pull install imageID arg1 arg2
+ podman container runlabel --display run myImage`,
+ }
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode},
+ Command: runlabelCommand,
+ Parent: containerCmd,
+ })
+
+ flags := rmCommand.Flags()
+ flags.StringVar(&runlabelOptions.Authfile, "authfile", auth.GetDefaultAuthFile(), "Path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
+ flags.StringVar(&runlabelOptions.CertDir, "cert-dir", "", "`Pathname` of a directory containing TLS certificates and keys")
+ flags.StringVar(&runlabelOptions.Credentials, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry")
+ flags.BoolVar(&runlabelOptions.Display, "display", false, "Preview the command that the label would run")
+ flags.StringVarP(&runlabelOptions.Name, "name", "n", "", "Assign a name to the container")
+ flags.StringVar(&runlabelOptions.Optional1, "opt1", "", "Optional parameter to pass for install")
+ flags.StringVar(&runlabelOptions.Optional2, "opt2", "", "Optional parameter to pass for install")
+ flags.StringVar(&runlabelOptions.Optional3, "opt3", "", "Optional parameter to pass for install")
+ flags.BoolP("pull", "p", false, "Pull the image if it does not exist locally prior to executing the label contents")
+ flags.BoolVarP(&runlabelOptions.Quiet, "quiet", "q", false, "Suppress output information when installing images")
+ flags.BoolVar(&runlabelOptions.Replace, "replace", false, "Replace existing container with a new one from the image")
+ flags.StringVar(&runlabelOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)")
+ flags.BoolVar(&runlabelOptions.TLSVerifyCLI, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries")
+
+ // Hide the optional flags.
+ _ = flags.MarkHidden("opt1")
+ _ = flags.MarkHidden("opt2")
+ _ = flags.MarkHidden("opt3")
+
+ if err := flags.MarkDeprecated("pull", "podman will pull if not found in local storage"); err != nil {
+ logrus.Error("unable to mark pull flag deprecated")
+ }
+}
+
+func runlabel(cmd *cobra.Command, args []string) error {
+ if cmd.Flags().Changed("tls-verify") {
+ runlabelOptions.SkipTLSVerify = types.NewOptionalBool(!runlabelOptions.TLSVerifyCLI)
+ }
+ if runlabelOptions.Authfile != "" {
+ if _, err := os.Stat(runlabelOptions.Authfile); err != nil {
+ return errors.Wrapf(err, "error getting authfile %s", runlabelOptions.Authfile)
+ }
+ }
+ return registry.ContainerEngine().ContainerRunlabel(context.Background(), args[0], args[1], args[2:], runlabelOptions.ContainerRunlabelOptions)
+}
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index 0a2016496..f97fa836a 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -17,6 +17,7 @@ import (
"github.com/containers/libpod/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"
+ "github.com/spf13/pflag"
)
var (
@@ -59,6 +60,14 @@ func init() {
flags.StringVarP(&createOptions.Hostname, "hostname", "", "", "Set a hostname to the pod")
flags.StringVar(&podIDFile, "pod-id-file", "", "Write the pod ID to the file")
flags.StringVar(&share, "share", createconfig.DefaultKernelNamespaces, "A comma delimited list of kernel namespaces the pod will share")
+ flags.SetNormalizeFunc(aliasNetworkFlag)
+}
+
+func aliasNetworkFlag(_ *pflag.FlagSet, name string) pflag.NormalizedName {
+ if name == "net" {
+ name = "network"
+ }
+ return pflag.NormalizedName(name)
}
func create(cmd *cobra.Command, args []string) error {
@@ -105,29 +114,21 @@ func create(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
- netInput, err := cmd.Flags().GetString("network")
- if err != nil {
- return err
- }
- n := specgen.Namespace{}
- switch netInput {
- case "bridge":
- n.NSMode = specgen.Bridge
- case "host":
- n.NSMode = specgen.Host
- case "slip4netns":
- n.NSMode = specgen.Slirp
- default:
- if strings.HasPrefix(netInput, "container:") { // nolint
- split := strings.Split(netInput, ":")
- if len(split) != 2 {
- return errors.Errorf("invalid network paramater: %q", netInput)
- }
- n.NSMode = specgen.FromContainer
- n.Value = split[1]
- } else if strings.HasPrefix(netInput, "ns:") {
- return errors.New("the ns: network option is not supported for pods")
- } else {
+ if cmd.Flag("network").Changed {
+ netInput, err := cmd.Flags().GetString("network")
+ if err != nil {
+ return err
+ }
+ n := specgen.Namespace{}
+ switch netInput {
+ case "bridge":
+ n.NSMode = specgen.Bridge
+ case "host":
+ n.NSMode = specgen.Host
+ case "slirp4netns":
+ n.NSMode = specgen.Slirp
+ default:
+ // Container and NS mode are presently unsupported
n.NSMode = specgen.Bridge
createOptions.Net.CNINetworks = strings.Split(netInput, ",")
}