Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions commands/status.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commands

import (
"encoding/json"
"os"

"github.com/docker/cli/cli-plugins/hooks"
Expand All @@ -20,6 +21,16 @@ func newStatusCmd(desktopClient *desktop.Client) *cobra.Command {
}
if status.Running {
cmd.Println("Docker Model Runner is running")
cmd.Println("\nStatus:")
var backendStatus map[string]string
if err := json.Unmarshal(status.Status, &backendStatus); err != nil {
cmd.PrintErrln(string(status.Status))
}
for b, s := range backendStatus {
if s != "not running" {
cmd.Println(b+":", s)
}
}
} else {
cmd.Println("Docker Model Runner is not running")
hooks.PrintNextSteps(cmd.OutOrStdout(), []string{enableViaCLI, enableViaGUI})
Expand Down
9 changes: 8 additions & 1 deletion commands/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ func TestStatus(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
client := mockdesktop.NewMockDockerHttpClient(ctrl)

req, err := http.NewRequest(http.MethodGet, desktop.URL(inference.ModelsPrefix), nil)
require.NoError(t, err)
client.EXPECT().Do(req).Return(test.doResponse, test.doErr)

if test.doResponse != nil && test.doResponse.StatusCode == http.StatusOK {
req, err = http.NewRequest(http.MethodGet, desktop.URL(inference.InferencePrefix+"/status"), nil)
require.NoError(t, err)
client.EXPECT().Do(req).Return(&http.Response{Body: mockBody}, test.doErr)
}

originalOsExit := osExit
exitCalled := false
osExit = func(code int) {
Expand All @@ -106,7 +113,7 @@ func TestStatus(t *testing.T) {
require.EqualError(t, err, test.expectedErr.Error())
} else {
require.NoError(t, err)
require.Equal(t, test.expectedOutput, buf.String())
require.True(t, strings.HasPrefix(buf.String(), test.expectedOutput))
}
})
}
Expand Down
19 changes: 17 additions & 2 deletions desktop/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ func New(dockerClient DockerHttpClient) *Client {
}

type Status struct {
Running bool `json:"running"`
Error error `json:"error"`
Running bool `json:"running"`
Status []byte `json:"status"`
Error error `json:"error"`
}

func (c *Client) Status() Status {
Expand All @@ -70,8 +71,22 @@ func (c *Client) Status() Status {
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
var status []byte
statusResp, err := c.doRequest(http.MethodGet, inference.InferencePrefix+"/status", nil)
if err != nil {
status = []byte(fmt.Sprintf("error querying status: %v", err))
} else {
defer statusResp.Body.Close()
statusBody, err := io.ReadAll(statusResp.Body)
if err != nil {
status = []byte(fmt.Sprintf("error reading status body: %v", err))
} else {
status = statusBody
}
}
return Status{
Running: true,
Status: status,
}
}
return Status{
Expand Down