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 0141b38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"errors"
"fmt"
"os"
"path"
Expand All @@ -14,12 +15,12 @@ import (
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,13 @@ 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 := os.TempDir()
if tmpDir == "" {
return "", errors.New("could not find 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 0141b38

Please sign in to comment.