Skip to content

Commit

Permalink
fix: use tmp dir for local socks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpuljak committed Mar 6, 2024
1 parent 4790661 commit bfb529a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ import (
"path"
"provider/pkg/ssh_tunnel/util"
"provider/pkg/types"
"runtime"
"strings"

"github.com/docker/docker/client"

log "github.com/sirupsen/logrus"
)

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

return getRemoteClient(targetOptions, pluginPath)
return getRemoteClient(targetOptions)
}

func getLocalClient() (*client.Client, error) {
Expand All @@ -31,8 +32,8 @@ func getLocalClient() (*client.Client, error) {
return cli, nil
}

func getRemoteClient(targetOptions types.TargetOptions, pluginPath string) (*client.Client, error) {
localSockPath, err := forwardDockerSock(targetOptions, pluginPath)
func getRemoteClient(targetOptions types.TargetOptions) (*client.Client, error) {
localSockPath, err := forwardDockerSock(targetOptions)
if err != nil {
return nil, err
}
Expand All @@ -45,8 +46,16 @@ func getRemoteClient(targetOptions types.TargetOptions, pluginPath string) (*cli
return cli, nil
}

func forwardDockerSock(targetOptions types.TargetOptions, pluginPath string) (string, error) {
localSockPath := path.Join(pluginPath, "target-socks", fmt.Sprintf("daytona-%s-docker.sock", strings.ReplaceAll(*targetOptions.RemoteHostname, ".", "-")))
func forwardDockerSock(targetOptions types.TargetOptions) (string, error) {
tmpDir := "/tmp"
if runtime.GOOS == "windows" {
tmpDir = os.TempDir()
if tmpDir == "" {
return "", fmt.Errorf("could not determine temp dir")
}
}

localSockPath := path.Join(tmpDir, "target-socks", fmt.Sprintf("daytona-%s-docker.sock", strings.ReplaceAll(*targetOptions.RemoteHostname, ".", "-")))

if _, err := os.Stat(path.Dir(localSockPath)); err != nil {
err := os.MkdirAll(path.Dir(localSockPath), 0755)
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,5 @@ func (p DockerProvider) getClient(targetOptionsJson string) (*docker_client.Clie
return nil, err
}

return client.GetClient(*targetOptions, *p.BasePath)
return client.GetClient(*targetOptions)
}

0 comments on commit bfb529a

Please sign in to comment.