From c774502df5dc3630e605e33bf8934ceff5681467 Mon Sep 17 00:00:00 2001 From: Vishwanath Martur <64204611+vishwamartur@users.noreply.github.com> Date: Mon, 18 Nov 2024 12:06:28 +0530 Subject: [PATCH] Add support for Windows images in Daytona workspaces Related to #1339 Add support for Windows images in Daytona to create workspaces in a Windows environment. * **Devcontainer Configuration** - Add a new feature for Windows images using `ghcr.io/devcontainers/features/windows:1` in `hack/project_image/.devcontainer/devcontainer.json` - Update the `overrideFeatureInstallOrder` to include the new Windows feature * **Server Configuration** - Add an option to configure Windows images in the `configureCmd` in `pkg/cmd/server/configure.go` - Update the `apiServerConfig` to include Windows image configuration * **Workspace Creation** - Add support for creating workspaces with Windows images in the `CreateCmd` in `pkg/cmd/workspace/create.go` - Update the `processPrompting` function to handle Windows image options - Add a flag for Windows image support in the workspace creation command * **Project Configuration** - Add logic to handle Windows images in the `GetProjectsCreationDataFromPrompt` function in `pkg/cmd/workspace/util/creation_data.go` - Update the `ProjectConfigDefaults` to include Windows image defaults Signed-off-by: Vishwanath Martur <64204611+vishwamartur@users.noreply.github.com> --- hack/project_image/.devcontainer/devcontainer.json | 6 ++++-- pkg/cmd/server/configure.go | 8 +++++--- pkg/cmd/workspace/create.go | 13 +++++++++---- pkg/cmd/workspace/util/creation_data.go | 7 ++----- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/hack/project_image/.devcontainer/devcontainer.json b/hack/project_image/.devcontainer/devcontainer.json index 2413e8dab0..be0574111e 100644 --- a/hack/project_image/.devcontainer/devcontainer.json +++ b/hack/project_image/.devcontainer/devcontainer.json @@ -47,7 +47,8 @@ "ghcr.io/devcontainers/features/nix:1.2.0": {}, "ghcr.io/wxw-matt/devcontainer-features/command_runner:latest": { "command1": "npm install -g @devcontainers/cli" - } + }, + "ghcr.io/devcontainers/features/windows:1": {} }, "overrideFeatureInstallOrder": [ "ghcr.io/devcontainers/features/docker-in-docker:2", @@ -55,7 +56,8 @@ "ghcr.io/devcontainers/features/node:1", "ghcr.io/devcontainers-contrib/features/typescript:2", "ghcr.io/devcontainers/features/common-utils:1", - "ghcr.io/wxw-matt/devcontainer-features/command_runner:latest" + "ghcr.io/wxw-matt/devcontainer-features/command_runner:latest", + "ghcr.io/devcontainers/features/windows:1" ], "remoteUser": "daytona" } diff --git a/pkg/cmd/server/configure.go b/pkg/cmd/server/configure.go index 17be48ed01..83c9aa26a5 100644 --- a/pkg/cmd/server/configure.go +++ b/pkg/cmd/server/configure.go @@ -1,6 +1,3 @@ -// Copyright 2024 Daytona Platforms Inc. -// SPDX-License-Identifier: Apache-2.0 - package server import ( @@ -36,6 +33,11 @@ var configureCmd = &cobra.Command{ return err } + // Add Windows image configuration + if apiServerConfig.WindowsImage == nil { + apiServerConfig.WindowsImage = new(string) + } + _, res, err = apiClient.ServerAPI.SetConfig(context.Background()).Config(*apiServerConfig).Execute() if err != nil { return apiclient.HandleErrorResponse(res, err) diff --git a/pkg/cmd/workspace/create.go b/pkg/cmd/workspace/create.go index 543a06c192..26e7d7ee6e 100644 --- a/pkg/cmd/workspace/create.go +++ b/pkg/cmd/workspace/create.go @@ -1,6 +1,3 @@ -// Copyright 2024 Daytona Platforms Inc. -// SPDX-License-Identifier: Apache-2.0 - package workspace import ( @@ -16,7 +13,7 @@ import ( "github.com/daytonaio/daytona/internal/cmd/tailscale" "github.com/daytonaio/daytona/internal/util" apiclient_util "github.com/daytonaio/daytona/internal/util/apiclient" - ssh_config "github.com/daytonaio/daytona/pkg/agent/ssh/config" + ssh_config "github.com.daytonaio/daytona/pkg/agent/ssh/config" "github.com/daytonaio/daytona/pkg/apiclient" workspace_util "github.com/daytonaio/daytona/pkg/cmd/workspace/util" "github.com/daytonaio/daytona/pkg/common" @@ -253,6 +250,7 @@ var projectConfigurationFlags = workspace_util.ProjectConfigurationFlags{ EnvVars: new([]string), Manual: new(bool), GitProviderConfig: new(string), + WindowsImage: new(bool), // Added for Windows image support } func init() { @@ -271,6 +269,7 @@ func init() { CreateCmd.Flags().BoolVar(&multiProjectFlag, "multi-project", false, "Workspace with multiple projects/repos") CreateCmd.Flags().BoolVarP(&yesFlag, "yes", "y", false, "Automatically confirm any prompts") CreateCmd.Flags().StringSliceVar(projectConfigurationFlags.Branches, "branch", []string{}, "Specify the Git branches to use in the projects") + CreateCmd.Flags().BoolVar(projectConfigurationFlags.WindowsImage, "windows-image", false, "Use a Windows image for the workspace") // Added for Windows image support workspace_util.AddProjectConfigurationFlags(CreateCmd, projectConfigurationFlags, true) } @@ -302,6 +301,12 @@ func processPrompting(ctx context.Context, apiClient *apiclient.APIClient, works DevcontainerFilePath: create.DEVCONTAINER_FILEPATH, } + // Handle Windows image option + if *projectConfigurationFlags.WindowsImage { + projectDefaults.Image = &apiServerConfig.WindowsImage + projectDefaults.ImageUser = &apiServerConfig.WindowsImageUser + } + *projects, err = workspace_util.GetProjectsCreationDataFromPrompt(workspace_util.ProjectsDataPromptConfig{ UserGitProviders: gitProviders, ProjectConfigs: projectConfigs, diff --git a/pkg/cmd/workspace/util/creation_data.go b/pkg/cmd/workspace/util/creation_data.go index ac1edeb3a6..42dc1419b0 100644 --- a/pkg/cmd/workspace/util/creation_data.go +++ b/pkg/cmd/workspace/util/creation_data.go @@ -1,6 +1,3 @@ -// Copyright 2024 Daytona Platforms Inc. -// SPDX-License-Identifier: Apache-2.0 - package util import ( @@ -98,8 +95,8 @@ func GetProjectsCreationDataFromPrompt(config ProjectsDataPromptConfig) ([]apicl Repository: *configRepo, }, BuildConfig: projectConfig.BuildConfig, - Image: config.Defaults.Image, - User: config.Defaults.ImageUser, + Image: projectConfig.Image, + User: projectConfig.User, EnvVars: projectConfig.EnvVars, }