Skip to content

Commit

Permalink
chore: upgrade dependencies
Browse files Browse the repository at this point in the history
Signed-off-by: bcmmbaga <[email protected]>
  • Loading branch information
bcmmbaga committed Jul 29, 2024
1 parent d874676 commit 040528f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
9 changes: 1 addition & 8 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
Size: "shared-cpu-4x",
DiskSize: 10,
OrgSlug: orgSlug,
AuthToken: &authToken,
AuthToken: authToken,
}

workspaceReq *provider.WorkspaceRequest
Expand Down
22 changes: 11 additions & 11 deletions pkg/provider/util/fly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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,
})
Expand All @@ -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
}
Expand All @@ -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,
})
Expand Down
16 changes: 8 additions & 8 deletions pkg/types/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}

Expand Down

0 comments on commit 040528f

Please sign in to comment.