From 4d923e380fa877a357e460d40a304714cab164b1 Mon Sep 17 00:00:00 2001 From: bcmmbaga Date: Thu, 1 Aug 2024 19:33:32 +0300 Subject: [PATCH] chore: refactor docker client Signed-off-by: bcmmbaga --- go.mod | 2 +- go.sum | 2 ++ pkg/provider/conn.go | 38 ++------------------------------------ pkg/provider/provider.go | 12 ------------ pkg/provider/util/fly.go | 7 ++++++- 5 files changed, 11 insertions(+), 50 deletions(-) diff --git a/go.mod b/go.mod index 4fb26cf..d2f81cd 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/daytonaio/daytona-provider-fly go 1.22.2 require ( - github.com/daytonaio/daytona v0.23.0 + github.com/daytonaio/daytona v0.23.1 github.com/docker/docker v26.1.0+incompatible github.com/google/uuid v1.6.0 github.com/hashicorp/go-hclog v1.6.3 diff --git a/go.sum b/go.sum index 4f87629..7ea0cc7 100644 --- a/go.sum +++ b/go.sum @@ -734,6 +734,8 @@ github.com/daytonaio/daytona v0.22.0 h1:JW9VY3iNZv0lAc06hux5hnJBaCQnmti35D4ZGKT7 github.com/daytonaio/daytona v0.22.0/go.mod h1:Wt2JaDzVbwyOKSj4/g//+TQrdZk0WP6IvUgUDanHVHI= github.com/daytonaio/daytona v0.23.0 h1:gwOqjKN/RSe1xhew+CrgefD8I+v53jOy37EBf9CQcmE= github.com/daytonaio/daytona v0.23.0/go.mod h1:8yXvTGwapmO6ygfj2jMR9wWwjbpW7HBGNm8ALAeqFMQ= +github.com/daytonaio/daytona v0.23.1 h1:07ZvgiZWT1kM4X/Iu1cq86p6m8SjIXoVdqw52agOGp8= +github.com/daytonaio/daytona v0.23.1/go.mod h1:8yXvTGwapmO6ygfj2jMR9wWwjbpW7HBGNm8ALAeqFMQ= github.com/dblohm7/wingoes v0.0.0-20231025182615-65d8b4b5428f h1:c5mkOIXbHZVKGQaSEZZyLW9ORD+h4PT2TPF8IQPwyOs= github.com/dblohm7/wingoes v0.0.0-20231025182615-65d8b4b5428f/go.mod h1:6NCrWM5jRefaG7iN0iMShPalLsljHWBh9v1zxM2f8Xs= github.com/digitalocean/go-smbios v0.0.0-20180907143718-390a4f403a8e h1:vUmf0yezR0y7jJ5pceLHthLaYf4bA5T14B6q39S4q2Q= diff --git a/pkg/provider/conn.go b/pkg/provider/conn.go index 3922467..1dd4c0e 100644 --- a/pkg/provider/conn.go +++ b/pkg/provider/conn.go @@ -2,9 +2,7 @@ package provider import ( "context" - "errors" "fmt" - "os" "path/filepath" "time" @@ -13,7 +11,6 @@ import ( "github.com/daytonaio/daytona/pkg/tailscale" "github.com/docker/docker/client" "github.com/google/uuid" - log "github.com/sirupsen/logrus" "tailscale.com/tsnet" ) @@ -63,39 +60,8 @@ func (p *FlyProvider) getDockerClient(workspaceId string) (docker.IDockerClient, return nil, err } - localSockPath := filepath.Join(p.LocalSockDir, workspaceId, "docker-forward.sock") - - if _, err := os.Stat(filepath.Dir(localSockPath)); err != nil { - err := os.MkdirAll(filepath.Dir(localSockPath), 0755) - if err != nil { - return nil, err - } - - startedChan, errChan := tailscale.ForwardRemoteUnixSock(tailscale.ForwardConfig{ - Ctx: context.Background(), - TsnetConn: tsnetConn, - Hostname: workspaceId, - SshPort: config.SSH_PORT, - LocalSock: localSockPath, - RemoteSock: "/var/run/docker.sock", - }) - - go func() { - err := <-errChan - if err != nil { - log.Error(err) - startedChan <- false - _ = os.Remove(localSockPath) - } - }() - - started := <-startedChan - if !started { - return nil, errors.New("failed to start SSH tunnel") - } - } - - cli, err := client.NewClientWithOpts(client.WithHost(fmt.Sprintf("unix://%s", localSockPath)), client.WithAPIVersionNegotiation()) + remoteHost := fmt.Sprintf("tcp://%s:2375", workspaceId) + cli, err := client.NewClientWithOpts(client.WithDialContext(tsnetConn.Dial), client.WithHost(remoteHost), client.WithAPIVersionNegotiation()) if err != nil { return nil, err } diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index 295c3ba..c24fbf1 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -5,9 +5,7 @@ import ( "errors" "fmt" "io" - "os" "path" - "runtime" "time" "github.com/daytonaio/daytona-provider-fly/internal" @@ -36,20 +34,11 @@ type FlyProvider struct { ApiPort *uint32 ServerPort *uint32 LogsDir *string - LocalSockDir string tsnetConn *tsnet.Server } // Initialize initializes the provider with the given configuration. func (p *FlyProvider) Initialize(req provider.InitializeProviderRequest) (*util.Empty, error) { - tmpDir := "/tmp" - if runtime.GOOS == "windows" { - tmpDir = os.TempDir() - if tmpDir == "" { - return nil, errors.New("could not determine temp dir") - } - } - p.BasePath = &req.BasePath p.DaytonaDownloadUrl = &req.DaytonaDownloadUrl p.DaytonaVersion = &req.DaytonaVersion @@ -59,7 +48,6 @@ func (p *FlyProvider) Initialize(req provider.InitializeProviderRequest) (*util. p.ApiPort = &req.ApiPort p.ServerPort = &req.ServerPort p.LogsDir = &req.LogsDir - p.LocalSockDir = path.Join(tmpDir, "fly-socks") return new(util.Empty), nil } diff --git a/pkg/provider/util/fly.go b/pkg/provider/util/fly.go index 6f63265..13bb108 100644 --- a/pkg/provider/util/fly.go +++ b/pkg/provider/util/fly.go @@ -160,6 +160,11 @@ adduser -D -G docker daytona su daytona -c "daytona agent --host" `, initScript) + envVars := workspace.EnvVars + // Disable running docker with TLS + envVars["DOCKER_TLS_VERIFY"] = "" + envVars["DOCKER_TLS_CERTDIR"] = "" + return flapsClient.Launch(context.Background(), fly.LaunchMachineInput{ Name: getResourceName(workspace.Id), Config: &fly.MachineConfig{ @@ -176,7 +181,7 @@ su daytona -c "daytona agent --host" Init: fly.MachineInit{ Entrypoint: []string{"/bin/sh", "-c", script}, }, - Env: workspace.EnvVars, + Env: envVars, }, Region: opts.Region, })