Skip to content

Commit 4f4b6ab

Browse files
authored
Merge pull request #55 from docker/standalone-refinement
standalone: fix Compose hostname for CE/Cloud and implement logs for CE
2 parents 7a9dbe2 + 960c290 commit 4f4b6ab

File tree

4 files changed

+225
-1
lines changed

4 files changed

+225
-1
lines changed

commands/compose.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"errors"
66
"fmt"
77
"slices"
8+
"strconv"
89
"strings"
910

1011
"github.com/docker/model-cli/desktop"
12+
"github.com/docker/model-cli/pkg/standalone"
1113
"github.com/spf13/cobra"
1214
)
1315

@@ -51,7 +53,7 @@ func newUpCommand() *cobra.Command {
5153
_ = setenv("URL", modelRunner.URL("/engines/v1/"))
5254
} else if kind == desktop.ModelRunnerEngineKindMoby || kind == desktop.ModelRunnerEngineKindCloud {
5355
// TODO: Find a more robust solution in Moby-like environments.
54-
_ = setenv("URL", "http://172.17.0.1:12434/engines/v1/")
56+
_ = setenv("URL", "http://host.docker.internal:"+strconv.Itoa(standalone.DefaultControllerPort)+"/engines/v1/")
5557
}
5658
return nil
5759
},

commands/logs.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ package commands
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"io"
78
"os"
89
"os/signal"
910
"path/filepath"
1011
"runtime"
1112

13+
"github.com/docker/docker/api/types/container"
14+
"github.com/docker/docker/pkg/stdcopy"
1215
"github.com/docker/model-cli/commands/completion"
16+
"github.com/docker/model-cli/desktop"
17+
"github.com/docker/model-cli/pkg/standalone"
1318
"github.com/nxadm/tail"
1419
"github.com/spf13/cobra"
1520
"golang.org/x/sync/errgroup"
@@ -26,6 +31,32 @@ func newLogsCmd() *cobra.Command {
2631
return err
2732
}
2833

34+
// If we're running in standalone mode, then print the container
35+
// logs.
36+
if modelRunner.EngineKind() == desktop.ModelRunnerEngineKindMoby {
37+
dockerClient, err := desktop.DockerClientForContext(dockerCLI, dockerCLI.CurrentContext())
38+
if err != nil {
39+
return fmt.Errorf("failed to create Docker client: %w", err)
40+
}
41+
ctrID, _, err := standalone.FindControllerContainer(cmd.Context(), dockerClient)
42+
if err != nil {
43+
return fmt.Errorf("unable to identify Model Runner container: %w", err)
44+
} else if ctrID == "" {
45+
return errors.New("unable to identify Model Runner container")
46+
}
47+
log, err := dockerClient.ContainerLogs(cmd.Context(), ctrID, container.LogsOptions{
48+
ShowStdout: true,
49+
ShowStderr: true,
50+
Follow: follow,
51+
})
52+
if err != nil {
53+
return fmt.Errorf("unable to query Model Runner container logs: %w", err)
54+
}
55+
defer log.Close()
56+
_, err = stdcopy.StdCopy(os.Stdout, os.Stderr, log)
57+
return err
58+
}
59+
2960
var logFilePath string
3061
switch {
3162
case runtime.GOOS == "darwin":

vendor/github.com/docker/docker/pkg/stdcopy/stdcopy.go

Lines changed: 190 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ github.com/docker/docker/internal/multierror
115115
github.com/docker/docker/pkg/atomicwriter
116116
github.com/docker/docker/pkg/homedir
117117
github.com/docker/docker/pkg/jsonmessage
118+
github.com/docker/docker/pkg/stdcopy
118119
github.com/docker/docker/registry
119120
# github.com/docker/docker-credential-helpers v0.9.3
120121
## explicit; go 1.21

0 commit comments

Comments
 (0)