-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
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; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -145,6 +147,7 @@ export const migrationIDESettings = (user: User) => { | |
return newIDESettings; | ||
}; | ||
|
||
// TODO(ak) move to IDE service | ||
export const chooseIDE = ( | ||
ideChoice: string, | ||
ideOptions: IDEOptions, | ||
|
@@ -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; | ||
|
@@ -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"]; | ||
|
@@ -654,6 +659,7 @@ export class WorkspaceStarter { | |
}); | ||
} | ||
} | ||
//#endregion | ||
|
||
let featureFlags: NamedWorkspaceFeatureFlag[] = workspace.config._featureFlags || []; | ||
featureFlags = featureFlags.concat(this.config.workspaceDefaults.defaultFeatureFlags); | ||
|
@@ -706,6 +712,7 @@ export class WorkspaceStarter { | |
return instance; | ||
} | ||
|
||
// TODO(ak) move to IDE service | ||
protected resolveReferrerIDE( | ||
workspace: Workspace, | ||
user: User, | ||
|
@@ -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); | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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); | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.