mirror of
https://github.com/containers/podman.git
synced 2025-06-22 09:58:10 +08:00
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>
This commit is contained in:

committed by
Daniel J Walsh

parent
1d3cdf9a46
commit
99bdafba99
@ -9,6 +9,7 @@ import (
|
||||
envLib "github.com/containers/libpod/pkg/env"
|
||||
"github.com/containers/libpod/pkg/signal"
|
||||
"github.com/containers/libpod/pkg/specgen"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
@ -48,24 +49,28 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
|
||||
s.StopSignal = &sig
|
||||
}
|
||||
|
||||
rtc, err := r.GetConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Get Default Environment
|
||||
defaultEnvs, err := envLib.ParseSlice(rtc.Containers.Env)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Env fields in containers.conf failed to parse")
|
||||
}
|
||||
|
||||
// Image envs from the image if they don't exist
|
||||
// already
|
||||
env, err := newImage.Env(ctx)
|
||||
// already, overriding the default environments
|
||||
imageEnvs, err := newImage.Env(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(env) > 0 {
|
||||
envs, err := envLib.ParseSlice(env)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for k, v := range envs {
|
||||
if _, exists := s.Env[k]; !exists {
|
||||
s.Env[v] = k
|
||||
}
|
||||
}
|
||||
envs, err := envLib.ParseSlice(imageEnvs)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Env fields from image failed to parse")
|
||||
}
|
||||
s.Env = envLib.Join(envLib.Join(defaultEnvs, envs), s.Env)
|
||||
|
||||
labels, err := newImage.Labels(ctx)
|
||||
if err != nil {
|
||||
|
@ -47,6 +47,7 @@ type ContainerBasicConfig struct {
|
||||
// Optional.
|
||||
Env map[string]string `json:"env,omitempty"`
|
||||
// Terminal is whether the container will create a PTY.
|
||||
// Optional.
|
||||
Terminal bool `json:"terminal,omitempty"`
|
||||
// Stdin is whether the container will keep its STDIN open.
|
||||
Stdin bool `json:"stdin,omitempty"`
|
||||
|
Reference in New Issue
Block a user