@@ -4,14 +4,11 @@ import (
4
4
"bytes"
5
5
"context"
6
6
"log"
7
- "os"
8
7
"os/exec"
9
- "path"
10
8
"strings"
11
9
12
10
"github.com/pkg/errors"
13
11
libstack "github.com/portainer/docker-compose-wrapper"
14
- liberrors "github.com/portainer/docker-compose-wrapper/compose/errors"
15
12
"github.com/portainer/docker-compose-wrapper/compose/internal/utils"
16
13
)
17
14
@@ -27,50 +24,23 @@ type PluginWrapper struct {
27
24
28
25
// NewPluginWrapper initializes a new ComposeWrapper service with local docker-compose binary.
29
26
func NewPluginWrapper (binaryPath , configPath string ) (libstack.Deployer , error ) {
30
- if ! utils .IsBinaryPresent (utils .ProgramPath (binaryPath , "docker" )) {
31
- return nil , liberrors .ErrBinaryNotFound
32
- }
33
-
34
- if configPath == "" {
35
- homePath , err := os .UserHomeDir ()
36
- if err != nil {
37
- return nil , errors .WithMessage (err , "failed fetching user home directory" )
38
- }
39
- configPath = path .Join (homePath , ".docker" )
40
- }
41
-
42
- dockerPluginsPath := path .Join (configPath , "cli-plugins" )
43
- pluginPath := utils .ProgramPath (binaryPath , "docker-compose.plugin" )
44
-
45
- if utils .IsBinaryPresent (pluginPath ) {
46
- if ! utils .IsBinaryPresent (utils .ProgramPath (dockerPluginsPath , "docker-compose" )) {
47
- err := os .MkdirAll (dockerPluginsPath , 0755 )
48
- if err != nil {
49
- return nil , errors .WithMessage (err , "failed creating plugins path" )
50
- }
51
- }
52
-
53
- err := utils .Move (pluginPath , utils .ProgramPath (dockerPluginsPath , "docker-compose" ))
54
- if err != nil {
55
- return nil , err
56
- }
57
- } else if ! utils .IsBinaryPresent (utils .ProgramPath (dockerPluginsPath , "docker-compose" )) {
27
+ if ! utils .IsBinaryPresent (utils .ProgramPath (binaryPath , "docker-compose" )) {
58
28
return nil , MissingDockerComposePluginErr
59
29
}
60
30
61
31
return & PluginWrapper {binaryPath : binaryPath , configPath : configPath }, nil
62
32
}
63
33
64
34
// Up create and start containers
65
- func (wrapper * PluginWrapper ) Deploy (ctx context.Context , workingDir , host , projectName string , filePaths []string , envFilePath string , forceRereate bool ) error {
66
- output , err := wrapper .command (newUpCommand (filePaths , forceRereate ), workingDir , host , projectName , envFilePath )
35
+ func (wrapper * PluginWrapper ) Deploy (ctx context.Context , workingDir , host , projectName string , filePaths []string , envFilePath string , forceRecreate bool ) error {
36
+ output , err := wrapper .command (newUpCommand (filePaths , forceRecreate ), workingDir , host , projectName , envFilePath )
67
37
if len (output ) != 0 {
68
38
if err != nil {
69
39
return err
70
40
}
71
41
72
- log .Printf ("[INFO] [compose,internal,composeplugin ] [message: Stack deployment successful]" )
73
- log .Printf ("[DEBUG] [compose,internal,composeplugin ] [output: %s]" , output )
42
+ log .Printf ("[INFO] [docker compose] [message: Stack deployment successful]" )
43
+ log .Printf ("[DEBUG] [docker compose] [output: %s]" , output )
74
44
}
75
45
76
46
return err
@@ -84,8 +54,8 @@ func (wrapper *PluginWrapper) Remove(ctx context.Context, workingDir, host, proj
84
54
return err
85
55
}
86
56
87
- log .Printf ("[INFO] [compose,internal,composeplugin ] [message: Stack removal successful]" )
88
- log .Printf ("[DEBUG] [compose,internal,composeplugin ] [output: %s]" , output )
57
+ log .Printf ("[INFO] [docker compose] [message: Stack removal successful]" )
58
+ log .Printf ("[DEBUG] [docker compose] [output: %s]" , output )
89
59
}
90
60
91
61
return err
@@ -99,16 +69,16 @@ func (wrapper *PluginWrapper) Pull(ctx context.Context, workingDir, host, projec
99
69
return err
100
70
}
101
71
102
- log .Printf ("[INFO] [compose,internal,composeplugin ] [message: Stack pull successful]" )
103
- log .Printf ("[DEBUG] [compose,internal,composeplugin ] [output: %s]" , output )
72
+ log .Printf ("[INFO] [docker compose] [message: Stack pull successful]" )
73
+ log .Printf ("[DEBUG] [docker compose] [output: %s]" , output )
104
74
}
105
75
106
76
return err
107
77
}
108
78
109
79
// Command exectue a docker-compose commanåd
110
- func (wrapper * PluginWrapper ) command (command composeCommand , workingDir , url , projectName , envFilePath string ) ([]byte , error ) {
111
- program := utils .ProgramPath (wrapper .binaryPath , "docker" )
80
+ func (wrapper * PluginWrapper ) command (command composeCommand , workingDir , host , projectName , envFilePath string ) ([]byte , error ) {
81
+ program := utils .ProgramPath (wrapper .binaryPath , "docker-compose " )
112
82
113
83
if projectName != "" {
114
84
command .WithProjectName (projectName )
@@ -118,6 +88,10 @@ func (wrapper *PluginWrapper) command(command composeCommand, workingDir, url, p
118
88
command .WithEnvFilePath (envFilePath )
119
89
}
120
90
91
+ if host != "" {
92
+ command .WithHost (host )
93
+ }
94
+
121
95
var stderr bytes.Buffer
122
96
123
97
args := []string {}
@@ -126,11 +100,6 @@ func (wrapper *PluginWrapper) command(command composeCommand, workingDir, url, p
126
100
args = append (args , "--config" , wrapper .configPath )
127
101
}
128
102
129
- if url != "" {
130
- args = append (args , "-H" , url )
131
- }
132
-
133
- args = append (args , "compose" )
134
103
args = append (args , command .ToArgs ()... )
135
104
136
105
cmd := exec .Command (program , args ... )
@@ -191,8 +160,8 @@ func (command *composeCommand) WithEnvFilePath(envFilePath string) {
191
160
command .args = append (command .args , "--env-file" , envFilePath )
192
161
}
193
162
194
- func (command * composeCommand ) WithURL ( url string ) {
195
- command .args = append (command .args , "-H" , url )
163
+ func (command * composeCommand ) WithHost ( host string ) {
164
+ command .args = append (command .args , "-H" , host )
196
165
}
197
166
198
167
func (command * composeCommand ) ToArgs () []string {
0 commit comments