Skip to content

Commit d9f307e

Browse files
Andrea FalzettiiQQBot
authored andcommitted
update
1 parent 60113e3 commit d9f307e

File tree

3 files changed

+64
-77
lines changed

3 files changed

+64
-77
lines changed

components/ide-service/pkg/server/server.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ type WorkspaceConfig struct {
210210
}
211211

212212
type Task struct {
213-
Init string `json:"task,omitempty"`
213+
Init string `json:"init,omitempty"`
214214
}
215215

216216
var JetbrainsCode map[string]string
@@ -374,11 +374,63 @@ func (s *IDEServiceServer) ResolveWorkspaceConfig(ctx context.Context, req *api.
374374
if ok {
375375
for _, alias := range jbGW.DesktopIDEs {
376376
prebuilds := getPrebuilds(wsConfig, alias)
377+
warmUpTask := ""
377378
if prebuilds != nil {
378379
if prebuilds.Version == "latest" {
380+
warmUpTask += `
381+
echo 'warming up stable release of ${key}...'
382+
echo 'downloading stable ${key} backend...'
383+
mkdir /tmp/backend
384+
curl -sSLo /tmp/backend/backend.tar.gz "https://download.jetbrains.com/product?type=release&distribution=linux&code=${productCode}"
385+
tar -xf /tmp/backend/backend.tar.gz --strip-components=1 --directory /tmp/backend
386+
387+
echo 'configuring JB system config and caches aligned with runtime...'
388+
printf '\nshared.indexes.download.auto.consent=true' >> "/tmp/backend/bin/idea.properties"
389+
unset JAVA_TOOL_OPTIONS
390+
export IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains
391+
export IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains
392+
393+
echo 'running stable ${key} backend in warmup mode...'
394+
/tmp/backend/bin/remote-dev-server.sh warmup "$GITPOD_REPO_ROOT"
395+
396+
echo 'removing stable ${key} backend...'
397+
rm -rf /tmp/backend
398+
`
399+
}
379400

401+
if prebuilds.Version == "stable" {
402+
warmUpTask += `
403+
echo 'warming up latest release of ${key}...'
404+
echo 'downloading latest ${key} backend...'
405+
mkdir /tmp/backend-latest
406+
curl -sSLo /tmp/backend-latest/backend-latest.tar.gz "https://download.jetbrains.com/product?type=release,eap,rc&distribution=linux&code=${productCode}"
407+
tar -xf /tmp/backend-latest/backend-latest.tar.gz --strip-components=1 --directory /tmp/backend-latest
408+
409+
echo 'configuring JB system config and caches aligned with runtime...'
410+
printf '\nshared.indexes.download.auto.consent=true' >> "/tmp/backend-latest/bin/idea.properties"
411+
unset JAVA_TOOL_OPTIONS
412+
export IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains-latest
413+
export IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains-latest
414+
415+
echo 'running ${key} backend in warmup mode...'
416+
/tmp/backend-latest/bin/remote-dev-server.sh warmup "$GITPOD_REPO_ROOT"
417+
418+
echo 'removing latest ${key} backend...'
419+
rm -rf /tmp/backend-latest
420+
`
380421
}
381422
}
423+
424+
if warmUpTask != "" {
425+
warmUpEncoded, err := json.Marshal(Task{
426+
Init: strings.TrimSpace(warmUpTask),
427+
})
428+
if err != nil {
429+
log.WithError(err).Error("cannot marshal warm up task")
430+
}
431+
432+
resp.Tasks = string(warmUpEncoded)
433+
}
382434
}
383435
}
384436
return

components/server/src/ide-service.ts

Lines changed: 8 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -46,85 +46,18 @@ export class IDEService {
4646
return this.ideService.resolveWorkspaceConfig(req);
4747
}
4848

49-
resolveGitpodTasks(ws: Workspace): TaskConfig[] {
49+
resolveGitpodTasks(ws: Workspace, ideConfig: IDEConfig): TaskConfig[] {
5050
const tasks: TaskConfig[] = [];
5151
if (ws.config.tasks) {
5252
tasks.push(...ws.config.tasks);
5353
}
54-
// 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
55-
if (ws.type === "prebuild" && ws.config.jetbrains) {
56-
let warmUp = "";
57-
for (const key in ws.config.jetbrains) {
58-
let productCode;
59-
if (key === "intellij") {
60-
productCode = "IIU";
61-
} else if (key === "goland") {
62-
productCode = "GO";
63-
} else if (key === "pycharm") {
64-
productCode = "PCP";
65-
} else if (key === "phpstorm") {
66-
productCode = "PS";
67-
} else if (key === "rubymine") {
68-
productCode = "RM";
69-
} else if (key === "webstorm") {
70-
productCode = "WS";
71-
} else if (key === "rider") {
72-
productCode = "RD";
73-
} else if (key === "clion") {
74-
productCode = "CL";
75-
}
76-
const prebuilds = productCode && ws.config.jetbrains[key as keyof JetBrainsConfig]?.prebuilds;
77-
if (prebuilds) {
78-
warmUp +=
79-
prebuilds.version === "latest"
80-
? ""
81-
: `
82-
echo 'warming up stable release of ${key}...'
83-
echo 'downloading stable ${key} backend...'
84-
mkdir /tmp/backend
85-
curl -sSLo /tmp/backend/backend.tar.gz "https://download.jetbrains.com/product?type=release&distribution=linux&code=${productCode}"
86-
tar -xf /tmp/backend/backend.tar.gz --strip-components=1 --directory /tmp/backend
87-
88-
echo 'configuring JB system config and caches aligned with runtime...'
89-
printf '\nshared.indexes.download.auto.consent=true' >> "/tmp/backend/bin/idea.properties"
90-
unset JAVA_TOOL_OPTIONS
91-
export IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains
92-
export IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains
93-
94-
echo 'running stable ${key} backend in warmup mode...'
95-
/tmp/backend/bin/remote-dev-server.sh warmup "$GITPOD_REPO_ROOT"
96-
97-
echo 'removing stable ${key} backend...'
98-
rm -rf /tmp/backend
99-
`;
100-
warmUp +=
101-
prebuilds.version === "stable"
102-
? ""
103-
: `
104-
echo 'warming up latest release of ${key}...'
105-
echo 'downloading latest ${key} backend...'
106-
mkdir /tmp/backend-latest
107-
curl -sSLo /tmp/backend-latest/backend-latest.tar.gz "https://download.jetbrains.com/product?type=release,eap,rc&distribution=linux&code=${productCode}"
108-
tar -xf /tmp/backend-latest/backend-latest.tar.gz --strip-components=1 --directory /tmp/backend-latest
109-
110-
echo 'configuring JB system config and caches aligned with runtime...'
111-
printf '\nshared.indexes.download.auto.consent=true' >> "/tmp/backend-latest/bin/idea.properties"
112-
unset JAVA_TOOL_OPTIONS
113-
export IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains-latest
114-
export IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains-latest
115-
116-
echo 'running ${key} backend in warmup mode...'
117-
/tmp/backend-latest/bin/remote-dev-server.sh warmup "$GITPOD_REPO_ROOT"
118-
119-
echo 'removing latest ${key} backend...'
120-
rm -rf /tmp/backend-latest
121-
`;
122-
}
123-
}
124-
if (warmUp) {
125-
tasks.push({
126-
init: warmUp.trim(),
127-
});
54+
if (ideConfig.tasks) {
55+
try {
56+
let ideTasks: TaskConfig[] = JSON.parse(ideConfig.tasks);
57+
tasks.push(...ideTasks);
58+
} catch (e) {
59+
console.error("failed get tasks from ide config:", e);
60+
// shall we throw?
12861
}
12962
}
13063
return tasks;

components/server/src/workspace/workspace-starter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,9 @@ export class WorkspaceStarter {
13391339
}
13401340

13411341
log.debug("Workspace config", workspace.config);
1342-
const tasks = this.ideService.resolveGitpodTasks(workspace);
1342+
1343+
const tasks = this.ideService.resolveGitpodTasks(workspace, ideConfig);
1344+
13431345
if (tasks.length) {
13441346
// The task config is interpreted by supervisor only, there's little point in transforming it into something
13451347
// wsman understands and back into the very same structure.

0 commit comments

Comments
 (0)