Skip to content

Commit e127942

Browse files
committed
feat: add backend socket path support for various backends and enhance output display
1 parent 0a4848a commit e127942

6 files changed

Lines changed: 108 additions & 7 deletions

File tree

cmd/ggo/studio/studio.go

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,26 @@ func getOutput() *tui.Output {
141141
return cmdutil.NewOutput(outputFormat)
142142
}
143143

144+
// printBackendAndSocket prints current backend name and container unix sock path to TUI.
145+
func printBackendAndSocket(ctx context.Context, out *tui.Output, mgr *studio.Manager, mode studio.Mode) {
146+
backend, err := mgr.GetBackend(mode)
147+
if err != nil {
148+
return
149+
}
150+
styles := tui.DefaultStyles()
151+
out.Println()
152+
out.Println(styles.Subtitle.Render("Backend"))
153+
sock := "—"
154+
if sp, ok := backend.(studio.BackendSocketPath); ok {
155+
if p := sp.SocketPath(ctx); p != "" {
156+
sock = p
157+
}
158+
}
159+
out.Printf(" Backend: %s\n", backend.Name())
160+
out.Printf(" Container unix sock: %s\n", sock)
161+
out.Println()
162+
}
163+
144164
func newCreateCmd() *cobra.Command {
145165
cmd := &cobra.Command{
146166
Use: "create <name>",
@@ -256,7 +276,20 @@ func runCreate(cmd *cobra.Command, args []string) error {
256276
return err
257277
}
258278

259-
return out.Render(&createResult{env: env, mgr: mgr, noSSH: noSSH})
279+
backendName, socketPath := "", ""
280+
if backend, err := mgr.GetBackend(env.Mode); err == nil {
281+
backendName = backend.Name()
282+
if sp, ok := backend.(studio.BackendSocketPath); ok {
283+
socketPath = sp.SocketPath(ctx)
284+
}
285+
}
286+
return out.Render(&createResult{
287+
env: env,
288+
mgr: mgr,
289+
noSSH: noSSH,
290+
backendName: backendName,
291+
socketPath: socketPath,
292+
})
260293
}
261294

262295
// ensureRemoteGPUClientLibs downloads remote-gpu-client libraries if not already present
@@ -425,9 +458,11 @@ func parseEnvVars(envVars []string) (map[string]string, error) {
425458

426459
// createResult implements Renderable for create command output
427460
type createResult struct {
428-
env *studio.Environment
429-
mgr *studio.Manager
430-
noSSH bool
461+
env *studio.Environment
462+
mgr *studio.Manager
463+
noSSH bool
464+
backendName string
465+
socketPath string
431466
}
432467

433468
func (r *createResult) RenderJSON() any {
@@ -448,7 +483,14 @@ func (r *createResult) RenderTUI(out *tui.Output) {
448483
Add("Mode", string(env.Mode)).
449484
Add("Image", env.Image).
450485
AddWithStatus("Status", string(env.Status), string(env.Status))
451-
486+
if r.backendName != "" {
487+
status = status.Add("Backend", r.backendName)
488+
sock := r.socketPath
489+
if sock == "" {
490+
sock = "—"
491+
}
492+
status = status.Add("Container unix sock", sock)
493+
}
452494
out.Println(status.String())
453495

454496
if env.SSHPort > 0 && !r.noSSH {
@@ -569,6 +611,14 @@ func newStartCmd() *cobra.Command {
569611
mgr := getManager()
570612
out := getOutput()
571613

614+
env, err := mgr.Get(ctx, args[0])
615+
if err != nil {
616+
cmd.SilenceUsage = true
617+
return err
618+
}
619+
if !out.IsJSON() {
620+
printBackendAndSocket(ctx, out, mgr, env.Mode)
621+
}
572622
if err := mgr.Start(ctx, args[0]); err != nil {
573623
cmd.SilenceUsage = true
574624
return err
@@ -593,6 +643,14 @@ func newStopCmd() *cobra.Command {
593643
mgr := getManager()
594644
out := getOutput()
595645

646+
env, err := mgr.Get(ctx, args[0])
647+
if err != nil {
648+
cmd.SilenceUsage = true
649+
return err
650+
}
651+
if !out.IsJSON() {
652+
printBackendAndSocket(ctx, out, mgr, env.Mode)
653+
}
596654
if err := mgr.Stop(ctx, args[0]); err != nil {
597655
cmd.SilenceUsage = true
598656
return err

internal/studio/backend_colima.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ func NewColimaBackendWithProfile(profile string) *ColimaBackend {
4141
}
4242
}
4343

44-
// SetDockerHost sets a custom Docker socket path
44+
// SetDockerHost sets a custom Docker socket path (overrides default Colima socket).
4545
func (b *ColimaBackend) SetDockerHost(dockerHost string) {
46+
if dockerHost == "" {
47+
return
48+
}
4649
b.dockerHost = dockerHost
47-
b.dockerBackend = NewDockerBackend()
50+
b.dockerBackend = NewDockerBackendWithHost(dockerHost)
4851
}
4952

5053
// GetVMArch returns the architecture of the Colima VM
@@ -125,6 +128,11 @@ func (b *ColimaBackend) Mode() Mode {
125128
return ModeColima
126129
}
127130

131+
// SocketPath implements BackendSocketPath.
132+
func (b *ColimaBackend) SocketPath(ctx context.Context) string {
133+
return b.dockerHost
134+
}
135+
128136
func (b *ColimaBackend) IsAvailable(ctx context.Context) bool {
129137
if runtime.GOOS != OSDarwin && runtime.GOOS != OSLinux {
130138
return false

internal/studio/backend_docker.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ func (b *DockerBackend) setDockerEnv(cmd *exec.Cmd) {
7171
}
7272
}
7373

74+
// SocketPath implements BackendSocketPath. Returns the effective Docker socket path.
75+
func (b *DockerBackend) SocketPath(ctx context.Context) string {
76+
if b.dockerHost != "" {
77+
return b.dockerHost
78+
}
79+
if v := os.Getenv("DOCKER_HOST"); v != "" {
80+
return v
81+
}
82+
return "unix:///var/run/docker.sock"
83+
}
84+
7485
// GetHostArch returns the architecture of the Docker host
7586
// Returns "amd64", "arm64", or empty string if detection fails
7687
func (b *DockerBackend) GetHostArch(ctx context.Context) string {

internal/studio/backend_wsl.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ func (b *WSLBackend) Mode() Mode {
5252
return ModeWSL
5353
}
5454

55+
// SocketPath implements BackendSocketPath. Returns the Docker socket path inside the WSL distro.
56+
func (b *WSLBackend) SocketPath(ctx context.Context) string {
57+
distro, err := b.GetDistro(ctx)
58+
if err != nil || distro == "" {
59+
distro = "default"
60+
}
61+
return fmt.Sprintf("WSL (%s): /var/run/docker.sock (inside distro)", distro)
62+
}
63+
5564
func (b *WSLBackend) IsAvailable(ctx context.Context) bool {
5665
if runtime.GOOS != OSWindows {
5766
return false

internal/studio/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ type AutoStartableBackend interface {
229229
EnsureRunning(ctx context.Context) error
230230
}
231231

232+
// BackendSocketPath is an optional interface for backends that use a container unix socket.
233+
// SocketPath returns the backend's container unix socket path (e.g. DOCKER_HOST or docker.sock path).
234+
// Empty string means not applicable (e.g. Apple Container).
235+
type BackendSocketPath interface {
236+
Backend
237+
SocketPath(ctx context.Context) string
238+
}
239+
232240
// SSHConfig represents an SSH configuration entry
233241
type SSHConfig struct {
234242
Host string

scripts/trigger-release.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ if [[ -z "$repo_root" ]]; then
5656
fi
5757

5858
cd "$repo_root"
59+
workflow_test="$repo_root/scripts/build-workflow.test.sh"
60+
if [[ ! -x "$workflow_test" ]]; then
61+
echo "Missing executable $workflow_test" >&2
62+
exit 1
63+
fi
64+
65+
"$workflow_test"
5966
"$gh_cmd" workflow run "$workflow" --ref "$ref"
6067

6168
echo "Triggered $workflow on ref $ref"

0 commit comments

Comments
 (0)