diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/common/create.go | 7 | ||||
-rw-r--r-- | cmd/podman/common/create_opts.go | 1 | ||||
-rw-r--r-- | cmd/podman/common/specgen.go | 29 | ||||
-rw-r--r-- | cmd/podman/containers/create.go | 12 | ||||
-rw-r--r-- | cmd/podman/containers/run.go | 3 | ||||
-rw-r--r-- | cmd/podman/generate/systemd.go | 71 | ||||
-rw-r--r-- | cmd/podman/images/pull.go | 1 | ||||
-rw-r--r-- | cmd/podman/root.go | 2 |
8 files changed, 88 insertions, 38 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index d0bc8d466..2b6f9348e 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -323,13 +323,16 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet { "override-arch", "", "use `ARCH` instead of the architecture of the machine for choosing images", ) - // markFlagHidden(createFlags, "override-arch") createFlags.StringVar( &cf.OverrideOS, "override-os", "", "use `OS` instead of the running OS for choosing images", ) - // markFlagHidden(createFlags, "override-os") + createFlags.StringVar( + &cf.OverrideVariant, + "override-variant", "", + "Use _VARIANT_ instead of the running architecture variant for choosing images", + ) createFlags.String( "pid", "", "PID namespace to use", diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go index 16d41988f..1b0e64590 100644 --- a/cmd/podman/common/create_opts.go +++ b/cmd/podman/common/create_opts.go @@ -65,6 +65,7 @@ type ContainerCLIOpts struct { OOMScoreAdj int OverrideArch string OverrideOS string + OverrideVariant string PID string PIDsLimit *int64 Pod string diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go index 4de622916..e7b88eb3f 100644 --- a/cmd/podman/common/specgen.go +++ b/cmd/podman/common/specgen.go @@ -307,10 +307,11 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string // ENVIRONMENT VARIABLES // // Precedence order (higher index wins): - // 1) env-host, 2) image data, 3) env-file, 4) env - env := map[string]string{ - "container": "podman", - } + // 1) containers.conf (EnvHost, EnvHTTP, Env) 2) image data, 3 User EnvHost/EnvHTTP, 4) env-file, 5) env + // containers.conf handled and image data handled on the server side + // user specified EnvHost and EnvHTTP handled on Server Side relative to Server + // env-file and env handled on client side + var env map[string]string // First transform the os env into a map. We need it for the labels later in // any case. @@ -319,24 +320,8 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string return errors.Wrap(err, "error parsing host environment variables") } - if c.EnvHost { - env = envLib.Join(env, osEnv) - } else if c.HTTPProxy { - for _, envSpec := range []string{ - "http_proxy", - "HTTP_PROXY", - "https_proxy", - "HTTPS_PROXY", - "ftp_proxy", - "FTP_PROXY", - "no_proxy", - "NO_PROXY", - } { - if v, ok := osEnv[envSpec]; ok { - env[envSpec] = v - } - } - } + s.EnvHost = c.EnvHost + s.HTTPProxy = c.HTTPProxy // env-file overrides any previous variables for _, f := range c.EnvFile { diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index 801547033..5e48aa622 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -66,9 +66,6 @@ func createFlags(flags *pflag.FlagSet) { _ = flags.MarkHidden("env-host") _ = flags.MarkHidden("http-proxy") } - // Not sure we want these exposed yet. If we do, they need to be documented in man pages - _ = flags.MarkHidden("override-arch") - _ = flags.MarkHidden("override-os") } func init() { @@ -254,10 +251,11 @@ func pullImage(imageName string) (string, error) { return "", errors.Wrapf(define.ErrNoSuchImage, "unable to find a name and tag match for %s in repotags", imageName) } pullReport, pullErr := registry.ImageEngine().Pull(registry.GetContext(), imageName, entities.ImagePullOptions{ - Authfile: cliVals.Authfile, - Quiet: cliVals.Quiet, - OverrideArch: cliVals.OverrideArch, - OverrideOS: cliVals.OverrideOS, + Authfile: cliVals.Authfile, + Quiet: cliVals.Quiet, + OverrideArch: cliVals.OverrideArch, + OverrideOS: cliVals.OverrideOS, + OverrideVariant: cliVals.OverrideVariant, }) if pullErr != nil { return "", pullErr diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go index a84cb6814..34eea14e1 100644 --- a/cmd/podman/containers/run.go +++ b/cmd/podman/containers/run.go @@ -70,9 +70,6 @@ func runFlags(flags *pflag.FlagSet) { _ = flags.MarkHidden("http-proxy") _ = flags.MarkHidden("preserve-fds") } - // Not sure we want these exposed yet. If we do, they need to be documented in man pages - _ = flags.MarkHidden("override-arch") - _ = flags.MarkHidden("override-os") } func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ diff --git a/cmd/podman/generate/systemd.go b/cmd/podman/generate/systemd.go index 851a104bc..f690836a4 100644 --- a/cmd/podman/generate/systemd.go +++ b/cmd/podman/generate/systemd.go @@ -1,15 +1,22 @@ package pods import ( + "encoding/json" "fmt" + "os" + "path/filepath" "github.com/containers/podman/v2/cmd/podman/registry" "github.com/containers/podman/v2/cmd/podman/utils" "github.com/containers/podman/v2/pkg/domain/entities" + "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) var ( + files bool + format string systemdTimeout uint systemdOptions = entities.GenerateSystemdOptions{} systemdDescription = `Generate systemd units for a pod or container. @@ -29,19 +36,20 @@ var ( func init() { registry.Commands = append(registry.Commands, registry.CliCommand{ - Mode: []entities.EngineMode{entities.ABIMode}, + Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode}, Command: systemdCmd, Parent: generateCmd, }) flags := systemdCmd.Flags() flags.BoolVarP(&systemdOptions.Name, "name", "n", false, "Use container/pod names instead of IDs") - flags.BoolVarP(&systemdOptions.Files, "files", "f", false, "Generate .service files instead of printing to stdout") + flags.BoolVarP(&files, "files", "f", false, "Generate .service files instead of printing to stdout") flags.UintVarP(&systemdTimeout, "time", "t", containerConfig.Engine.StopTimeout, "Stop timeout override") flags.StringVar(&systemdOptions.RestartPolicy, "restart-policy", "on-failure", "Systemd restart-policy") flags.BoolVarP(&systemdOptions.New, "new", "", false, "Create a new container instead of starting an existing one") flags.StringVar(&systemdOptions.ContainerPrefix, "container-prefix", "container", "Systemd unit name prefix for containers") flags.StringVar(&systemdOptions.PodPrefix, "pod-prefix", "pod", "Systemd unit name prefix for pods") flags.StringVar(&systemdOptions.Separator, "separator", "-", "Systemd unit name separator between name/id and prefix") + flags.StringVar(&format, "format", "", "Print the created units in specified format (json)") flags.SetNormalizeFunc(utils.AliasFlags) } @@ -50,11 +58,68 @@ func systemd(cmd *cobra.Command, args []string) error { systemdOptions.StopTimeout = &systemdTimeout } + if registry.IsRemote() { + logrus.Warnln("The generated units should be placed on your remote system") + } + report, err := registry.ContainerEngine().GenerateSystemd(registry.GetContext(), args[0], systemdOptions) if err != nil { return err } - fmt.Println(report.Output) + if files { + cwd, err := os.Getwd() + if err != nil { + return errors.Wrap(err, "error getting current working directory") + } + for name, content := range report.Units { + path := filepath.Join(cwd, fmt.Sprintf("%s.service", name)) + f, err := os.Create(path) + if err != nil { + return err + } + _, err = f.WriteString(content) + if err != nil { + return err + } + err = f.Close() + if err != nil { + return err + } + + // add newline if default format is given + if format == "" { + path += "\n" + } + // modify in place so we can print the + // paths when --files is set + report.Units[name] = path + } + } + + switch format { + case "json": + return printJSON(report.Units) + case "": + return printDefault(report.Units) + default: + return errors.Errorf("unknown --format argument: %s", format) + } + +} + +func printDefault(units map[string]string) error { + for _, content := range units { + fmt.Print(content) + } + return nil +} + +func printJSON(units map[string]string) error { + b, err := json.MarshalIndent(units, "", " ") + if err != nil { + return err + } + fmt.Println(string(b)) return nil } diff --git a/cmd/podman/images/pull.go b/cmd/podman/images/pull.go index 4deaecbf5..d86f9800c 100644 --- a/cmd/podman/images/pull.go +++ b/cmd/podman/images/pull.go @@ -82,6 +82,7 @@ func pullFlags(flags *pflag.FlagSet) { flags.StringVar(&pullOptions.CredentialsCLI, "creds", "", "`Credentials` (USERNAME:PASSWORD) to use for authenticating to a registry") flags.StringVar(&pullOptions.OverrideArch, "override-arch", "", "Use `ARCH` instead of the architecture of the machine for choosing images") flags.StringVar(&pullOptions.OverrideOS, "override-os", "", "Use `OS` instead of the running OS for choosing images") + flags.StringVar(&pullOptions.OverrideVariant, "override-variant", "", " use VARIANT instead of the running architecture variant for choosing images") flags.Bool("disable-content-trust", false, "This is a Docker specific option and is a NOOP") flags.BoolVarP(&pullOptions.Quiet, "quiet", "q", false, "Suppress output information when pulling images") flags.StringVar(&pullOptions.SignaturePolicy, "signature-policy", "", "`Pathname` of signature policy file (not usually used)") diff --git a/cmd/podman/root.go b/cmd/podman/root.go index 8f77e5893..749a5fbe7 100644 --- a/cmd/podman/root.go +++ b/cmd/podman/root.go @@ -226,7 +226,7 @@ func persistentPostRunE(cmd *cobra.Command, args []string) error { func loggingHook() { var found bool for _, l := range logLevels { - if l == logLevel { + if l == strings.ToLower(logLevel) { found = true break } |