diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/common/create.go | 28 | ||||
-rw-r--r-- | cmd/podman/common/create_opts.go | 19 | ||||
-rw-r--r-- | cmd/podman/common/specgen.go | 2 | ||||
-rw-r--r-- | cmd/podman/containers/create.go | 27 | ||||
-rw-r--r-- | cmd/podman/containers/rm.go | 15 | ||||
-rw-r--r-- | cmd/podman/images/build.go | 8 | ||||
-rw-r--r-- | cmd/podman/images/pull.go | 28 | ||||
-rw-r--r-- | cmd/podman/manifest/add.go | 4 | ||||
-rw-r--r-- | cmd/podman/manifest/annotate.go | 4 | ||||
-rw-r--r-- | cmd/podman/manifest/exists.go | 39 | ||||
-rw-r--r-- | cmd/podman/utils/alias.go | 6 | ||||
-rw-r--r-- | cmd/podman/volumes/exists.go | 40 |
12 files changed, 163 insertions, 57 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index 280175f95..915ff63b6 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -402,7 +402,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) { logDriverFlagName := "log-driver" createFlags.StringVar( &cf.LogDriver, - logDriverFlagName, "", + logDriverFlagName, logDriver(), "Logging driver for the container", ) _ = cmd.RegisterFlagCompletionFunc(logDriverFlagName, AutocompleteLogDriver) @@ -474,29 +474,29 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) { ) _ = cmd.RegisterFlagCompletionFunc(oomScoreAdjFlagName, completion.AutocompleteNone) - overrideArchFlagName := "override-arch" + archFlagName := "arch" createFlags.StringVar( - &cf.OverrideArch, - overrideArchFlagName, "", + &cf.Arch, + archFlagName, "", "use `ARCH` instead of the architecture of the machine for choosing images", ) - _ = cmd.RegisterFlagCompletionFunc(overrideArchFlagName, completion.AutocompleteNone) + _ = cmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteArch) - overrideOSFlagName := "override-os" + osFlagName := "os" createFlags.StringVar( - &cf.OverrideOS, - overrideOSFlagName, "", + &cf.OS, + osFlagName, "", "use `OS` instead of the running OS for choosing images", ) - _ = cmd.RegisterFlagCompletionFunc(overrideOSFlagName, completion.AutocompleteNone) + _ = cmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteOS) - overrideVariantFlagName := "override-variant" + variantFlagName := "variant" createFlags.StringVar( - &cf.OverrideVariant, - overrideVariantFlagName, "", + &cf.Variant, + variantFlagName, "", "Use _VARIANT_ instead of the running architecture variant for choosing images", ) - _ = cmd.RegisterFlagCompletionFunc(overrideVariantFlagName, completion.AutocompleteNone) + _ = cmd.RegisterFlagCompletionFunc(variantFlagName, completion.AutocompleteNone) pidFlagName := "pid" createFlags.String( @@ -516,7 +516,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) { createFlags.StringVar( &cf.Platform, platformFlagName, "", - "Specify the platform for selecting the image. (Conflicts with override-arch and override-os)", + "Specify the platform for selecting the image. (Conflicts with --arch and --os)", ) _ = cmd.RegisterFlagCompletionFunc(platformFlagName, completion.AutocompleteNone) diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go index 9635f4135..a4da8da9e 100644 --- a/cmd/podman/common/create_opts.go +++ b/cmd/podman/common/create_opts.go @@ -73,9 +73,9 @@ type ContainerCLIOpts struct { NoHealthCheck bool OOMKillDisable bool OOMScoreAdj int - OverrideArch string - OverrideOS string - OverrideVariant string + Arch string + OS string + Variant string PID string PIDsLimit *int64 Platform string @@ -346,9 +346,9 @@ func ContainerCreateToContainerCLIOpts(cc handlers.CreateContainerConfig, cgroup LogOptions: stringMaptoArray(cc.HostConfig.LogConfig.Config), Name: cc.Name, OOMScoreAdj: cc.HostConfig.OomScoreAdj, - OverrideArch: "", - OverrideOS: "", - OverrideVariant: "", + Arch: "", + OS: "", + Variant: "", PID: string(cc.HostConfig.PidMode), PIDsLimit: cc.HostConfig.PidsLimit, Privileged: cc.HostConfig.Privileged, @@ -517,3 +517,10 @@ func volumes() []string { } return nil } + +func logDriver() string { + if !registry.IsRemote() { + return containerConfig.Containers.LogDriver + } + return "" +} diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go index 287836d9f..4cc53a630 100644 --- a/cmd/podman/common/specgen.go +++ b/cmd/podman/common/specgen.go @@ -463,7 +463,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string if s.LogConfiguration == nil { s.LogConfiguration = &specgen.LogConfig{} } - s.LogConfiguration.Driver = define.KubernetesLogging + if ld := c.LogDriver; len(ld) > 0 { s.LogConfiguration.Driver = ld } diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index 420813ba9..5c6c773eb 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -237,17 +237,20 @@ func pullImage(imageName string) (string, error) { imageMissing = !br.Value } - if cliVals.Platform != "" { - if cliVals.OverrideArch != "" || cliVals.OverrideOS != "" { - return "", errors.Errorf("--platform option can not be specified with --override-arch or --override-os") - } - split := strings.SplitN(cliVals.Platform, "/", 2) - cliVals.OverrideOS = split[0] - if len(split) > 1 { - cliVals.OverrideArch = split[1] + if cliVals.Platform != "" || cliVals.Arch != "" || cliVals.OS != "" { + if cliVals.Platform != "" { + if cliVals.Arch != "" || cliVals.OS != "" { + return "", errors.Errorf("--platform option can not be specified with --arch or --os") + } + split := strings.SplitN(cliVals.Platform, "/", 2) + cliVals.OS = split[0] + if len(split) > 1 { + cliVals.Arch = split[1] + } } + if pullPolicy != config.PullImageAlways { - logrus.Info("--platform causes the pull policy to be \"always\"") + logrus.Info("--platform --arch and --os causes the pull policy to be \"always\"") pullPolicy = config.PullImageAlways } } @@ -259,9 +262,9 @@ func pullImage(imageName string) (string, error) { pullReport, pullErr := registry.ImageEngine().Pull(registry.GetContext(), imageName, entities.ImagePullOptions{ Authfile: cliVals.Authfile, Quiet: cliVals.Quiet, - OverrideArch: cliVals.OverrideArch, - OverrideOS: cliVals.OverrideOS, - OverrideVariant: cliVals.OverrideVariant, + Arch: cliVals.Arch, + OS: cliVals.OS, + Variant: cliVals.Variant, SignaturePolicy: cliVals.SignaturePolicy, PullPolicy: pullPolicy, }) diff --git a/cmd/podman/containers/rm.go b/cmd/podman/containers/rm.go index ee9dc4c78..ea616b6e5 100644 --- a/cmd/podman/containers/rm.go +++ b/cmd/podman/containers/rm.go @@ -3,6 +3,7 @@ package containers import ( "context" "fmt" + "io/ioutil" "strings" "github.com/containers/common/pkg/completion" @@ -54,6 +55,7 @@ var ( var ( rmOptions = entities.RmOptions{} + cidFiles = []string{} ) func rmFlags(cmd *cobra.Command) { @@ -65,7 +67,7 @@ func rmFlags(cmd *cobra.Command) { flags.BoolVarP(&rmOptions.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container") cidfileFlagName := "cidfile" - flags.StringArrayVarP(&rmOptions.CIDFiles, cidfileFlagName, "", nil, "Read the container ID from the file") + flags.StringArrayVar(&cidFiles, cidfileFlagName, nil, "Read the container ID from the file") _ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault) if !registry.IsRemote() { @@ -92,7 +94,16 @@ func init() { validate.AddLatestFlag(containerRmCommand, &rmOptions.Latest) } -func rm(_ *cobra.Command, args []string) error { +func rm(cmd *cobra.Command, args []string) error { + for _, cidFile := range cidFiles { + content, err := ioutil.ReadFile(string(cidFile)) + if err != nil { + return errors.Wrap(err, "error reading CIDFile") + } + id := strings.Split(string(content), "\n")[0] + args = append(args, id) + } + return removeContainers(args, rmOptions, true) } diff --git a/cmd/podman/images/build.go b/cmd/podman/images/build.go index 1029e03d1..4219e325b 100644 --- a/cmd/podman/images/build.go +++ b/cmd/podman/images/build.go @@ -423,10 +423,10 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil Ulimit: flags.Ulimit, Volumes: flags.Volumes, }, - Compression: compression, - ConfigureNetwork: networkPolicy, - ContextDirectory: contextDir, - // DefaultMountsFilePath: FIXME: this requires global flags to be working! + Compression: compression, + ConfigureNetwork: networkPolicy, + ContextDirectory: contextDir, + DefaultMountsFilePath: containerConfig.Containers.DefaultMountsFile, Devices: flags.Devices, DropCapabilities: flags.CapDrop, Err: stderr, diff --git a/cmd/podman/images/pull.go b/cmd/podman/images/pull.go index 2d881a906..fe92baebe 100644 --- a/cmd/podman/images/pull.go +++ b/cmd/podman/images/pull.go @@ -84,20 +84,20 @@ func pullFlags(cmd *cobra.Command) { flags.StringVar(&pullOptions.CredentialsCLI, credsFlagName, "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") _ = cmd.RegisterFlagCompletionFunc(credsFlagName, completion.AutocompleteNone) - overrideArchFlagName := "override-arch" - flags.StringVar(&pullOptions.OverrideArch, overrideArchFlagName, "", "Use `ARCH` instead of the architecture of the machine for choosing images") - _ = cmd.RegisterFlagCompletionFunc(overrideArchFlagName, completion.AutocompleteNone) + archFlagName := "arch" + flags.StringVar(&pullOptions.Arch, archFlagName, "", "Use `ARCH` instead of the architecture of the machine for choosing images") + _ = cmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteArch) - overrideOsFlagName := "override-os" - flags.StringVar(&pullOptions.OverrideOS, overrideOsFlagName, "", "Use `OS` instead of the running OS for choosing images") - _ = cmd.RegisterFlagCompletionFunc(overrideOsFlagName, completion.AutocompleteNone) + osFlagName := "os" + flags.StringVar(&pullOptions.OS, osFlagName, "", "Use `OS` instead of the running OS for choosing images") + _ = cmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteOS) - overrideVariantFlagName := "override-variant" - flags.StringVar(&pullOptions.OverrideVariant, overrideVariantFlagName, "", " use VARIANT instead of the running architecture variant for choosing images") - _ = cmd.RegisterFlagCompletionFunc(overrideVariantFlagName, completion.AutocompleteNone) + variantFlagName := "variant" + flags.StringVar(&pullOptions.Variant, variantFlagName, "", " use VARIANT instead of the running architecture variant for choosing images") + _ = cmd.RegisterFlagCompletionFunc(variantFlagName, completion.AutocompleteNone) platformFlagName := "platform" - flags.String(platformFlagName, "", "Specify the platform for selecting the image. (Conflicts with override-arch and override-os)") + flags.String(platformFlagName, "", "Specify the platform for selecting the image. (Conflicts with arch and os)") _ = cmd.RegisterFlagCompletionFunc(platformFlagName, completion.AutocompleteNone) flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP") @@ -138,13 +138,13 @@ func imagePull(cmd *cobra.Command, args []string) error { return err } if platform != "" { - if pullOptions.OverrideArch != "" || pullOptions.OverrideOS != "" { - return errors.Errorf("--platform option can not be specified with --override-arch or --override-os") + if pullOptions.Arch != "" || pullOptions.OS != "" { + return errors.Errorf("--platform option can not be specified with --arch or --os") } split := strings.SplitN(platform, "/", 2) - pullOptions.OverrideOS = split[0] + pullOptions.OS = split[0] if len(split) > 1 { - pullOptions.OverrideArch = split[1] + pullOptions.Arch = split[1] } } diff --git a/cmd/podman/manifest/add.go b/cmd/podman/manifest/add.go index cb0838eeb..b33f01c10 100644 --- a/cmd/podman/manifest/add.go +++ b/cmd/podman/manifest/add.go @@ -52,7 +52,7 @@ func init() { archFlagName := "arch" flags.StringVar(&manifestAddOpts.Arch, archFlagName, "", "override the `architecture` of the specified image") - _ = addCmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteNone) + _ = addCmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteArch) authfileFlagName := "authfile" flags.StringVar(&manifestAddOpts.Authfile, authfileFlagName, auth.GetDefaultAuthFile(), "path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override") @@ -72,7 +72,7 @@ func init() { osFlagName := "os" flags.StringVar(&manifestAddOpts.OS, osFlagName, "", "override the `OS` of the specified image") - _ = addCmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteNone) + _ = addCmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteOS) osVersionFlagName := "os-version" flags.StringVar(&manifestAddOpts.OSVersion, osVersionFlagName, "", "override the OS `version` of the specified image") diff --git a/cmd/podman/manifest/annotate.go b/cmd/podman/manifest/annotate.go index 71017e0ec..7c4f5ad01 100644 --- a/cmd/podman/manifest/annotate.go +++ b/cmd/podman/manifest/annotate.go @@ -39,7 +39,7 @@ func init() { archFlagName := "arch" flags.StringVar(&manifestAnnotateOpts.Arch, archFlagName, "", "override the `architecture` of the specified image") - _ = annotateCmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteNone) + _ = annotateCmd.RegisterFlagCompletionFunc(archFlagName, completion.AutocompleteArch) featuresFlagName := "features" flags.StringSliceVar(&manifestAnnotateOpts.Features, featuresFlagName, nil, "override the `features` of the specified image") @@ -47,7 +47,7 @@ func init() { osFlagName := "os" flags.StringVar(&manifestAnnotateOpts.OS, osFlagName, "", "override the `OS` of the specified image") - _ = annotateCmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteNone) + _ = annotateCmd.RegisterFlagCompletionFunc(osFlagName, completion.AutocompleteOS) osFeaturesFlagName := "os-features" flags.StringSliceVar(&manifestAnnotateOpts.OSFeatures, osFeaturesFlagName, nil, "override the OS `features` of the specified image") diff --git a/cmd/podman/manifest/exists.go b/cmd/podman/manifest/exists.go new file mode 100644 index 000000000..14e01edab --- /dev/null +++ b/cmd/podman/manifest/exists.go @@ -0,0 +1,39 @@ +package manifest + +import ( + "github.com/containers/podman/v2/cmd/podman/common" + "github.com/containers/podman/v2/cmd/podman/registry" + "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/spf13/cobra" +) + +var ( + existsCmd = &cobra.Command{ + Use: "exists MANIFEST", + Short: "Check if a manifest list exists in local storage", + Long: `If the manifest list exists in local storage, podman manifest exists exits with 0, otherwise the exit code will be 1.`, + Args: cobra.ExactArgs(1), + RunE: exists, + ValidArgsFunction: common.AutocompleteImages, + Example: "podman manifest exists mylist", + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, + Command: existsCmd, + Parent: manifestCmd, + }) +} + +func exists(cmd *cobra.Command, args []string) error { + found, err := registry.ImageEngine().ManifestExists(registry.GetContext(), args[0]) + if err != nil { + return err + } + if !found.Value { + registry.SetExitCode(1) + } + return nil +} diff --git a/cmd/podman/utils/alias.go b/cmd/podman/utils/alias.go index 469233b59..8d089920b 100644 --- a/cmd/podman/utils/alias.go +++ b/cmd/podman/utils/alias.go @@ -25,6 +25,12 @@ func AliasFlags(f *pflag.FlagSet, name string) pflag.NormalizedName { name = "external" case "purge": name = "rm" + case "override-arch": + name = "arch" + case "override-os": + name = "os" + case "override-variant": + name = "variant" } return pflag.NormalizedName(name) } diff --git a/cmd/podman/volumes/exists.go b/cmd/podman/volumes/exists.go new file mode 100644 index 000000000..71cd117ae --- /dev/null +++ b/cmd/podman/volumes/exists.go @@ -0,0 +1,40 @@ +package volumes + +import ( + "github.com/containers/podman/v2/cmd/podman/common" + "github.com/containers/podman/v2/cmd/podman/registry" + "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/spf13/cobra" +) + +var ( + volumeExistsDescription = `If the given volume exists, podman volume exists exits with 0, otherwise the exit code will be 1.` + volumeExistsCommand = &cobra.Command{ + Use: "exists VOLUME", + Short: "volume exists", + Long: volumeExistsDescription, + RunE: volumeExists, + Example: `podman volume exists myvol`, + Args: cobra.ExactArgs(1), + ValidArgsFunction: common.AutocompleteVolumes, + } +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, + Command: volumeExistsCommand, + Parent: volumeCmd, + }) +} + +func volumeExists(cmd *cobra.Command, args []string) error { + response, err := registry.ContainerEngine().VolumeExists(registry.GetContext(), args[0]) + if err != nil { + return err + } + if !response.Value { + registry.SetExitCode(1) + } + return nil +} |