Skip to content

Commit

Permalink
(#25) Add a function to "down" the compose
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Sep 11, 2019
1 parent d905a32 commit 0f66b80
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
26 changes: 26 additions & 0 deletions compose.go
Expand Up @@ -18,6 +18,7 @@ const (

// DockerCompose defines the contract for running Docker Compose
type DockerCompose interface {
Down() execError
Invoke() execError
WithCommand([]string) DockerCompose
WithEnv(map[string]string) DockerCompose
Expand Down Expand Up @@ -48,6 +49,31 @@ func NewLocalDockerCompose(filePath string, identifier string) *LocalDockerCompo
return dc
}

// Down executes docker-compose down
func (dc *LocalDockerCompose) Down() execError {
if which(dc.Executable) != nil {
panic("Local Docker Compose not found. Is " + dc.Executable + " on the PATH?")
}

abs, err := filepath.Abs(dc.ComposeFilePath)
pwd, name := filepath.Split(abs)

cmds := []string{
"-f", name, "down",
}

execErr := execute(pwd, map[string]string{}, dc.Executable, cmds)
err = execErr.Error
if err != nil {
args := strings.Join(dc.Cmd, " ")
panic(
"Local Docker compose exited abnormally whilst running " +
dc.Executable + ": [" + args + "]. " + err.Error())
}

return execErr
}

// Invoke invokes the docker compose
func (dc *LocalDockerCompose) Invoke() execError {
if which(dc.Executable) != nil {
Expand Down
4 changes: 1 addition & 3 deletions compose_test.go
Expand Up @@ -15,9 +15,7 @@ func TestLocalDockerCompose(t *testing.T) {
checkIfError(t, err)

destroyFn := func() {
compose.WithCommand([]string{"down"})

err := compose.Invoke()
err := compose.Down()
checkIfError(t, err)
}
defer destroyFn()
Expand Down

0 comments on commit 0f66b80

Please sign in to comment.