diff --git a/go.mod b/go.mod index 4edbd8b..4fb26cf 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.22.0 + github.com/daytonaio/daytona v0.23.0 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 f7c2023..4f87629 100644 --- a/go.sum +++ b/go.sum @@ -732,6 +732,8 @@ github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454Wv github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE= github.com/daytonaio/daytona v0.22.0 h1:JW9VY3iNZv0lAc06hux5hnJBaCQnmti35D4ZGKT7OjU= 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/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/provider.go b/pkg/provider/provider.go index 22a49ce..295c3ba 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -93,20 +93,13 @@ func (p *FlyProvider) CreateWorkspace(workspaceReq *provider.WorkspaceRequest) ( return nil, err } - envVars := workspace.GetWorkspaceEnvVars(workspaceReq.Workspace, workspace.WorkspaceEnvVarParams{ - ApiUrl: *p.ApiUrl, - ApiKey: workspaceReq.Workspace.ApiKey, - ServerUrl: *p.ServerUrl, - ServerVersion: *p.DaytonaVersion, - }) - initScript := fmt.Sprintf(`apk add --no-cache curl bash && \ curl -sfL -H "Authorization: Bearer %s" %s | bash`, workspaceReq.Workspace.ApiKey, *p.DaytonaDownloadUrl, ) - machine, err := flyutil.CreateWorkspace(workspaceReq.Workspace, targetOptions, envVars, initScript) + machine, err := flyutil.CreateWorkspace(workspaceReq.Workspace, targetOptions, initScript) if err != nil { logWriter.Write([]byte("Failed to create workspace: " + err.Error() + "\n")) return nil, err diff --git a/pkg/provider/provider_test.go b/pkg/provider/provider_test.go index b646a2a..767f87c 100644 --- a/pkg/provider/provider_test.go +++ b/pkg/provider/provider_test.go @@ -22,7 +22,7 @@ var ( Size: "shared-cpu-4x", DiskSize: 10, OrgSlug: orgSlug, - AuthToken: &authToken, + AuthToken: authToken, } workspaceReq *provider.WorkspaceRequest diff --git a/pkg/provider/util/fly.go b/pkg/provider/util/fly.go index 533195d..6f63265 100644 --- a/pkg/provider/util/fly.go +++ b/pkg/provider/util/fly.go @@ -18,9 +18,9 @@ import ( ) // CreateWorkspace creates a new fly.io app for the provided workspace. -func CreateWorkspace(workspace *workspace.Workspace, opts *types.TargetOptions, envVars map[string]string, initScript string) (*fly.Machine, error) { +func CreateWorkspace(workspace *workspace.Workspace, opts *types.TargetOptions, initScript string) (*fly.Machine, error) { appName := getResourceName(workspace.Id) - flapsClient, err := createFlapsClient(appName, *opts.AuthToken) + flapsClient, err := createFlapsClient(appName, opts.AuthToken) if err != nil { return nil, err } @@ -35,7 +35,7 @@ func CreateWorkspace(workspace *workspace.Workspace, opts *types.TargetOptions, return nil, err } - machine, err := createMachine(workspace, opts, envVars, initScript) + machine, err := createMachine(workspace, opts, initScript) if err != nil { return nil, err } @@ -51,7 +51,7 @@ func CreateWorkspace(workspace *workspace.Workspace, opts *types.TargetOptions, // StartWorkspace starts the machine for the provided workspace. func StartWorkspace(workspace *workspace.Workspace, opts *types.TargetOptions) error { appName := getResourceName(workspace.Id) - flapsClient, err := createFlapsClient(appName, *opts.AuthToken) + flapsClient, err := createFlapsClient(appName, opts.AuthToken) if err != nil { return err } @@ -81,7 +81,7 @@ func StartWorkspace(workspace *workspace.Workspace, opts *types.TargetOptions) e // StopWorkspace stops the machine for the provided workspace. func StopWorkspace(workspace *workspace.Workspace, opts *types.TargetOptions) error { appName := getResourceName(workspace.Id) - flapsClient, err := createFlapsClient(appName, *opts.AuthToken) + flapsClient, err := createFlapsClient(appName, opts.AuthToken) if err != nil { return err } @@ -98,7 +98,7 @@ func StopWorkspace(workspace *workspace.Workspace, opts *types.TargetOptions) er // DeleteWorkspace deletes the app associated with the provided workspace. func DeleteWorkspace(workspace *workspace.Workspace, opts *types.TargetOptions) error { appName := getResourceName(workspace.Id) - flapsClient, err := createFlapsClient(appName, *opts.AuthToken) + flapsClient, err := createFlapsClient(appName, opts.AuthToken) if err != nil { return err } @@ -124,9 +124,9 @@ func DeleteWorkspace(workspace *workspace.Workspace, opts *types.TargetOptions) } // createMachine creates a new machine for the provided workspace. -func createMachine(workspace *workspace.Workspace, opts *types.TargetOptions, envVars map[string]string, initScript string) (*fly.Machine, error) { +func createMachine(workspace *workspace.Workspace, opts *types.TargetOptions, initScript string) (*fly.Machine, error) { appName := getResourceName(workspace.Id) - flapsClient, err := createFlapsClient(appName, *opts.AuthToken) + flapsClient, err := createFlapsClient(appName, opts.AuthToken) if err != nil { return nil, err } @@ -176,7 +176,7 @@ su daytona -c "daytona agent --host" Init: fly.MachineInit{ Entrypoint: []string{"/bin/sh", "-c", script}, }, - Env: envVars, + Env: workspace.EnvVars, }, Region: opts.Region, }) @@ -185,7 +185,7 @@ su daytona -c "daytona agent --host" // GetMachine returns the machine for the provided workspace. func GetMachine(workspace *workspace.Workspace, opts *types.TargetOptions) (*fly.Machine, error) { appName := getResourceName(workspace.Id) - flapsClient, err := createFlapsClient(appName, *opts.AuthToken) + flapsClient, err := createFlapsClient(appName, opts.AuthToken) if err != nil { return nil, err } @@ -200,7 +200,7 @@ func GetWorkspaceLogs(workspace *workspace.Workspace, opts *types.TargetOptions, fly.SetBaseURL("https://api.fly.io") client := fly.NewClientFromOptions(fly.ClientOptions{ - Tokens: tokens.Parse(*opts.AuthToken), + Tokens: tokens.Parse(opts.AuthToken), Name: appName, Version: internal.Version, }) diff --git a/pkg/types/targets.go b/pkg/types/targets.go index 688c6c5..b1e322c 100644 --- a/pkg/types/targets.go +++ b/pkg/types/targets.go @@ -9,11 +9,11 @@ import ( ) type TargetOptions struct { - Region string `json:"Region"` - Size string `json:"Size"` - DiskSize int `json:"Disk Size"` - OrgSlug string `json:"Org Slug"` - AuthToken *string `json:"Auth Token,omitempty"` + Region string `json:"Region"` + Size string `json:"Size"` + DiskSize int `json:"Disk Size"` + OrgSlug string `json:"Org Slug"` + AuthToken string `json:"Auth Token,omitempty"` } func GetTargetManifest() *provider.ProviderTargetManifest { @@ -53,15 +53,15 @@ func ParseTargetOptions(optionsJson string) (*TargetOptions, error) { return nil, err } - if targetOptions.AuthToken == nil { + if targetOptions.AuthToken == "" { // Fetch token from environment variable token, ok := os.LookupEnv("FLY_ACCESS_TOKEN") if ok { - targetOptions.AuthToken = &token + targetOptions.AuthToken = token } } - if targetOptions.AuthToken == nil { + if targetOptions.AuthToken == "" { return nil, fmt.Errorf("auth token not set in env/target options") }