Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 31dcfbe

Browse files
committed
feat: run docker compose in a working directory
1 parent 0a14182 commit 31dcfbe

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

wrapper.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package wrapper
22

33
import (
44
"bytes"
5-
"errors"
65
"fmt"
76
"os"
87
"os/exec"
98
"strings"
9+
10+
"github.com/pkg/errors"
1011
)
1112

1213
var (
@@ -29,17 +30,17 @@ func NewComposeWrapper(binaryPath string) (*ComposeWrapper, error) {
2930
}
3031

3132
// Up create and start containers
32-
func (wrapper *ComposeWrapper) Up(filePaths []string, url, projectName, envFilePath, configPath string) ([]byte, error) {
33-
return wrapper.Command(newUpCommand(filePaths), url, projectName, envFilePath, configPath)
33+
func (wrapper *ComposeWrapper) Up(filePaths []string, projectDir, host, projectName, envFilePath, configPath string) ([]byte, error) {
34+
return wrapper.Command(newUpCommand(filePaths), projectDir, host, projectName, envFilePath, configPath)
3435
}
3536

3637
// Down stop and remove containers
37-
func (wrapper *ComposeWrapper) Down(filePaths []string, url, projectName string) ([]byte, error) {
38-
return wrapper.Command(newDownCommand(filePaths), url, projectName, "", "")
38+
func (wrapper *ComposeWrapper) Down(filePaths []string, projectDir string, host, projectName string) ([]byte, error) {
39+
return wrapper.Command(newDownCommand(filePaths), projectDir, host, projectName, "", "")
3940
}
4041

4142
// Command exectue a docker-compose commanåd
42-
func (wrapper *ComposeWrapper) Command(command composeCommand, url, projectName, envFilePath, configPath string) ([]byte, error) {
43+
func (wrapper *ComposeWrapper) Command(command composeCommand, workingDir, host, projectName, envFilePath, configPath string) ([]byte, error) {
4344
program := programPath(wrapper.binaryPath, "docker-compose")
4445

4546
if projectName != "" {
@@ -50,12 +51,13 @@ func (wrapper *ComposeWrapper) Command(command composeCommand, url, projectName,
5051
command.WithEnvFilePath(envFilePath)
5152
}
5253

53-
if url != "" {
54-
command.WithURL(url)
54+
if host != "" {
55+
command.WithHost(host)
5556
}
5657

5758
var stderr bytes.Buffer
5859
cmd := exec.Command(program, command.ToArgs()...)
60+
cmd.Dir = workingDir
5961

6062
if configPath != "" {
6163
cmd.Env = os.Environ()
@@ -105,8 +107,8 @@ func (command *composeCommand) WithEnvFilePath(envFilePath string) {
105107
command.args = append(command.args, "--env-file", envFilePath)
106108
}
107109

108-
func (command *composeCommand) WithURL(url string) {
109-
command.args = append(command.args, "-H", url)
110+
func (command *composeCommand) WithHost(host string) {
111+
command.args = append(command.args, "-H", host)
110112
}
111113

112114
func (command *composeCommand) ToArgs() []string {

0 commit comments

Comments
 (0)