Skip to content

Commit 5c50a09

Browse files
committed
seach for provider binary in PATH
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent f5c2002 commit 5c50a09

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed

docs/extension.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ the resource(s) needed to run a service.
2626
- Another Docker CLI plugin (typically, `model` to run `docker-model`)
2727
- An executable in user's `PATH`
2828

29-
To be a valid Compose extension, provider command *MUST* accept subcommand `compose` (which can be hidden)
29+
To be a valid Compose extension, provider command *MUST* accept a `compose` command (which can be hidden)
3030
with subcommands `up` and `down`.
3131

3232
## Up lifecycle
3333

3434
To execute an application's `up` lifecycle, Compose executes the provider's `compose up` command, passing
35-
the project name, service name and additional options. The `provider.options` are translated
35+
the project name, service name, and additional options. The `provider.options` are translated
3636
into command line flags. For example:
3737
```console
3838
awesomecloud compose --project-name <NAME> up --type=mysql --size=256 "database"

pkg/compose/plugins.go

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ func (s *composeService) runPlugin(ctx context.Context, project *types.Project,
5555
return err
5656
}
5757

58-
if err := s.checkPluginEnabledInDD(ctx, plugin); err != nil {
59-
return err
60-
}
61-
62-
cmd := s.setupPluginCommand(ctx, project, service, plugin.Path, command)
58+
cmd := s.setupPluginCommand(ctx, project, service, plugin, command)
6359

6460
variables, err := s.executePlugin(ctx, cmd, command, service)
6561
if err != nil {
@@ -148,9 +144,18 @@ func (s *composeService) executePlugin(ctx context.Context, cmd *exec.Cmd, comma
148144
return variables, nil
149145
}
150146

151-
func (s *composeService) getPluginBinaryPath(providerType string) (*manager.Plugin, error) {
152-
// Only support Docker CLI plugins for first iteration. Could support any binary from PATH
153-
return manager.GetPlugin(providerType, s.dockerCli, &cobra.Command{})
147+
func (s *composeService) getPluginBinaryPath(provider string) (path string, err error) {
148+
if provider == "compose" {
149+
return "", errors.New("'compose' is not a valid provider type")
150+
}
151+
plugin, err := manager.GetPlugin(provider, s.dockerCli, &cobra.Command{})
152+
if err == nil {
153+
path = plugin.Path
154+
}
155+
if manager.IsNotFound(err) {
156+
path, err = exec.LookPath(provider)
157+
}
158+
return path, err
154159
}
155160

156161
func (s *composeService) setupPluginCommand(ctx context.Context, project *types.Project, service types.ServiceConfig, path, command string) *exec.Cmd {
@@ -182,24 +187,3 @@ func (s *composeService) setupPluginCommand(ctx context.Context, project *types.
182187
cmd.Env = append(cmd.Env, types.Mapping(carrier).Values()...)
183188
return cmd
184189
}
185-
186-
func (s *composeService) checkPluginEnabledInDD(ctx context.Context, plugin *manager.Plugin) error {
187-
if integrationEnabled := s.isDesktopIntegrationActive(); !integrationEnabled {
188-
return fmt.Errorf("you should enable Docker Desktop integration to use %q provider services", plugin.Name)
189-
}
190-
191-
// Until we support more use cases, check explicitly status of model runner
192-
if plugin.Name == "model" {
193-
cmd := exec.CommandContext(ctx, "docker", "model", "status")
194-
_, err := cmd.CombinedOutput()
195-
if err != nil {
196-
var exitErr *exec.ExitError
197-
if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 {
198-
return fmt.Errorf("you should enable model runner to use %q provider services: %s", plugin.Name, err.Error())
199-
}
200-
}
201-
} else {
202-
return fmt.Errorf("unsupported provider %q", plugin.Name)
203-
}
204-
return nil
205-
}

0 commit comments

Comments
 (0)