Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
go.opentelemetry.io/otel/sdk v1.37.0
go.opentelemetry.io/otel/sdk/metric v1.37.0
go.uber.org/mock v0.5.2
golang.ngrok.com/ngrok/v2 v2.0.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change still needed?

golang.org/x/exp/jsonrpc2 v0.0.0-20250718183923-645b1fa84792
golang.org/x/mod v0.27.0
golang.org/x/oauth2 v0.30.0
Expand Down Expand Up @@ -238,7 +239,6 @@ require (
go.uber.org/zap v1.27.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.ngrok.com/muxado/v2 v2.0.1 // indirect
golang.ngrok.com/ngrok/v2 v2.0.0 // indirect
golang.org/x/exp/event v0.0.0-20250620022241-b7579e27df2b // indirect
golang.org/x/net v0.42.0 // indirect
golang.org/x/text v0.27.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/vault/api v1.16.0 h1:nbEYGJiAPGzT9U4oWgaaB0g+Rj8E59QuHKyA5LhwQN4=
github.com/hashicorp/vault/api v1.16.0/go.mod h1:KhuUhzOD8lDSk29AtzNjgAu2kxRA9jL9NAbkFlqvkBA=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef h1:A9HsByNhogrvm9cWb28sjiS3i7tcKCkflWFEkHfuAgM=
github.com/howeyc/gopass v0.0.0-20210920133722-c8aef6fb66ef/go.mod h1:lADxMC39cJJqL93Duh1xhAs4I2Zs8mKS89XWXFGp9cs=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
Expand Down
43 changes: 43 additions & 0 deletions pkg/container/docker/sdk/client_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ func findPlatformContainerSocket(rt runtime.Type) (string, runtime.Type, error)
return customSocketPath, runtime.TypeDocker, nil
}

if customSocketPath := os.Getenv(ColimaSocketEnv); customSocketPath != "" {
logger.Debugf("Using Colima socket from env: %s", customSocketPath)
// validate the socket path
if _, err := os.Stat(customSocketPath); err != nil {
return "", runtime.TypeDocker, fmt.Errorf("invalid Colima socket path: %w", err)
}
return customSocketPath, runtime.TypeDocker, nil
}

if rt == runtime.TypePodman {
socketPath, err := findPodmanSocket()
if err == nil {
Expand All @@ -76,6 +85,13 @@ func findPlatformContainerSocket(rt runtime.Type) (string, runtime.Type, error)
}
}

if rt == runtime.TypeColima {
socketPath, err := findColimaSocket()
if err == nil {
return socketPath, runtime.TypeColima, nil
}
}

return "", "", ErrRuntimeNotFound
}

Expand Down Expand Up @@ -159,3 +175,30 @@ func findDockerSocket() (string, error) {

return "", fmt.Errorf("docker socket not found in standard locations")
}

// findColimaSocket attempts to locate a Colima socket
func findColimaSocket() (string, error) {
// Check standard Colima location
_, err := os.Stat(ColimaDesktopMacSocketPath)
if err == nil {
logger.Debugf("Found Colima socket at %s", ColimaDesktopMacSocketPath)
return ColimaDesktopMacSocketPath, nil
}

logger.Debugf("Failed to check Colima socket at %s: %v", ColimaDesktopMacSocketPath, err)

// Check user-specific location for Colima
if home := os.Getenv("HOME"); home != "" {
userSocketPath := filepath.Join(home, ColimaDesktopMacSocketPath)
_, err := os.Stat(userSocketPath)

if err == nil {
logger.Debugf("Found Colima socket at %s", userSocketPath)
return userSocketPath, nil
}

logger.Debugf("Failed to check Colima socket at %s: %v", userSocketPath, err)
}

return "", fmt.Errorf("colima socket not found in standard locations")
}
6 changes: 5 additions & 1 deletion pkg/container/docker/sdk/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
DockerSocketEnv = "TOOLHIVE_DOCKER_SOCKET"
// PodmanSocketEnv is the environment variable for custom Podman socket path
PodmanSocketEnv = "TOOLHIVE_PODMAN_SOCKET"
// ColimaSocketEnv is the environment variable for custom Colima socket path
ColimaSocketEnv = "TOOLHIVE_COLIMA_SOCKET"
)

// Common socket paths
Expand All @@ -36,9 +38,11 @@ const (
DockerDesktopMacSocketPath = ".docker/run/docker.sock"
// RancherDesktopMacSocketPath is the Docker socket path for Rancher Desktop on macOS
RancherDesktopMacSocketPath = ".rd/docker.sock"
// ColimaDesktopMacSocketPath is the Docker socket path for Colima on macOS
ColimaDesktopMacSocketPath = ".colima/default/docker.sock"
)

var supportedSocketPaths = []runtime.Type{runtime.TypePodman, runtime.TypeDocker}
var supportedSocketPaths = []runtime.Type{runtime.TypePodman, runtime.TypeDocker, runtime.TypeColima}

// NewDockerClient creates a new container client
func NewDockerClient(ctx context.Context) (*client.Client, string, runtime.Type, error) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/container/runtime/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ const (
TypeDocker Type = "docker"
// TypeKubernetes represents the Kubernetes runtime
TypeKubernetes Type = "kubernetes"
// TypeColima represents the Colima runtime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be necessary - it looks like you are using the Docker runtime to connect to Colima. This enum is used for different implementations of our runtime interface.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In review, I'm checking in the Docker runtime if there is a path override in the Docker runtime check, but I'm also checking explicitly if its Colima:
https://github.com/stacklok/toolhive/pull/1332/files#diff-d58624f599f4b93a4c84d22c3d24888c6a2c57855eb451ccc72815d5cda9667bR88-R94

I'd like not to remove this, because if I do, then the user has to know and explicitly override the Docker socket to the Colima socket, which requires discovery of this in the docs or otherwise.

What are your thoughts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the Colima check from there and instead add it to findDockerSocket, similar to what we currently have for Rancher Desktop:

// Try Rancher Desktop socket path on macOS
if home := os.Getenv("HOME"); home != "" {
rancherDesktopPath := filepath.Join(home, RancherDesktopMacSocketPath)
_, err := os.Stat(rancherDesktopPath)
if err == nil {
logger.Debugf("Found Rancher Desktop socket at %s", rancherDesktopPath)
return rancherDesktopPath, nil
}
logger.Debugf("Failed to check Rancher Desktop socket at %s: %v", rancherDesktopPath, err)
}

With that you'll be able to remove all the other changes to client_unix.go.

TypeColima Type = "colima"
)

// MountType represents the type of mount
Expand Down
Loading