Skip to content

[jetbrains] experimental support of warm up in prebuilds #9450

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

Merged
merged 1 commit into from
Apr 25, 2022
Merged
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
64 changes: 64 additions & 0 deletions components/gitpod-protocol/data/gitpod-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@
"items": {
"type": "string"
}
},
"prebuilds": {
"type": "object",
"description": "Enable warming up of IntelliJ in prebuilds.",
"additionalProperties": false,
"properties": {
"version": {
"type": "string",
"enum": [
"stable",
"latest",
"both"
],
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
}
}
}
}
},
Expand All @@ -285,6 +301,22 @@
"items": {
"type": "string"
}
},
"prebuilds": {
"type": "object",
"description": "Enable warming up of GoLand in prebuilds.",
"additionalProperties": false,
"properties": {
"version": {
"type": "string",
"enum": [
"stable",
"latest",
"both"
],
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
}
}
}
}
},
Expand All @@ -299,6 +331,22 @@
"items": {
"type": "string"
}
},
"prebuilds": {
"type": "object",
"description": "Enable warming up of PyCharm in prebuilds.",
"additionalProperties": false,
"properties": {
"version": {
"type": "string",
"enum": [
"stable",
"latest",
"both"
],
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
}
}
}
}
},
Expand All @@ -313,6 +361,22 @@
"items": {
"type": "string"
}
},
"prebuilds": {
"type": "object",
"description": "Enable warming up of PhpStorm in prebuilds.",
"additionalProperties": false,
"properties": {
"version": {
"type": "string",
"enum": [
"stable",
"latest",
"both"
],
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
}
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions components/gitpod-protocol/go/gitpod-config-types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,19 @@ export interface VSCodeConfig {
extensions?: string[];
}

export interface JetBrainsConfig {
intellij?: JetBrainsProductConfig;
goland?: JetBrainsProductConfig;
pycharm?: JetBrainsProductConfig;
phpstorm?: JetBrainsProductConfig;
}
export interface JetBrainsProductConfig {
prebuilds?: JetBrainsPrebuilds;
}
export interface JetBrainsPrebuilds {
version?: "stable" | "latest" | "both";
}

export interface RepositoryCloneInformation {
url: string;
checkoutLocation?: string;
Expand All @@ -561,6 +574,7 @@ export interface WorkspaceConfig {
gitConfig?: { [config: string]: string };
github?: GithubAppConfig;
vscode?: VSCodeConfig;
jetbrains?: JetBrainsConfig;

/** deprecated. Enabled by default **/
experimentalNetwork?: boolean;
Expand Down
1 change: 1 addition & 0 deletions components/gitpod-protocol/src/workspace-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export interface WorkspaceInstanceRepoStatus {
// ConfigurationIdeConfig ide config of WorkspaceInstanceConfiguration
export interface ConfigurationIdeConfig {
useLatest?: boolean;
desktopIdeAlias?: string;
}

// WorkspaceInstanceConfiguration contains all per-instance configuration
Expand Down
2 changes: 2 additions & 0 deletions components/server/src/container-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,12 @@ import { LocalMessageBroker, LocalRabbitMQBackedMessageBroker } from "./messagin
import { contentServiceBinder } from "@gitpod/content-service/lib/sugar";
import { ReferrerPrefixParser } from "./workspace/referrer-prefix-context-parser";
import { InstallationAdminTelemetryDataProvider } from "./installation-admin/telemetry-data-provider";
import { IDEService } from "./ide-service";

export const productionContainerModule = new ContainerModule((bind, unbind, isBound, rebind) => {
bind(Config).toConstantValue(ConfigFile.fromFile());
bind(IDEConfigService).toSelf().inSingletonScope();
bind(IDEService).toSelf().inSingletonScope();

bind(UserService).toSelf().inSingletonScope();
bind(UserDeletionService).toSelf().inSingletonScope();
Expand Down
87 changes: 87 additions & 0 deletions components/server/src/ide-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/**
* Copyright (c) 2022 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

import { JetBrainsConfig, TaskConfig, Workspace } from "@gitpod/gitpod-protocol";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ideally we had a top-level package ide to move the other stuff into. But that's a clear follow-up.

import { injectable } from "inversify";

@injectable()
export class IDEService {
resolveGitpodTasks(ws: Workspace): TaskConfig[] {
const tasks: TaskConfig[] = [];
if (ws.config.tasks) {
tasks.push(...ws.config.tasks);
}
// TODO(ak) it is a hack to get users going, we should rather layer JB products on prebuild workspaces and move logic to corresponding images
if (ws.type === "prebuild" && ws.config.jetbrains) {
let warmUp = "";
for (const key in ws.config.jetbrains) {
let productCode;
if (key === "intellij") {
productCode = "IIU";
} else if (key === "goland") {
productCode = "GO";
} else if (key === "pycharm") {
productCode = "PCP";
} else if (key === "phpstorm") {
productCode = "PS";
}
const prebuilds = productCode && ws.config.jetbrains[key as keyof JetBrainsConfig]?.prebuilds;
if (prebuilds) {
warmUp +=
prebuilds.version === "latest"
? ""
: `
echo 'warming up stable release of ${key}...'
echo 'downloading stable ${key} backend...'
mkdir /tmp/backend
curl -sSLo /tmp/backend/backend.tar.gz "https://download.jetbrains.com/product?type=release&distribution=linux&code=${productCode}"
tar -xf /tmp/backend/backend.tar.gz --strip-components=1 --directory /tmp/backend

echo 'configuring JB system config and caches aligned with runtime...'
printf '\nshared.indexes.download.auto.consent=true' >> "/tmp/backend/bin/idea.properties"
unset JAVA_TOOL_OPTIONS
export IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains
export IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains

echo 'running stable ${key} backend in warmup mode...'
/tmp/backend/bin/remote-dev-server.sh warmup "$GITPOD_REPO_ROOT"

echo 'removing stable ${key} backend...'
rm -rf /tmp/backend
`;
warmUp +=
prebuilds.version === "stable"
? ""
: `
echo 'warming up latest release of ${key}...'
echo 'downloading latest ${key} backend...'
mkdir /tmp/backend-latest
curl -sSLo /tmp/backend-latest/backend-latest.tar.gz "https://download.jetbrains.com/product?type=release,eap,rc&distribution=linux&code=${productCode}"
tar -xf /tmp/backend-latest/backend-latest.tar.gz --strip-components=1 --directory /tmp/backend-latest

echo 'configuring JB system config and caches aligned with runtime...'
printf '\nshared.indexes.download.auto.consent=true' >> "/tmp/backend-latest/bin/idea.properties"
unset JAVA_TOOL_OPTIONS
export IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains-latest
export IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains-latest

echo 'running ${key} backend in warmup mode...'
/tmp/backend-latest/bin/remote-dev-server.sh warmup "$GITPOD_REPO_ROOT"

echo 'removing latest ${key} backend...'
rm -rf /tmp/backend-latest
`;
}
}
if (warmUp) {
tasks.push({
init: warmUp.trim(),
});
}
}
return tasks;
}
}
14 changes: 11 additions & 3 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred";
import { ExtendedUser } from "@gitpod/ws-manager/lib/constraints";
import { increaseFailedInstanceStartCounter, increaseSuccessfulInstanceStartCounter } from "../prometheus-metrics";
import { ContextParser } from "./context-parser-service";
import { IDEService } from "../ide-service";

export interface StartWorkspaceOptions {
rethrow?: boolean;
Expand All @@ -119,6 +120,7 @@ export interface StartWorkspaceOptions {
const MAX_INSTANCE_START_RETRIES = 2;
const INSTANCE_START_RETRY_INTERVAL_SECONDS = 2;

// TODO(ak) move to IDE service
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

export const migrationIDESettings = (user: User) => {
if (!user?.additionalData?.ideSettings || user.additionalData.ideSettings.settingVersion === "2.0") {
return;
Expand All @@ -145,6 +147,7 @@ export const migrationIDESettings = (user: User) => {
return newIDESettings;
};

// TODO(ak) move to IDE service
export const chooseIDE = (
ideChoice: string,
ideOptions: IDEOptions,
Expand Down Expand Up @@ -181,6 +184,7 @@ export class WorkspaceStarter {
@inject(WorkspaceManagerClientProvider) protected readonly clientProvider: WorkspaceManagerClientProvider;
@inject(Config) protected readonly config: Config;
@inject(IDEConfigService) private readonly ideConfigService: IDEConfigService;
@inject(IDEService) private readonly ideService: IDEService;
@inject(TracedWorkspaceDB) protected readonly workspaceDb: DBWithTracing<WorkspaceDB>;
@inject(TracedUserDB) protected readonly userDB: DBWithTracing<UserDB>;
@inject(TokenProvider) protected readonly tokenProvider: TokenProvider;
Expand Down Expand Up @@ -598,6 +602,7 @@ export class WorkspaceStarter {
excludeFeatureFlags: NamedWorkspaceFeatureFlag[],
ideConfig: IDEConfig,
): Promise<WorkspaceInstance> {
//#endregion IDE resolution TODO(ak) move to IDE service
// TODO: Compatible with ide-config not deployed, need revert after ide-config deployed
delete ideConfig.ideOptions.options["code-latest"];
delete ideConfig.ideOptions.options["code-desktop-insiders"];
Expand Down Expand Up @@ -654,6 +659,7 @@ export class WorkspaceStarter {
});
}
}
//#endregion

let featureFlags: NamedWorkspaceFeatureFlag[] = workspace.config._featureFlags || [];
featureFlags = featureFlags.concat(this.config.workspaceDefaults.defaultFeatureFlags);
Expand Down Expand Up @@ -706,6 +712,7 @@ export class WorkspaceStarter {
return instance;
}

// TODO(ak) move to IDE service
protected resolveReferrerIDE(
workspace: Workspace,
user: User,
Expand Down Expand Up @@ -1129,12 +1136,13 @@ export class WorkspaceStarter {
envvars.push(contextEnv);

log.debug("Workspace config", workspace.config);
if (!!workspace.config.tasks) {
// The task config is interpreted by Theia only, there's little point in transforming it into something
const tasks = this.ideService.resolveGitpodTasks(workspace);
if (tasks.length) {
// The task config is interpreted by supervisor only, there's little point in transforming it into something
// wsman understands and back into the very same structure.
const ev = new EnvironmentVariable();
ev.setName("GITPOD_TASKS");
ev.setValue(JSON.stringify(workspace.config.tasks));
ev.setValue(JSON.stringify(tasks));
envvars.push(ev);
}

Expand Down