Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit 649fb4e

Browse files
author
Piotr Stankiewicz
committed
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 <[email protected]>
1 parent ede328c commit 649fb4e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

desktop/context.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/docker/model-cli/pkg/standalone"
1818
"github.com/docker/model-cli/pkg/types"
1919
"github.com/docker/model-runner/pkg/inference"
20+
"github.com/pkg/errors"
2021
)
2122

2223
// 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
115116
treatDesktopAsMoby := os.Getenv("_MODEL_RUNNER_TREAT_DESKTOP_AS_MOBY") == "1"
116117

117118
// Detect the associated engine type.
118-
kind := types.ModelRunnerEngineKindMoby
119-
if modelRunnerHost != "" {
119+
kind := types.ModelRunnerEngineKindUnknown
120+
if runtime.GOOS == "linux" {
121+
kind = types.ModelRunnerEngineKindMoby
122+
}
123+
124+
if modelRunnerHost != "" && kind == types.ModelRunnerEngineKindMoby {
120125
kind = types.ModelRunnerEngineKindMobyManual
121126
} else if isDesktopContext(ctx, cli) {
122127
kind = types.ModelRunnerEngineKindDesktop
@@ -127,6 +132,10 @@ func DetectContext(ctx context.Context, cli *command.DockerCli) (*ModelRunnerCon
127132
kind = types.ModelRunnerEngineKindCloud
128133
}
129134

135+
if kind == types.ModelRunnerEngineKindUnknown {
136+
return nil, errors.New("unable to determine docker engine type")
137+
}
138+
130139
// Compute the URL prefix based on the associated engine kind.
131140
var rawURLPrefix string
132141
if kind == types.ModelRunnerEngineKindMoby {

pkg/types/engine.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ package types
55
type ModelRunnerEngineKind uint8
66

77
const (
8+
// ModelRunnerEngineKindUnknown represents an engine whose type can not be
9+
// determined.
10+
ModelRunnerEngineKindUnknown ModelRunnerEngineKind = iota
811
// ModelRunnerEngineKindMoby represents a non-Desktop/Cloud engine on which
912
// the Model CLI command is responsible for managing a Model Runner.
10-
ModelRunnerEngineKindMoby ModelRunnerEngineKind = iota
13+
ModelRunnerEngineKindMoby
1114
// ModelRunnerEngineKindMobyManual represents a non-Desktop/Cloud engine
1215
// that's explicitly targeted by a MODEL_RUNNER_HOST environment variable on
1316
// which the user is responsible for managing a Model Runner.

0 commit comments

Comments
 (0)