From 4f1c361908678e80831bb24988f87cffc86f6965 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Tue, 18 Jul 2023 13:42:53 +0200 Subject: [PATCH] containers.conf: add new `compose_providers` option Specify one or more external providers for the compose command. The first found provider is used for execution. Can be an absolute path or a (file) name. Relative names are invalid. File names are evaluated via $PATH look ups. Signed-off-by: Valentin Rothberg --- docs/containers.conf.5.md | 6 ++++++ pkg/config/config.go | 6 ++++++ pkg/config/config_local_test.go | 12 ++++++++++++ pkg/config/containers.conf | 5 +++++ pkg/config/default.go | 11 +++++++++++ pkg/config/default_darwin.go | 11 +++++++++++ pkg/config/default_freebsd.go | 4 ++++ pkg/config/default_linux.go | 4 ++++ pkg/config/default_windows.go | 5 +++++ pkg/config/testdata/containers_default.conf | 5 +++++ 10 files changed, 69 insertions(+) diff --git a/docs/containers.conf.5.md b/docs/containers.conf.5.md index 16cc6ebd4..bff3adf2b 100644 --- a/docs/containers.conf.5.md +++ b/docs/containers.conf.5.md @@ -428,6 +428,12 @@ Enforce using docker.io for completing short names in Podman's compatibility REST API. Note that this will ignore unqualified-search-registries and short-name aliases defined in containers-registries.conf(5). +**compose_providers**=[] + +Specify one or more external providers for the compose command. The first +found provider is used for execution. Can be an absolute and relative path or +a (file) name. + **compose_warning_logs**=true Emit logs on each invocation of the compose command indicating that an external diff --git a/pkg/config/config.go b/pkg/config/config.go index 7bc7ec9aa..4d151abc1 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -266,6 +266,12 @@ type EngineConfig struct { // in containers-registries.conf(5). CompatAPIEnforceDockerHub bool `toml:"compat_api_enforce_docker_hub,omitempty"` + // ComposeProviders specifies one or more external providers for the + // compose command. The first found provider is used for execution. + // Can be an absolute and relative path or a (file) name. Make sure to + // expand the return items via `os.ExpandEnv`. + ComposeProviders []string `toml:"compose_providers,omitempty"` + // ComposeWarningLogs emits logs on each invocation of the compose // command indicating that an external compose provider is being // executed. diff --git a/pkg/config/config_local_test.go b/pkg/config/config_local_test.go index 78129e693..b9bd4218f 100644 --- a/pkg/config/config_local_test.go +++ b/pkg/config/config_local_test.go @@ -476,6 +476,18 @@ var _ = Describe("Config Local", func() { gomega.Expect(config2.Engine.CompatAPIEnforceDockerHub).To(gomega.Equal(false)) }) + It("ComposeProviders", func() { + // Given + config, err := NewConfig("") + gomega.Expect(err).To(gomega.BeNil()) + gomega.Expect(config.Engine.ComposeProviders).To(gomega.Equal(getDefaultComposeProviders())) // no hard-coding to work on all paltforms + // When + config2, err := NewConfig("testdata/containers_default.conf") + // Then + gomega.Expect(err).To(gomega.BeNil()) + gomega.Expect(config2.Engine.ComposeProviders).To(gomega.Equal([]string{"/some/thing/else", "/than/before"})) + }) + It("ComposeWarningLogs", func() { // Given config, err := NewConfig("") diff --git a/pkg/config/containers.conf b/pkg/config/containers.conf index 25486ea44..631505016 100644 --- a/pkg/config/containers.conf +++ b/pkg/config/containers.conf @@ -381,6 +381,11 @@ default_sysctls = [ # short-name aliases defined in containers-registries.conf(5). #compat_api_enforce_docker_hub = true +# Specify one or more external providers for the compose command. The first +# found provider is used for execution. Can be an absolute and relative path +# or a (file) name. +#compose_providers=[] + # Emit logs on each invocation of the compose command indicating that an # external compose provider is being executed. #compose_warning_logs = true diff --git a/pkg/config/default.go b/pkg/config/default.go index 2b01884e2..d418e6b05 100644 --- a/pkg/config/default.go +++ b/pkg/config/default.go @@ -87,6 +87,16 @@ var ( // should be set during link-time, if different packagers put their // helper binary in a different location. additionalHelperBinariesDir string + + defaultUnixComposeProviders = []string{ + "docker-compose", + "$HOME/.docker/cli-plugins/docker-compose", + "/usr/local/lib/docker/cli-plugins/docker-compose", + "/usr/local/libexec/docker/cli-plugins/docker-compose", + "/usr/lib/docker/cli-plugins/docker-compose", + "/usr/libexec/docker/cli-plugins/docker-compose", + "podman-compose", + } ) // nolint:unparam @@ -260,6 +270,7 @@ func defaultConfigFromMemory() (*EngineConfig, error) { c.EventsLogFileMaxSize = eventsLogMaxSize(DefaultEventsLogSizeMax) c.CompatAPIEnforceDockerHub = true + c.ComposeProviders = getDefaultComposeProviders() // may vary across supported platforms c.ComposeWarningLogs = true if path, ok := os.LookupEnv("CONTAINERS_STORAGE_CONF"); ok { diff --git a/pkg/config/default_darwin.go b/pkg/config/default_darwin.go index 755766620..86fa6d508 100644 --- a/pkg/config/default_darwin.go +++ b/pkg/config/default_darwin.go @@ -20,3 +20,14 @@ func getDefaultMachineVolumes() []string { "/var/folders:/var/folders", } } + +func getDefaultComposeProviders() []string { + return []string{ + "docker-compose", + "$HOME/.docker/cli-plugins/docker-compose", + "/opt/homebrew/bin/docker-compose", + "/usr/local/bin/docker-compose", + "/Applications/Docker.app/Contents/Resources/cli-plugins/docker-compose", + "podman-compose", + } +} diff --git a/pkg/config/default_freebsd.go b/pkg/config/default_freebsd.go index 637abf981..1110edd03 100644 --- a/pkg/config/default_freebsd.go +++ b/pkg/config/default_freebsd.go @@ -26,3 +26,7 @@ func getLibpodTmpDir() string { func getDefaultMachineVolumes() []string { return []string{"$HOME:$HOME"} } + +func getDefaultComposeProviders() []string { + return defaultUnixComposeProviders +} diff --git a/pkg/config/default_linux.go b/pkg/config/default_linux.go index d4d04764a..ee2c49d13 100644 --- a/pkg/config/default_linux.go +++ b/pkg/config/default_linux.go @@ -74,3 +74,7 @@ func getLibpodTmpDir() string { func getDefaultMachineVolumes() []string { return []string{"$HOME:$HOME"} } + +func getDefaultComposeProviders() []string { + return defaultUnixComposeProviders +} diff --git a/pkg/config/default_windows.go b/pkg/config/default_windows.go index 08a0bf223..c79bc7008 100644 --- a/pkg/config/default_windows.go +++ b/pkg/config/default_windows.go @@ -49,3 +49,8 @@ func getLibpodTmpDir() string { func getDefaultMachineVolumes() []string { return []string{} } + +func getDefaultComposeProviders() []string { + // Rely on os.LookPath to do the trick on Windows. + return []string{"docker-compose", "podman-compose"} +} diff --git a/pkg/config/testdata/containers_default.conf b/pkg/config/testdata/containers_default.conf index 26992a2a2..f34c54ad3 100644 --- a/pkg/config/testdata/containers_default.conf +++ b/pkg/config/testdata/containers_default.conf @@ -162,6 +162,11 @@ conmon_path = [ # short-name aliases defined in containers-registries.conf(5). compat_api_enforce_docker_hub = false +# Specify one or more external providers for the compose command. The first +# found provider is used for execution. Can be an absolute and relative path or +# a (file) name. +compose_providers=["/some/thing/else", "/than/before"] + # Emit logs on each invocation of the compose command indicating that an # external compose provider is being executed. compose_warning_logs = false