From 649fb4e2ec8ab595537a226a174ee7d06d996cf9 Mon Sep 17 00:00:00 2001 From: Piotr Stankiewicz Date: Wed, 16 Jul 2025 15:22:40 +0200 Subject: [PATCH] Improve engine type detection In some cases we may end up misidentifying the underlying engine type. Improve the logic for doing that to make it impossible to identify DD on windows or macos as plain moby. Signed-off-by: Piotr Stankiewicz --- desktop/context.go | 13 +++++++++++-- pkg/types/engine.go | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/desktop/context.go b/desktop/context.go index aa70d837..adfacc25 100644 --- a/desktop/context.go +++ b/desktop/context.go @@ -17,6 +17,7 @@ import ( "github.com/docker/model-cli/pkg/standalone" "github.com/docker/model-cli/pkg/types" "github.com/docker/model-runner/pkg/inference" + "github.com/pkg/errors" ) // isDesktopContext returns true if the CLI instance points to a Docker Desktop @@ -115,8 +116,12 @@ func DetectContext(ctx context.Context, cli *command.DockerCli) (*ModelRunnerCon treatDesktopAsMoby := os.Getenv("_MODEL_RUNNER_TREAT_DESKTOP_AS_MOBY") == "1" // Detect the associated engine type. - kind := types.ModelRunnerEngineKindMoby - if modelRunnerHost != "" { + kind := types.ModelRunnerEngineKindUnknown + if runtime.GOOS == "linux" { + kind = types.ModelRunnerEngineKindMoby + } + + if modelRunnerHost != "" && kind == types.ModelRunnerEngineKindMoby { kind = types.ModelRunnerEngineKindMobyManual } else if isDesktopContext(ctx, cli) { kind = types.ModelRunnerEngineKindDesktop @@ -127,6 +132,10 @@ func DetectContext(ctx context.Context, cli *command.DockerCli) (*ModelRunnerCon kind = types.ModelRunnerEngineKindCloud } + if kind == types.ModelRunnerEngineKindUnknown { + return nil, errors.New("unable to determine docker engine type") + } + // Compute the URL prefix based on the associated engine kind. var rawURLPrefix string if kind == types.ModelRunnerEngineKindMoby { diff --git a/pkg/types/engine.go b/pkg/types/engine.go index b16e5299..7e24b7b2 100644 --- a/pkg/types/engine.go +++ b/pkg/types/engine.go @@ -5,9 +5,12 @@ package types type ModelRunnerEngineKind uint8 const ( + // ModelRunnerEngineKindUnknown represents an engine whose type can not be + // determined. + ModelRunnerEngineKindUnknown ModelRunnerEngineKind = iota // ModelRunnerEngineKindMoby represents a non-Desktop/Cloud engine on which // the Model CLI command is responsible for managing a Model Runner. - ModelRunnerEngineKindMoby ModelRunnerEngineKind = iota + ModelRunnerEngineKindMoby // ModelRunnerEngineKindMobyManual represents a non-Desktop/Cloud engine // that's explicitly targeted by a MODEL_RUNNER_HOST environment variable on // which the user is responsible for managing a Model Runner.