Skip to content

Commit e9b69f9

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

1 file changed

Lines changed: 13 additions & 29 deletions

File tree

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
eg := errgroup.Group{}
6561
stdout, err := cmd.StdoutPipe()
@@ -125,9 +121,18 @@ func (s *composeService) runPlugin(ctx context.Context, project *types.Project,
125121
return nil
126122
}
127123

128-
func (s *composeService) getPluginBinaryPath(providerType string) (*manager.Plugin, error) {
129-
// Only support Docker CLI plugins for first iteration. Could support any binary from PATH
130-
return manager.GetPlugin(providerType, s.dockerCli, &cobra.Command{})
124+
func (s *composeService) getPluginBinaryPath(provider string) (path string, err error) {
125+
if provider == "compose" {
126+
return "", errors.New("'compose' is not a valid provider type")
127+
}
128+
plugin, err := manager.GetPlugin(provider, s.dockerCli, &cobra.Command{})
129+
if err == nil {
130+
path = plugin.Path
131+
}
132+
if manager.IsNotFound(err) {
133+
path, err = exec.LookPath(provider)
134+
}
135+
return path, err
131136
}
132137

133138
func (s *composeService) setupPluginCommand(ctx context.Context, project *types.Project, service types.ServiceConfig, path, command string) *exec.Cmd {
@@ -159,24 +164,3 @@ func (s *composeService) setupPluginCommand(ctx context.Context, project *types.
159164
cmd.Env = append(cmd.Env, types.Mapping(carrier).Values()...)
160165
return cmd
161166
}
162-
163-
func (s *composeService) checkPluginEnabledInDD(ctx context.Context, plugin *manager.Plugin) error {
164-
if integrationEnabled := s.isDesktopIntegrationActive(); !integrationEnabled {
165-
return fmt.Errorf("you should enable Docker Desktop integration to use %q provider services", plugin.Name)
166-
}
167-
168-
// Until we support more use cases, check explicitly status of model runner
169-
if plugin.Name == "model" {
170-
cmd := exec.CommandContext(ctx, "docker", "model", "status")
171-
_, err := cmd.CombinedOutput()
172-
if err != nil {
173-
var exitErr *exec.ExitError
174-
if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 {
175-
return fmt.Errorf("you should enable model runner to use %q provider services: %s", plugin.Name, err.Error())
176-
}
177-
}
178-
} else {
179-
return fmt.Errorf("unsupported provider %q", plugin.Name)
180-
}
181-
return nil
182-
}

0 commit comments

Comments
 (0)