Skip to content

Commit

Permalink
Merge pull request #4 from daytonaio/sock-path-param
Browse files Browse the repository at this point in the history
feat: add sock file path as target param
  • Loading branch information
Tpuljak authored Mar 7, 2024
2 parents 6175037 + 6d5160f commit a37b19b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
20 changes: 17 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,22 @@ import (

func GetClient(targetOptions types.TargetOptions, sockDir string) (*client.Client, error) {
if targetOptions.RemoteHostname == nil {
return getLocalClient()
return getLocalClient(targetOptions)
}

return getRemoteClient(targetOptions, sockDir)
}

func getLocalClient() (*client.Client, error) {
func getLocalClient(targetOptions types.TargetOptions) (*client.Client, error) {
if targetOptions.SockPath != nil && *targetOptions.SockPath != "" {
cli, err := client.NewClientWithOpts(client.WithHost(fmt.Sprintf("unix://%s", *targetOptions.SockPath)), client.WithAPIVersionNegotiation())
if err != nil {
return nil, err
}

return cli, nil
}

cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return nil, err
Expand Down Expand Up @@ -59,11 +68,16 @@ func forwardDockerSock(targetOptions types.TargetOptions, sockDir string) (strin
return localSockPath, nil
}

remoteSockPath := "/var/run/docker.sock"
if targetOptions.SockPath != nil && *targetOptions.SockPath != "" {
remoteSockPath = *targetOptions.SockPath
}

startedChan, errChan := util.ForwardRemoteUnixSock(
context.Background(),
targetOptions,
localSockPath,
"/var/run/docker.sock",
remoteSockPath,
)

go func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (p DockerProvider) GetDefaultTargets() (*[]provider.ProviderTarget, error)
{
Name: "local",
ProviderInfo: info,
Options: "{\"Container Image\": \"daytonaio/workspace-project\"}",
Options: "{\n\t\"Container Image\": \"daytonaio/workspace-project\",\n\t\"Sock Path\": \"/var/run/docker.sock\"\n}",
},
}
return &defaultTargets, nil
Expand Down
5 changes: 5 additions & 0 deletions pkg/types/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type TargetOptions struct {
RemoteUser *string `json:"Remote User,omitempty"`
RemotePassword *string `json:"Remote Password,omitempty"`
RemotePrivateKey *string `json:"Remote Private Key Path,omitempty"`
SockPath *string `json:"Sock Path,omitempty"`
}

func GetTargetManifest() *provider.ProviderTargetManifest {
Expand Down Expand Up @@ -44,6 +45,10 @@ func GetTargetManifest() *provider.ProviderTargetManifest {
DefaultValue: "~/.ssh",
DisabledPredicate: "^local$",
},
"Sock Path": provider.ProviderTargetProperty{
Type: provider.ProviderTargetPropertyTypeString,
DefaultValue: "/var/run/docker.sock",
},
}
}

Expand Down

0 comments on commit a37b19b

Please sign in to comment.