@@ -7,11 +7,11 @@ import (
77 "os"
88 "strconv"
99
10- "github.com/docker/model-runner/cmd/cli/pkg/types"
11-
1210 "github.com/docker/cli/cli-plugins/hooks"
1311 "github.com/docker/model-runner/cmd/cli/commands/completion"
1412 "github.com/docker/model-runner/cmd/cli/desktop"
13+ "github.com/docker/model-runner/cmd/cli/pkg/standalone"
14+ "github.com/docker/model-runner/cmd/cli/pkg/types"
1515 "github.com/spf13/cobra"
1616)
1717
@@ -21,7 +21,7 @@ func newStatusCmd() *cobra.Command {
2121 Use : "status" ,
2222 Short : "Check if the Docker Model Runner is running" ,
2323 RunE : func (cmd * cobra.Command , args []string ) error {
24- standalone , err := ensureStandaloneRunnerAvailable (cmd .Context (), asPrinter (cmd ), false )
24+ runner , err := ensureStandaloneRunnerAvailable (cmd .Context (), asPrinter (cmd ), false )
2525 if err != nil {
2626 return fmt .Errorf ("unable to initialize standalone model runner: %w" , err )
2727 }
@@ -40,7 +40,7 @@ func newStatusCmd() *cobra.Command {
4040 }
4141
4242 if formatJson {
43- return jsonStatus (standalone , status , backendStatus )
43+ return jsonStatus (asPrinter ( cmd ), runner , status , backendStatus )
4444 } else {
4545 textStatus (cmd , status , backendStatus )
4646 }
@@ -69,44 +69,58 @@ func textStatus(cmd *cobra.Command, status desktop.Status, backendStatus map[str
6969 }
7070}
7171
72- func jsonStatus (standalone * standaloneRunner , status desktop.Status , backendStatus map [string ]string ) error {
72+ func makeEndpoint (host string , port int ) string {
73+ return "http://" + net .JoinHostPort (host , strconv .Itoa (port )) + "/v1/"
74+ }
75+
76+ func jsonStatus (printer standalone.StatusPrinter , runner * standaloneRunner , status desktop.Status , backendStatus map [string ]string ) error {
7377 type Status struct {
74- Running bool `json:"running"`
75- Backends map [string ]string `json:"backends"`
76- Endpoint string `json:"endpoint"`
78+ Running bool `json:"running"`
79+ Backends map [string ]string `json:"backends"`
80+ Kind string `json:"kind"`
81+ Endpoint string `json:"endpoint"`
82+ EndpointHost string `json:"endpointHost"`
7783 }
78- var endpoint string
84+ var endpoint , endpointHost string
7985 kind := modelRunner .EngineKind ()
8086 switch kind {
8187 case types .ModelRunnerEngineKindDesktop :
82- endpoint = "http://model-runner.docker.internal/engines/v1/"
88+ endpoint = "http://model-runner.docker.internal/v1/"
89+ endpointHost = modelRunner .URL ("/v1/" )
8390 case types .ModelRunnerEngineKindMobyManual :
84- endpoint = modelRunner .URL ("/engines/v1/" )
91+ endpoint = modelRunner .URL ("/v1/" )
92+ endpointHost = endpoint
8593 case types .ModelRunnerEngineKindCloud :
86- fallthrough
87- case types .ModelRunnerEngineKindMoby :
88- if standalone .gatewayIP == "" {
89- standalone .gatewayIP = "127.0.0.1"
90- }
91-
92- if standalone .gatewayPort == 0 {
93- standalone .gatewayPort = 12434
94+ gatewayIP := "127.0.0.1"
95+ var gatewayPort uint16 = standalone .DefaultControllerPortCloud
96+ if runner != nil {
97+ if runner .gatewayIP != "" {
98+ gatewayIP = runner .gatewayIP
99+ }
100+ if runner .gatewayPort != 0 {
101+ gatewayPort = runner .gatewayPort
102+ }
94103 }
95-
96- endpoint = "http://" + net .JoinHostPort (standalone .gatewayIP , strconv .Itoa (int (standalone .gatewayPort ))) + "/engines/v1/"
104+ endpoint = makeEndpoint (gatewayIP , int (gatewayPort ))
105+ endpointHost = makeEndpoint ("127.0.0.1" , standalone .DefaultControllerPortCloud )
106+ case types .ModelRunnerEngineKindMoby :
107+ endpoint = makeEndpoint ("host.docker.internal" , standalone .DefaultControllerPortMoby )
108+ endpointHost = makeEndpoint ("127.0.0.1" , standalone .DefaultControllerPortMoby )
97109 default :
98110 return fmt .Errorf ("unhandled engine kind: %v" , kind )
99111 }
100112 s := Status {
101- Running : status .Running ,
102- Backends : backendStatus ,
103- Endpoint : endpoint ,
113+ Running : status .Running ,
114+ Backends : backendStatus ,
115+ Kind : kind .String (),
116+ Endpoint : endpoint ,
117+ EndpointHost : endpointHost ,
104118 }
105119 marshal , err := json .Marshal (s )
106120 if err != nil {
107121 return err
108122 }
109- fmt .Println (string (marshal ))
123+ printer .Println (string (marshal ))
110124 return nil
111125}
112126
0 commit comments