Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HelperBinariesDir field to engine config #758

Merged
merged 1 commit into from Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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`
Luap99 marked this conversation as resolved.
Show resolved Hide resolved
- `/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",
Luap99 marked this conversation as resolved.
Show resolved Hide resolved
"/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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is off in the first entry.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional, check the other config options in the file.

# "/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