Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions common/docs/containers.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ overwriting values specified on the command line when the container was created.

Pass all host environment variables into the container.

**env_merge**=[]

Preprocess default environment variables for the container.
Works the same as the **--env-merge** command line option.
The value of existing variables in the image will be used for substitution.

Example: `env_merge=["PATH=${PATH}:/custom/bin"]`

**host_containers_internal_ip**=""

Set the IP address the container should expect to connect to the host. The IP
Expand Down
3 changes: 3 additions & 0 deletions common/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ type ContainersConfig struct {
// EnvHost Pass all host environment variables into the container.
EnvHost bool `toml:"env_host,omitempty"`

// EnvMerge preprocess the environment variables list for the container.
EnvMerge configfile.Slice `toml:"env_merge,omitempty"`

// HostContainersInternalIP is used to set a specific host.containers.internal ip.
HostContainersInternalIP string `toml:"host_containers_internal_ip,omitempty"`

Expand Down
11 changes: 11 additions & 0 deletions common/pkg/config/config_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,4 +664,15 @@ var _ = Describe("Config Local", func() {
// Then
gomega.Expect(err).To(gomega.HaveOccurred())
})
It("should parse env_merge from config file", func() {
// Given
config, err := newLocked(&Options{}, testConfigPath(""))
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(config.Containers.EnvMerge.Get()).To(gomega.BeEmpty())
// When
config2, err := newLocked(&Options{}, testConfigPath("testdata/containers_default.conf"))
// Then
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(config2.Containers.EnvMerge.Get()).To(gomega.Equal([]string{"FOO=bar"}))
})
})
4 changes: 4 additions & 0 deletions common/pkg/config/containers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ default_sysctls = [
#
#env_host = false

# Preprocess default environment variables for the container.
#
#env_merge = []

# Set the IP address the container should expect to connect to the host. The IP
# address is used by Podman to automatically add the `host.containers.internal`
# and `host.docker.internal` hostnames to the container's `/etc/hosts` file. It
Expand Down
1 change: 1 addition & 0 deletions common/pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func defaultConfig() (*Config, error) {
EnableLabeling: selinux.GetEnabled(),
Env: configfile.NewSlice(defaultContainerEnv),
EnvHost: false,
EnvMerge: configfile.Slice{},
HTTPProxy: true,
IPCNS: "shareable",
Init: false,
Expand Down
5 changes: 5 additions & 0 deletions common/pkg/config/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ var _ = Describe("Config Modules", func() {
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(c.Containers.InitPath).To(gomega.Equal("etc four"))
gomega.Expect(c.Containers.Env.Get()).To(gomega.Equal([]string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "usr share only"}))
gomega.Expect(c.Containers.EnvMerge.Get()).To(gomega.Equal([]string{
"PATH=/base/bin:${PATH}",
"PATH=/usr/local/share/bin:${PATH}",
"etc only env_merge conf",
}))
gomega.Expect(c.Network.DefaultNetwork).To(gomega.Equal("etc only conf"))
gomega.Expect(c.LoadedModules()).To(gomega.HaveLen(3)) // 3 modules are getting loaded!

Expand Down
2 changes: 2 additions & 0 deletions common/pkg/config/testdata/containers_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ env = [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
]

env_merge = ["FOO=bar"]

# Run an init inside the container that forwards signals and reaps processes.
init = false

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[network]
default_network="etc only conf"

[containers]
env_merge=["PATH=/usr/local/share/bin:${PATH}", "etc only env_merge conf", {append=true}]
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[containers]
env=["usr share only", {append=true}]
env_merge=["PATH=/base/bin:${PATH}"]