mirror of
https://github.com/docker/compose.git
synced 2025-07-30 17:14:13 +02:00
plugin provider support: check docker model runner status
Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
parent
bf71138df6
commit
096b1e32d3
@ -50,12 +50,16 @@ const (
|
|||||||
func (s *composeService) runPlugin(ctx context.Context, project *types.Project, service types.ServiceConfig, command string) error {
|
func (s *composeService) runPlugin(ctx context.Context, project *types.Project, service types.ServiceConfig, command string) error {
|
||||||
provider := *service.Provider
|
provider := *service.Provider
|
||||||
|
|
||||||
path, err := s.getPluginBinaryPath(provider.Type)
|
plugin, err := s.getPluginBinaryPath(provider.Type)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := s.setupPluginCommand(ctx, project, provider, path, command)
|
if err := s.checkPluginEnabledInDD(ctx, plugin); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := s.setupPluginCommand(ctx, project, provider, plugin.Path, command)
|
||||||
|
|
||||||
eg := errgroup.Group{}
|
eg := errgroup.Group{}
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
@ -121,13 +125,9 @@ func (s *composeService) runPlugin(ctx context.Context, project *types.Project,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) getPluginBinaryPath(providerType string) (string, error) {
|
func (s *composeService) getPluginBinaryPath(providerType string) (*manager.Plugin, error) {
|
||||||
// Only support Docker CLI plugins for first iteration. Could support any binary from PATH
|
// Only support Docker CLI plugins for first iteration. Could support any binary from PATH
|
||||||
plugin, err := manager.GetPlugin(providerType, s.dockerCli, &cobra.Command{})
|
return manager.GetPlugin(providerType, s.dockerCli, &cobra.Command{})
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return plugin.Path, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) setupPluginCommand(ctx context.Context, project *types.Project, provider types.ServiceProviderConfig, path, command string) *exec.Cmd {
|
func (s *composeService) setupPluginCommand(ctx context.Context, project *types.Project, provider types.ServiceProviderConfig, path, command string) *exec.Cmd {
|
||||||
@ -142,7 +142,7 @@ func (s *composeService) setupPluginCommand(ctx context.Context, project *types.
|
|||||||
|
|
||||||
// Use docker/cli mechanism to propagate termination signal to child process
|
// Use docker/cli mechanism to propagate termination signal to child process
|
||||||
server, err := socket.NewPluginServer(nil)
|
server, err := socket.NewPluginServer(nil)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
defer server.Close() //nolint:errcheck
|
defer server.Close() //nolint:errcheck
|
||||||
cmd.Cancel = server.Close
|
cmd.Cancel = server.Close
|
||||||
cmd.Env = replace(cmd.Env, socket.EnvKey, server.Addr().String())
|
cmd.Env = replace(cmd.Env, socket.EnvKey, server.Addr().String())
|
||||||
@ -156,3 +156,24 @@ func (s *composeService) setupPluginCommand(ctx context.Context, project *types.
|
|||||||
cmd.Env = append(cmd.Env, types.Mapping(carrier).Values()...)
|
cmd.Env = append(cmd.Env, types.Mapping(carrier).Values()...)
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *composeService) checkPluginEnabledInDD(ctx context.Context, plugin *manager.Plugin) error {
|
||||||
|
if integrationEnabled := s.isDesktopIntegrationActive(); !integrationEnabled {
|
||||||
|
return fmt.Errorf("you should enable Docker Desktop integration to use %q provider services", plugin.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Until we support more use cases, check explicitly status of model runner
|
||||||
|
if plugin.Name == "model" {
|
||||||
|
cmd := exec.CommandContext(ctx, "docker", "model", "status")
|
||||||
|
_, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
var exitErr *exec.ExitError
|
||||||
|
if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 {
|
||||||
|
return fmt.Errorf("you should enable model runner to use %q provider services: %s", plugin.Name, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("unsupported provider %q", plugin.Name)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user