@@ -2,11 +2,12 @@ package wrapper
2
2
3
3
import (
4
4
"bytes"
5
- "errors"
6
5
"fmt"
7
6
"os"
8
7
"os/exec"
9
8
"strings"
9
+
10
+ "github.com/pkg/errors"
10
11
)
11
12
12
13
var (
@@ -29,17 +30,17 @@ func NewComposeWrapper(binaryPath string) (*ComposeWrapper, error) {
29
30
}
30
31
31
32
// 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 )
34
35
}
35
36
36
37
// 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 , "" , "" )
39
40
}
40
41
41
42
// 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 ) {
43
44
program := programPath (wrapper .binaryPath , "docker-compose" )
44
45
45
46
if projectName != "" {
@@ -50,12 +51,13 @@ func (wrapper *ComposeWrapper) Command(command composeCommand, url, projectName,
50
51
command .WithEnvFilePath (envFilePath )
51
52
}
52
53
53
- if url != "" {
54
- command .WithURL ( url )
54
+ if host != "" {
55
+ command .WithHost ( host )
55
56
}
56
57
57
58
var stderr bytes.Buffer
58
59
cmd := exec .Command (program , command .ToArgs ()... )
60
+ cmd .Dir = workingDir
59
61
60
62
if configPath != "" {
61
63
cmd .Env = os .Environ ()
@@ -66,7 +68,7 @@ func (wrapper *ComposeWrapper) Command(command composeCommand, url, projectName,
66
68
67
69
output , err := cmd .Output ()
68
70
if err != nil {
69
- return nil , errors .New ( stderr .String ())
71
+ return nil , errors .Wrap ( err , stderr .String ())
70
72
}
71
73
72
74
return output , nil
@@ -105,8 +107,8 @@ func (command *composeCommand) WithEnvFilePath(envFilePath string) {
105
107
command .args = append (command .args , "--env-file" , envFilePath )
106
108
}
107
109
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 )
110
112
}
111
113
112
114
func (command * composeCommand ) ToArgs () []string {
0 commit comments