mirror of
https://github.com/containers/podman.git
synced 2025-05-22 09:36:57 +08:00
Merge pull request #5696 from rhatdan/cc
Fix environment handling from containers.conf
This commit is contained in:
@ -538,6 +538,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.IsSet("env") {
|
||||||
// env overrides any previous variables
|
// env overrides any previous variables
|
||||||
cmdlineEnv := c.StringSlice("env")
|
cmdlineEnv := c.StringSlice("env")
|
||||||
if len(cmdlineEnv) > 0 {
|
if len(cmdlineEnv) > 0 {
|
||||||
@ -547,6 +548,7 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
|
|||||||
}
|
}
|
||||||
env = envLib.Join(env, parsedEnv)
|
env = envLib.Join(env, parsedEnv)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// LABEL VARIABLES
|
// LABEL VARIABLES
|
||||||
labels, err := parse.GetAllLabels(c.StringSlice("label-file"), c.StringArray("label"))
|
labels, err := parse.GetAllLabels(c.StringSlice("label-file"), c.StringArray("label"))
|
||||||
@ -636,12 +638,15 @@ func ParseCreateOpts(ctx context.Context, c *GenericCLIResults, runtime *libpod.
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "unable to translate --shm-size")
|
return nil, errors.Wrapf(err, "unable to translate --shm-size")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.IsSet("add-host") {
|
||||||
// Verify the additional hosts are in correct format
|
// Verify the additional hosts are in correct format
|
||||||
for _, host := range c.StringSlice("add-host") {
|
for _, host := range c.StringSlice("add-host") {
|
||||||
if _, err := parse.ValidateExtraHost(host); err != nil {
|
if _, err := parse.ValidateExtraHost(host); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dnsSearches []string
|
dnsSearches []string
|
||||||
|
2
go.sum
2
go.sum
@ -189,6 +189,7 @@ github.com/google/btree v0.0.0-20160524151835-7d79101e329e/go.mod h1:lNA+9X1NB3Z
|
|||||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||||
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||||
@ -617,6 +618,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
|
@ -316,7 +316,17 @@ func (config *CreateConfig) createConfigToOCISpec(runtime *libpod.Runtime, userM
|
|||||||
|
|
||||||
// Make sure to always set the default variables unless overridden in the
|
// Make sure to always set the default variables unless overridden in the
|
||||||
// config.
|
// config.
|
||||||
config.Env = env.Join(env.DefaultEnvVariables, config.Env)
|
var defaultEnv map[string]string
|
||||||
|
if runtimeConfig == nil {
|
||||||
|
defaultEnv = env.DefaultEnvVariables
|
||||||
|
} else {
|
||||||
|
defaultEnv, err = env.ParseSlice(runtimeConfig.Containers.Env)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "Env fields in containers.conf failed ot parse")
|
||||||
|
}
|
||||||
|
defaultEnv = env.Join(env.DefaultEnvVariables, defaultEnv)
|
||||||
|
}
|
||||||
|
config.Env = env.Join(defaultEnv, config.Env)
|
||||||
for name, val := range config.Env {
|
for name, val := range config.Env {
|
||||||
g.AddProcessEnv(name, val)
|
g.AddProcessEnv(name, val)
|
||||||
}
|
}
|
||||||
|
2
test/e2e/build/basicalpine/Containerfile.path
Normal file
2
test/e2e/build/basicalpine/Containerfile.path
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
FROM alpine
|
||||||
|
ENV PATH=/tmp:/bin:/usr/bin:/usr/sbin
|
@ -175,4 +175,24 @@ var _ = Describe("Podman build", func() {
|
|||||||
data := inspect.InspectImageJSON()
|
data := inspect.InspectImageJSON()
|
||||||
Expect(data[0].ID).To(Equal(string(id)))
|
Expect(data[0].ID).To(Equal(string(id)))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman Test PATH in built image", func() {
|
||||||
|
path := "/tmp:/bin:/usr/bin:/usr/sbin"
|
||||||
|
session := podmanTest.PodmanNoCache([]string{
|
||||||
|
"build", "-f", "build/basicalpine/Containerfile.path", "-t", "test-path",
|
||||||
|
})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"run", "test-path", "printenv", "PATH"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
stdoutLines := session.OutputToStringArray()
|
||||||
|
Expect(stdoutLines[0]).Should(Equal(path))
|
||||||
|
|
||||||
|
session = podmanTest.PodmanNoCache([]string{"rmi", "-a", "-f"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user