Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POD-898 | Add Environment Template support to desktop app #1255

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 44 additions & 18 deletions cmd/pro/provider/list/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,50 @@ func (cmd *TemplatesCmd) Run(ctx context.Context) error {
return cmp.Compare(a.Value, b.Value)
})

return printOptions(&OptionsFormat{
Options: map[string]*types.Option{
loft.RunnerEnv: {
DisplayName: "Runner",
Description: "The DevPod Pro runner to use for a new workspace.",
Enum: runners,
Required: true,
Mutable: false,
},
loft.TemplateOptionEnv: {
DisplayName: "Template",
Description: "The template to use for a new workspace.",
Required: true,
Enum: templates,
Default: templateList.DefaultDevPodWorkspaceTemplate,
SubOptionsCommand: fmt.Sprintf("'%s' pro provider list templateoptions", executable),
Mutable: true,
},
//collect environments
environmentsList, err := managementClient.Loft().ManagementV1().DevPodEnvironmentTemplates().List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("list environments: %w", err)
}

environments := []types.OptionEnum{}
for _, env := range environmentsList.Items {
environments = append(environments, types.OptionEnum{
Value: env.Name,
DisplayName: loft.DisplayName(env.Name, env.Spec.DisplayName),
})
}

options := map[string]*types.Option{
loft.RunnerEnv: {
DisplayName: "Runner",
Description: "The DevPod Pro runner to use for a new workspace.",
Enum: runners,
Required: true,
Mutable: false,
},
loft.TemplateOptionEnv: {
DisplayName: "Template",
Description: "The template to use for a new workspace.",
Required: true,
Enum: templates,
Default: templateList.DefaultDevPodWorkspaceTemplate,
SubOptionsCommand: fmt.Sprintf("'%s' pro provider list templateoptions", executable),
Mutable: true,
},
}

if len(environments) > 0 {
options[loft.EnvironmentTemplateOptionEnv] = &types.Option{
DisplayName: "Environment Template",
Description: "The template to use for creating environment",
Enum: environments,
Required: true,
Mutable: false,
}
}

return printOptions(&OptionsFormat{
Options: options,
})
}
5 changes: 5 additions & 0 deletions cmd/pro/provider/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
templateVersion = ""
}

environmentName := os.Getenv(loft.EnvironmentTemplateOptionEnv)

// find parameters
resolvedParameters, err := getParametersFromEnvironment(ctx, managementClient, workspaceInfo.ProjectName, template, templateVersion)
if err != nil {
Expand Down Expand Up @@ -239,6 +241,9 @@
Name: template,
Version: templateVersion,
},
EnvironmentRef: storagev1.EnvironmentRef{

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

unknown field EnvironmentRef in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".DevPodWorkspaceInstanceSpec

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

undefined: storagev1.EnvironmentRef

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

unknown field EnvironmentRef in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".DevPodWorkspaceInstanceSpec

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / test-e2e-windows (build)

undefined: storagev1.EnvironmentRef

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / unit-tests

unknown field EnvironmentRef in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".DevPodWorkspaceInstanceSpec

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: storagev1.EnvironmentRef

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / lint

unknown field EnvironmentRef in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".DevPodWorkspaceInstanceSpec

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / lint

undefined: storagev1.EnvironmentRef (typecheck)

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / lint

unknown field EnvironmentRef in struct literal of type "github.com/loft-sh/api/v4/pkg/apis/storage/v1".DevPodWorkspaceInstanceSpec

Check failure on line 244 in cmd/pro/provider/up.go

View workflow job for this annotation

GitHub Actions / lint

undefined: storagev1.EnvironmentRef) (typecheck)
Name: environmentName,
},
},
},
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/devcontainer/crane/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type command struct {
}

func New(cmd string) *command {
return &command{cmd: cmd}
newCommand := &command{cmd: getBinName()}
return newCommand.WithArg(cmd)
}

func (c *command) WithFlag(flag, val string) *command {
Expand Down Expand Up @@ -73,7 +74,8 @@ func ShouldUse(cliOptions *provider2.CLIOptions) bool {

// IsAvailable checks if devpod crane is installed in host system
func IsAvailable() bool {
_, err := exec.LookPath(getBinName())
path, err := exec.LookPath(getBinName())
log.Default.Infof("Path found -> %v", path)
return err == nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/loft/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ const (
TemplateOptionEnv = "LOFT_TEMPLATE"
TemplateVersionOptionEnv = "LOFT_TEMPLATE_VERSION"

EnvironmentTemplateOptionEnv = "LOFT_ENVIRONMENT_TEMPLATE"

TimeoutEnv = "LOFT_TIMEOUT"
)
Loading