Skip to content

Commit

Permalink
containers.conf: add new compose_providers option
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vrothberg committed Jul 20, 2023
1 parent c2cbd1b commit 8881c20
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/containers.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ 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 path or a (file) name.
Can be an absolute and relative path or a (file) name.

The defaults vary across supported platforms (Linux, FreeBSD, Mac OS, Windows).

**compose_warning_logs**=true

Emit logs on each invocation of the compose command indicating that an external
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ 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.
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.
Expand Down
12 changes: 12 additions & 0 deletions pkg/config/config_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/containers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 path or a (file) name.
# 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
Expand Down
1 change: 1 addition & 0 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,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 {
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/default_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ package config

// DefaultInitPath is the default path to the container-init binary.
var DefaultInitPath = "/usr/libexec/podman/catatonit"

var 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",
}
4 changes: 4 additions & 0 deletions pkg/config/default_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ func getDefaultMachineVolumes() []string {
"/var/folders:/var/folders",
}
}

func getDefaultComposeProviders() []string {
return append(defaultUnixComposeProviders, "/opt/homebrew/bin/docker-compose", "podman-compose")
}
4 changes: 4 additions & 0 deletions pkg/config/default_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ func getLibpodTmpDir() string {
func getDefaultMachineVolumes() []string {
return []string{"$HOME:$HOME"}
}

func getDefaultComposeProviders() []string {
return append(defaultUnixComposeProviders, "podman-compose")
}
4 changes: 4 additions & 0 deletions pkg/config/default_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ func getLibpodTmpDir() string {
func getDefaultMachineVolumes() []string {
return []string{"$HOME:$HOME"}
}

func getDefaultComposeProviders() []string {
return append(defaultUnixComposeProviders, "podman-compose")
}
5 changes: 5 additions & 0 deletions pkg/config/default_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
5 changes: 5 additions & 0 deletions pkg/config/testdata/containers_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 path or a (file) name.
# 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
Expand Down

0 comments on commit 8881c20

Please sign in to comment.