diff --git a/components/server/src/ide-service.ts b/components/server/src/ide-service.ts index a0ab86bf4dc3d0..be35d14b58516c 100644 --- a/components/server/src/ide-service.ts +++ b/components/server/src/ide-service.ts @@ -4,7 +4,7 @@ * See License-AGPL.txt in the project root for license information. */ -import { TaskConfig, Workspace } from "@gitpod/gitpod-protocol"; +import { IDESettings, TaskConfig, User, Workspace } from "@gitpod/gitpod-protocol"; import { IDEOptions, IDEClient } from "@gitpod/gitpod-protocol/lib/ide-protocol"; import { IDEServiceClient, @@ -42,6 +42,32 @@ export class IDEService { } } + migrateSettings(user: User): IDESettings | undefined { + if (!user?.additionalData?.ideSettings || user.additionalData.ideSettings.settingVersion === "2.0") { + return undefined; + } + const newIDESettings: IDESettings = { + settingVersion: "2.0", + }; + const ideSettings = user.additionalData.ideSettings; + if (ideSettings.useDesktopIde) { + if (ideSettings.defaultDesktopIde === "code-desktop") { + newIDESettings.defaultIde = "code-desktop"; + } else if (ideSettings.defaultDesktopIde === "code-desktop-insiders") { + newIDESettings.defaultIde = "code-desktop"; + newIDESettings.useLatestVersion = true; + } else { + newIDESettings.defaultIde = ideSettings.defaultDesktopIde; + newIDESettings.useLatestVersion = ideSettings.useLatestVersion; + } + } else { + const useLatest = ideSettings.defaultIde === "code-latest"; + newIDESettings.defaultIde = "code"; + newIDESettings.useLatestVersion = useLatest; + } + return newIDESettings; + } + async resolveWorkspaceConfig(req: ResolveWorkspaceConfigRequest): Promise { for (let attempt = 0; attempt < 15; attempt++) { if (attempt != 0) { diff --git a/components/server/src/workspace/workspace-starter.spec.ts b/components/server/src/workspace/workspace-starter.spec.ts index 673d955e9ff514..39a24365433157 100644 --- a/components/server/src/workspace/workspace-starter.spec.ts +++ b/components/server/src/workspace/workspace-starter.spec.ts @@ -6,11 +6,12 @@ import { User } from "@gitpod/gitpod-protocol"; import * as chai from "chai"; -import { migrationIDESettings } from "./workspace-starter"; +import { IDEService } from "../ide-service"; const expect = chai.expect; -describe("workspace-starter", function () { - describe("migrationIDESettings", function () { +describe("ide-service", function () { + describe("ideService.migrateSettings", function () { + const ideService = new IDEService(); it("with no ideSettings should be undefined", function () { const user: User = { id: "string", @@ -18,7 +19,7 @@ describe("workspace-starter", function () { identities: [], additionalData: {}, }; - const result = migrationIDESettings(user); + const result = ideService.migrateSettings(user); expect(result).to.undefined; }); @@ -35,7 +36,7 @@ describe("workspace-starter", function () { }, }, }; - const result = migrationIDESettings(user); + const result = ideService.migrateSettings(user); expect(result).to.undefined; }); @@ -51,7 +52,7 @@ describe("workspace-starter", function () { }, }, }; - const result = migrationIDESettings(user); + const result = ideService.migrateSettings(user); expect(result?.defaultIde).to.equal("code"); expect(result?.useLatestVersion ?? false).to.be.true; }); @@ -69,7 +70,7 @@ describe("workspace-starter", function () { }, }, }; - const result = migrationIDESettings(user); + const result = ideService.migrateSettings(user); expect(result?.defaultIde).to.equal("code-desktop"); expect(result?.useLatestVersion ?? false).to.be.true; }); @@ -87,7 +88,7 @@ describe("workspace-starter", function () { }, }, }; - const result = migrationIDESettings(user); + const result = ideService.migrateSettings(user); expect(result?.defaultIde).to.equal("code-desktop"); expect(result?.useLatestVersion ?? false).to.be.false; }); @@ -106,7 +107,7 @@ describe("workspace-starter", function () { }, }, }; - const result = migrationIDESettings(user); + const result = ideService.migrateSettings(user); expect(result?.defaultIde).to.equal("intellij"); expect(result?.useLatestVersion ?? false).to.be.false; }); @@ -125,7 +126,7 @@ describe("workspace-starter", function () { }, }, }; - const result = migrationIDESettings(user); + const result = ideService.migrateSettings(user); expect(result?.defaultIde).to.equal("intellij"); expect(result?.useLatestVersion ?? false).to.be.true; }); @@ -144,7 +145,7 @@ describe("workspace-starter", function () { }, }, }; - const result = migrationIDESettings(user); + const result = ideService.migrateSettings(user); expect(result?.defaultIde).to.equal("code"); expect(result?.useLatestVersion ?? false).to.be.true; }); diff --git a/components/server/src/workspace/workspace-starter.ts b/components/server/src/workspace/workspace-starter.ts index 1bdd59ae8db2aa..6a5ea57519cd71 100644 --- a/components/server/src/workspace/workspace-starter.ts +++ b/components/server/src/workspace/workspace-starter.ts @@ -56,7 +56,6 @@ import { ImageConfigFile, ProjectEnvVar, ImageBuildLogInfo, - IDESettings, WithReferrerContext, EnvVarWithValue, BillingTier, @@ -137,32 +136,6 @@ export interface StartWorkspaceOptions { const MAX_INSTANCE_START_RETRIES = 2; const INSTANCE_START_RETRY_INTERVAL_SECONDS = 2; -export const migrationIDESettings = (user: User) => { - if (!user?.additionalData?.ideSettings || user.additionalData.ideSettings.settingVersion === "2.0") { - return; - } - const newIDESettings: IDESettings = { - settingVersion: "2.0", - }; - const ideSettings = user.additionalData.ideSettings; - if (ideSettings.useDesktopIde) { - if (ideSettings.defaultDesktopIde === "code-desktop") { - newIDESettings.defaultIde = "code-desktop"; - } else if (ideSettings.defaultDesktopIde === "code-desktop-insiders") { - newIDESettings.defaultIde = "code-desktop"; - newIDESettings.useLatestVersion = true; - } else { - newIDESettings.defaultIde = ideSettings.defaultDesktopIde; - newIDESettings.useLatestVersion = ideSettings.useLatestVersion; - } - } else { - const useLatest = ideSettings.defaultIde === "code-latest"; - newIDESettings.defaultIde = "code"; - newIDESettings.useLatestVersion = useLatest; - } - return newIDESettings; -}; - export async function getWorkspaceClassForInstance( ctx: TraceContext, workspace: Workspace, @@ -297,6 +270,7 @@ export class WorkspaceStarter { } const ideConfig = await this.resolveIDEConfiguration(ctx, workspace, user); + // create and store instance let instance = await this.workspaceDb .trace({ span }) @@ -379,6 +353,11 @@ export class WorkspaceStarter { private async resolveIDEConfiguration(ctx: TraceContext, workspace: Workspace, user: User) { const span = TraceContext.startSpan("resolveIDEConfiguration", ctx); try { + const migrated = this.ideService.migrateSettings(user); + if (user.additionalData?.ideSettings && migrated) { + user.additionalData.ideSettings = migrated; + } + const workspaceType = workspace.type === "prebuild" ? IdeServiceApi.WorkspaceType.PREBUILD @@ -804,11 +783,6 @@ export class WorkspaceStarter { ): Promise { const span = TraceContext.startSpan("newInstance", ctx); try { - const migrated = migrationIDESettings(user); - if (user.additionalData?.ideSettings && migrated) { - user.additionalData.ideSettings = migrated; - } - const configuration: WorkspaceInstanceConfiguration = { ideImage: ideConfig.webImage, supervisorImage: ideConfig.supervisorImage,