Skip to content

Commit

Permalink
refactored logic for Docker Compose backwards compat handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nialdaly committed Jun 19, 2022
1 parent adf209b commit ffe6365
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ require (
k8s.io/client-go v0.20.6
)

require github.com/slack-go/slack v0.10.3
require (
github.com/slack-go/slack v0.10.3
gotest.tools/v3 v3.0.3
)

require (
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
Expand Down
21 changes: 8 additions & 13 deletions modules/docker/docker_compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/gruntwork-io/terratest/modules/shell"
"github.com/gruntwork-io/terratest/modules/testing"
"github.com/stretchr/testify/require"
"gotest.tools/v3/icmd"
)

// Options are Docker options.
Expand Down Expand Up @@ -40,29 +41,23 @@ func RunDockerComposeE(t testing.TestingT, options *Options, args ...string) (st

func runDockerComposeE(t testing.TestingT, stdout bool, options *Options, args ...string) (string, error) {
cmd := shell.Command{
Command: "docker",
Command: "docker-compose",
// We append --project-name to ensure containers from multiple different tests using Docker Compose don't end
// up in the same project and end up conflicting with each other.
Args: append([]string{"compose", "--project-name", strings.ToLower(t.Name())}, args...),
Args: append([]string{"--project-name", strings.ToLower(t.Name())}, args...),
WorkingDir: options.WorkingDir,
Env: options.EnvVars,
Logger: options.Logger,
}

checkDockerComposeVersionCmd := shell.Command{
Command: "docker",
Args: []string{"compose", "version"},
WorkingDir: options.WorkingDir,
Env: options.EnvVars,
Logger: options.Logger,
}
dockerComposeVersionCmd := icmd.Command("docker", "compose", "version")

_, err := shell.RunCommandAndGetOutputE(t, checkDockerComposeVersionCmd)
result := icmd.RunCmd(dockerComposeVersionCmd)

if err != nil {
if result.ExitCode == 0 {
cmd = shell.Command{
Command: "docker-compose",
Args: append([]string{"--project-name", strings.ToLower(t.Name())}, args...),
Command: "docker",
Args: append([]string{"compose", "--project-name", strings.ToLower(t.Name())}, args...),
WorkingDir: options.WorkingDir,
Env: options.EnvVars,
Logger: options.Logger,
Expand Down

0 comments on commit ffe6365

Please sign in to comment.