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

Commit bf52517

Browse files
committed
call docker plugin docker-compose v2 directly.
1 parent e3cf664 commit bf52517

File tree

1 file changed

+17
-48
lines changed

1 file changed

+17
-48
lines changed

compose/internal/composeplugin/composeplugin.go

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ import (
44
"bytes"
55
"context"
66
"log"
7-
"os"
87
"os/exec"
9-
"path"
108
"strings"
119

1210
"github.com/pkg/errors"
1311
libstack "github.com/portainer/docker-compose-wrapper"
14-
liberrors "github.com/portainer/docker-compose-wrapper/compose/errors"
1512
"github.com/portainer/docker-compose-wrapper/compose/internal/utils"
1613
)
1714

@@ -27,50 +24,23 @@ type PluginWrapper struct {
2724

2825
// NewPluginWrapper initializes a new ComposeWrapper service with local docker-compose binary.
2926
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")) {
5828
return nil, MissingDockerComposePluginErr
5929
}
6030

6131
return &PluginWrapper{binaryPath: binaryPath, configPath: configPath}, nil
6232
}
6333

6434
// 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)
6737
if len(output) != 0 {
6838
if err != nil {
6939
return err
7040
}
7141

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)
7444
}
7545

7646
return err
@@ -84,8 +54,8 @@ func (wrapper *PluginWrapper) Remove(ctx context.Context, workingDir, host, proj
8454
return err
8555
}
8656

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)
8959
}
9060

9161
return err
@@ -99,16 +69,16 @@ func (wrapper *PluginWrapper) Pull(ctx context.Context, workingDir, host, projec
9969
return err
10070
}
10171

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)
10474
}
10575

10676
return err
10777
}
10878

10979
// 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")
11282

11383
if projectName != "" {
11484
command.WithProjectName(projectName)
@@ -118,6 +88,10 @@ func (wrapper *PluginWrapper) command(command composeCommand, workingDir, url, p
11888
command.WithEnvFilePath(envFilePath)
11989
}
12090

91+
if host != "" {
92+
command.WithHost(host)
93+
}
94+
12195
var stderr bytes.Buffer
12296

12397
args := []string{}
@@ -126,11 +100,6 @@ func (wrapper *PluginWrapper) command(command composeCommand, workingDir, url, p
126100
args = append(args, "--config", wrapper.configPath)
127101
}
128102

129-
if url != "" {
130-
args = append(args, "-H", url)
131-
}
132-
133-
args = append(args, "compose")
134103
args = append(args, command.ToArgs()...)
135104

136105
cmd := exec.Command(program, args...)
@@ -191,8 +160,8 @@ func (command *composeCommand) WithEnvFilePath(envFilePath string) {
191160
command.args = append(command.args, "--env-file", envFilePath)
192161
}
193162

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)
196165
}
197166

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

0 commit comments

Comments
 (0)