From a332825ff58de514dd226de58885aa32a778be4f Mon Sep 17 00:00:00 2001 From: baude Date: Wed, 11 Dec 2019 09:16:55 -0600 Subject: allow exec to read files of environment variables we want the ability to define environment variables in files for the exec command. Fixes: #1782408 Signed-off-by: baude --- cmd/podman/cliconfig/config.go | 1 + cmd/podman/exec.go | 2 ++ completions/bash/podman | 1 + docs/source/markdown/podman-exec.1.md | 4 ++++ pkg/adapter/containers.go | 2 +- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/podman/cliconfig/config.go b/cmd/podman/cliconfig/config.go index 431d5e087..e81756808 100644 --- a/cmd/podman/cliconfig/config.go +++ b/cmd/podman/cliconfig/config.go @@ -128,6 +128,7 @@ type ExecValues struct { PodmanCommand DetachKeys string Env []string + EnvFile []string Privileged bool Interactive bool Tty bool diff --git a/cmd/podman/exec.go b/cmd/podman/exec.go index 8dcec24ce..6e5799396 100644 --- a/cmd/podman/exec.go +++ b/cmd/podman/exec.go @@ -40,6 +40,7 @@ func init() { // priority execCommand.DetachKeys = "" flags.StringArrayVarP(&execCommand.Env, "env", "e", []string{}, "Set environment variables") + flags.StringSliceVar(&execCommand.EnvFile, "env-file", []string{}, "Read in a file of environment variables") flags.BoolVarP(&execCommand.Interactive, "interactive", "i", false, "Keep STDIN open even if not attached") flags.BoolVarP(&execCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of") flags.BoolVar(&execCommand.Privileged, "privileged", false, "Give the process extended Linux capabilities inside the container. The default is false") @@ -48,6 +49,7 @@ func init() { flags.IntVar(&execCommand.PreserveFDs, "preserve-fds", 0, "Pass N additional file descriptors to the container") flags.StringVarP(&execCommand.Workdir, "workdir", "w", "", "Working directory inside the container") + markFlagHiddenForRemoteClient("env-file", flags) markFlagHiddenForRemoteClient("latest", flags) markFlagHiddenForRemoteClient("preserve-fds", flags) } diff --git a/completions/bash/podman b/completions/bash/podman index f37b45837..40be0018b 100644 --- a/completions/bash/podman +++ b/completions/bash/podman @@ -1359,6 +1359,7 @@ _podman_exec() { --detach-keys -e --env + --env-file --user -u --workdir diff --git a/docs/source/markdown/podman-exec.1.md b/docs/source/markdown/podman-exec.1.md index 9624425dc..d46427c91 100644 --- a/docs/source/markdown/podman-exec.1.md +++ b/docs/source/markdown/podman-exec.1.md @@ -22,6 +22,10 @@ Specify the key sequence for detaching a container. Format is a single character You may specify arbitrary environment variables that are available for the command to be executed. +**--env-file**=*file* + +Read in a line delimited file of environment variables. + **--interactive**, **-i**=*true|false* When set to true, keep stdin open even if not attached. The default is *false*. diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go index 6d139d0bf..3334e9fa1 100644 --- a/pkg/adapter/containers.go +++ b/pkg/adapter/containers.go @@ -1024,7 +1024,7 @@ func (r *LocalRuntime) ExecContainer(ctx context.Context, cli *cliconfig.ExecVal // Validate given environment variables env := map[string]string{} - if err := parse.ReadKVStrings(env, []string{}, cli.Env); err != nil { + if err := parse.ReadKVStrings(env, cli.EnvFile, cli.Env); err != nil { return ec, errors.Wrapf(err, "unable to process environment variables") } -- cgit v1.2.3-54-g00ecf