Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add sock file path as target param #4

Merged
merged 1 commit into from
Mar 7, 2024
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
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