summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2020-05-06 13:20:44 +0200
committerDaniel J Walsh <dwalsh@redhat.com>2020-05-07 14:16:50 -0400
commit99bdafba999078bb5763c65cf7dfe7df520030f7 (patch)
tree916c768fca45b5e809f9e941b5425e760dcfe08c /cmd
parent1d3cdf9a4642df073becb54d178d6b1959526a47 (diff)
downloadpodman-99bdafba999078bb5763c65cf7dfe7df520030f7.tar.gz
podman-99bdafba999078bb5763c65cf7dfe7df520030f7.tar.bz2
podman-99bdafba999078bb5763c65cf7dfe7df520030f7.zip
podman: split env variables in env and overrides
There are three different priorities for applying env variables: 1) environment/config file environment variables 2) image's config 3) user overrides (--env) The third kind are known to the client, while the default config and image's config is handled by the backend. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common/create.go3
-rw-r--r--cmd/podman/common/create_opts.go2
-rw-r--r--cmd/podman/common/specgen.go13
-rw-r--r--cmd/podman/containers/create.go12
-rw-r--r--cmd/podman/containers/run.go2
5 files changed, 21 insertions, 11 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go
index 53f4a8fa2..7086dc839 100644
--- a/cmd/podman/common/create.go
+++ b/cmd/podman/common/create.go
@@ -156,8 +156,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
createFlags.String("entrypoint", "",
"Overwrite the default ENTRYPOINT of the image",
)
- createFlags.StringArrayVarP(
- &cf.env,
+ createFlags.StringArrayP(
"env", "e", containerConfig.Env(),
"Set environment variables in container",
)
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go
index c275b1674..8b38e3b47 100644
--- a/cmd/podman/common/create_opts.go
+++ b/cmd/podman/common/create_opts.go
@@ -32,7 +32,7 @@ type ContainerCLIOpts struct {
DeviceWriteBPs []string
DeviceWriteIOPs []string
Entrypoint *string
- env []string
+ Env []string
EnvHost bool
EnvFile []string
Expose []string
diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go
index 3e9772576..9a2345064 100644
--- a/cmd/podman/common/specgen.go
+++ b/cmd/podman/common/specgen.go
@@ -335,15 +335,12 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
env = envLib.Join(env, fileEnv)
}
- // env overrides any previous variables
- if cmdLineEnv := c.env; len(cmdLineEnv) > 0 {
- parsedEnv, err := envLib.ParseSlice(cmdLineEnv)
- if err != nil {
- return err
- }
- env = envLib.Join(env, parsedEnv)
+ parsedEnv, err := envLib.ParseSlice(c.Env)
+ if err != nil {
+ return err
}
- s.Env = env
+
+ s.Env = envLib.Join(env, parsedEnv)
// LABEL VARIABLES
labels, err := parse.GetAllLabels(c.LabelFile, c.Label)
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
index 7927da04d..2ecdda2e0 100644
--- a/cmd/podman/containers/create.go
+++ b/cmd/podman/containers/create.go
@@ -55,6 +55,11 @@ func createFlags(flags *pflag.FlagSet) {
flags.AddFlagSet(common.GetCreateFlags(&cliVals))
flags.AddFlagSet(common.GetNetFlags())
flags.SetNormalizeFunc(common.AliasFlags)
+ if registry.IsRemote() {
+ _ = flags.MarkHidden("authfile")
+ _ = flags.MarkHidden("env-host")
+ _ = flags.MarkHidden("http-proxy")
+ }
}
func init() {
@@ -170,6 +175,13 @@ func createInit(c *cobra.Command) error {
val := c.Flag("entrypoint").Value.String()
cliVals.Entrypoint = &val
}
+ if c.Flags().Changed("env") {
+ env, err := c.Flags().GetStringArray("env")
+ if err != nil {
+ return errors.Wrapf(err, "retrieve env flag")
+ }
+ cliVals.Env = env
+ }
// Docker-compatibility: the "-h" flag for run/create is reserved for
// the hostname (see https://github.com/containers/libpod/issues/1367).
diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go
index f72446cb6..5f3ea9ef4 100644
--- a/cmd/podman/containers/run.go
+++ b/cmd/podman/containers/run.go
@@ -60,6 +60,8 @@ func runFlags(flags *pflag.FlagSet) {
flags.BoolVar(&runRmi, "rmi", false, "Remove container image unless used by other containers")
if registry.IsRemote() {
_ = flags.MarkHidden("authfile")
+ _ = flags.MarkHidden("env-host")
+ _ = flags.MarkHidden("http-proxy")
}
}
func init() {