Skip to content

Commit

Permalink
Add HelperBinariesDir field to engine config
Browse files Browse the repository at this point in the history
This field contains a list of directories which should be used to store
some helper binaries, e.g. gvproxy.

Also add a FindHelperBinary method to the config struct to get the full
path to a helper binary.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
  • Loading branch information
Luap99 committed Sep 10, 2021
1 parent f907b47 commit 04a59d4
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/containers.conf.5.md
Expand Up @@ -378,6 +378,29 @@ if you want to set environment variables for the container.
Default method to use when logging events.
Valid values: `file`, `journald`, and `none`.

**helper_binaries_dir**=["/usr/libexec/podman", ...]

A is a list of directories which are used to search for helper binaries.

The default paths on Linux are:
- `/usr/local/libexec/podman`
- `/usr/local/lib/podman`
- `/usr/libexec/podman`
- `/usr/lib/podman`

The default paths on macOS are:
- `/usr/local/opt/podman/libexec`
- `/opt/homebrew/bin`
- `/opt/homebrew/opt/podman/libexec`
- `/usr/local/bin`
- `/usr/local/libexec/podman`
- `/usr/local/lib/podman`
- `/usr/libexec/podman`
- `/usr/lib/podman`

The default path on Windows is:
- `C:\Program Files\RedHat\Podman`

**hooks_dir**=["/etc/containers/oci/hooks.d", ...]

Path to the OCI hooks directories for automatically executed hooks.
Expand Down
22 changes: 22 additions & 0 deletions pkg/config/config.go
Expand Up @@ -234,6 +234,10 @@ type EngineConfig struct {
// EventsLogger determines where events should be logged.
EventsLogger string `toml:"events_logger,omitempty"`

// HelperBinariesDir is a list of directories which are used to search for
// helper binaries.
HelperBinariesDir []string `toml:"helper_binaries_dir"`

// configuration files. When the same filename is present in in
// multiple directories, the file in the directory listed last in
// this slice takes precedence.
Expand Down Expand Up @@ -1126,3 +1130,21 @@ func (c *Config) ActiveDestination() (uri, identity string, err error) {
}
return "", "", errors.New("no service destination configured")
}

// FindHelperBinary will search the given binary name in the configured directories.
// If searchPATH is set to true it will also search in $PATH.
func (c *Config) FindHelperBinary(name string, searchPATH bool) (string, error) {
for _, path := range c.Engine.HelperBinariesDir {
fullpath := filepath.Join(path, name)
if fi, err := os.Stat(fullpath); err == nil && fi.Mode().IsRegular() {
return fullpath, nil
}
}
if searchPATH {
return exec.LookPath(name)
}
if len(c.Engine.HelperBinariesDir) == 0 {
return "", errors.Errorf("could not find %q because there are no helper binary directories configured", name)
}
return "", errors.Errorf("could not find %q in one of %v", name, c.Engine.HelperBinariesDir)
}
13 changes: 13 additions & 0 deletions pkg/config/config_darwin.go
Expand Up @@ -15,3 +15,16 @@ func customConfigFile() (string, error) {
func ifRootlessConfigPath() (string, error) {
return rootlessConfigPath()
}

var defaultHelperBinariesDir = []string{
// Homebrew install paths
"/usr/local/opt/podman/libexec",
"/opt/homebrew/bin",
"/opt/homebrew/opt/podman/libexec",
"/usr/local/bin",
// default paths
"/usr/local/libexec/podman",
"/usr/local/lib/podman",
"/usr/libexec/podman",
"/usr/lib/podman",
}
7 changes: 7 additions & 0 deletions pkg/config/config_linux.go
Expand Up @@ -35,3 +35,10 @@ func ifRootlessConfigPath() (string, error) {
}
return "", nil
}

var defaultHelperBinariesDir = []string{
"/usr/local/libexec/podman",
"/usr/local/lib/podman",
"/usr/libexec/podman",
"/usr/lib/podman",
}
5 changes: 5 additions & 0 deletions pkg/config/config_test.go
Expand Up @@ -163,6 +163,10 @@ var _ = Describe("Config", func() {
"TERM=xterm",
}

helperDirs := []string{
"/somepath",
}

// Then
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(defaultConfig.Engine.CgroupManager).To(gomega.Equal("systemd"))
Expand All @@ -172,6 +176,7 @@ var _ = Describe("Config", func() {
gomega.Expect(defaultConfig.Engine.NumLocks).To(gomega.BeEquivalentTo(2048))
gomega.Expect(defaultConfig.Engine.OCIRuntimes).To(gomega.Equal(OCIRuntimeMap))
gomega.Expect(defaultConfig.Containers.HTTPProxy).To(gomega.Equal(false))
gomega.Expect(defaultConfig.Engine.HelperBinariesDir).To(gomega.Equal(helperDirs))
})

It("test GetDefaultEnvEx", func() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config_windows.go
Expand Up @@ -13,3 +13,7 @@ func customConfigFile() (string, error) {
func ifRootlessConfigPath() (string, error) {
return os.Getenv("APPDATA") + "\\containers\\containers.conf", nil
}

var defaultHelperBinariesDir = []string{
"C:\\Program Files\\RedHat\\Podman",
}
9 changes: 9 additions & 0 deletions pkg/config/containers.conf
Expand Up @@ -341,6 +341,15 @@ default_sysctls = [
#
#events_logger = "journald"

# A is a list of directories which are used to search for helper binaries.
#
#helper_binaries_dir = [
# "/usr/local/libexec/podman",
# "/usr/local/lib/podman",
# "/usr/libexec/podman",
# "/usr/lib/podman",
#]

# Path to OCI hooks directories for automatically executed hooks.
#
#hooks_dir = [
Expand Down
1 change: 1 addition & 0 deletions pkg/config/default.go
Expand Up @@ -247,6 +247,7 @@ func defaultConfigFromMemory() (*EngineConfig, error) {
c.StaticDir = filepath.Join(storeOpts.GraphRoot, "libpod")
c.VolumePath = filepath.Join(storeOpts.GraphRoot, "volumes")

c.HelperBinariesDir = defaultHelperBinariesDir
c.HooksDir = DefaultHooksDirs
c.ImageDefaultTransport = _defaultTransport
c.StateType = BoltDBStateStore
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/testdata/containers_default.conf
Expand Up @@ -164,6 +164,13 @@ no_pivot_root = false
# namespace is set, all containers and pods are visible.
#namespace = ""

# A is a list of directories which are used to search for helper binaries.
#
helper_binaries_dir = [
"/somepath",
]


# Path to OCI hooks directories for automatically executed hooks.
hooks_dir = [
]
Expand Down

0 comments on commit 04a59d4

Please sign in to comment.