forked from gruntwork-io/terratest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_compose.go
34 lines (29 loc) · 1022 Bytes
/
docker_compose.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package docker
import (
"github.com/gruntwork-io/terratest/modules/shell"
"testing"
)
type Options struct {
WorkingDir string
EnvVars map[string]string
}
// Run docker-compose with the given arguments and options and return stdout/stderr
func RunDockerCompose(t *testing.T, options *Options, args ... string) string {
out, err := RunDockerComposeE(t, options, args...)
if err != nil {
t.Fatal(err)
}
return out
}
// Run docker-compose with the given arguments and options and return stdout/stderr
func RunDockerComposeE(t *testing.T, options *Options, args ... string) (string, error) {
cmd := shell.Command{
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{"--project-name", t.Name()}, args...),
WorkingDir: options.WorkingDir,
Env: options.EnvVars,
}
return shell.RunCommandAndGetOutputE(t, cmd)
}