diff --git a/components/ide-service/pkg/server/server.go b/components/ide-service/pkg/server/server.go index 6441a6a9c9b105..011eb3a20cf88f 100644 --- a/components/ide-service/pkg/server/server.go +++ b/components/ide-service/pkg/server/server.go @@ -216,6 +216,7 @@ type Task struct { var JetbrainsCode map[string]string func init() { + JetbrainsCode = make(map[string]string) JetbrainsCode["intellij"] = "IIU" JetbrainsCode["goland"] = "GO" JetbrainsCode["pycharm"] = "PCP" @@ -372,65 +373,74 @@ func (s *IDEServiceServer) ResolveWorkspaceConfig(ctx context.Context, req *api. jbGW, ok := s.ideConfig.IdeOptions.Clients["jetbrains-gateway"] if ok { + warmUpTask := "" for _, alias := range jbGW.DesktopIDEs { prebuilds := getPrebuilds(wsConfig, alias) - warmUpTask := "" if prebuilds != nil { - if prebuilds.Version == "latest" { - warmUpTask += ` - 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 - ` + if prebuilds.Version != "latest" { + template := ` +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 +` + if code, ok := JetbrainsCode[alias]; ok { + template = strings.ReplaceAll(template, "${key}", alias) + template = strings.ReplaceAll(template, "${productCode}", code) + warmUpTask += template + } } - if prebuilds.Version == "stable" { - warmUpTask += ` - 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 prebuilds.Version != "stable" { + template := ` +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 code, ok := JetbrainsCode[alias]; ok { + template = strings.ReplaceAll(template, "${key}", alias) + template = strings.ReplaceAll(template, "${productCode}", code) + warmUpTask += template + } } } - - if warmUpTask != "" { - warmUpEncoded, err := json.Marshal(Task{ - Init: strings.TrimSpace(warmUpTask), - }) - if err != nil { - log.WithError(err).Error("cannot marshal warm up task") - } - - resp.Tasks = string(warmUpEncoded) + } + if warmUpTask != "" { + warmUpEncoded, err := json.Marshal([]Task{{ + Init: strings.TrimSpace(warmUpTask), + }}) + if err != nil { + log.WithError(err).Error("cannot marshal warm up task") } + + resp.Tasks = string(warmUpEncoded) } } return diff --git a/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_intellij.golden b/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_intellij.golden new file mode 100644 index 00000000000000..a7b2e673ff4482 --- /dev/null +++ b/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_intellij.golden @@ -0,0 +1,18 @@ +{ + "Resp": { + "envvars": [ + { + "name": "GITPOD_IDE_ALIAS", + "value": "intellij" + } + ], + "supervisor_image": "eu.gcr.io/gitpod-core-dev/build/supervisor:commit-ff38b98b7dde4929159bcaeec68d178898dc2139", + "web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9", + "ide_image_layers": [ + "eu.gcr.io/gitpod-core-dev/build/ide/intellij:commit-9a6c79a91b2b1f583d5bcb7f9f1ef54ee977e0df", + "eu.gcr.io/gitpod-core-dev/build/ide/jb-backend-plugin:commit-b38092639d1783a1957894ddd4f492b3cdc9794a" + ], + "tasks": "[{\"init\":\"echo 'warming up stable release of intellij...'\\necho 'downloading stable intellij backend...'\\nmkdir /tmp/backend\\ncurl -sSLo /tmp/backend/backend.tar.gz \\\"https://download.jetbrains.com/product?type=release\\u0026distribution=linux\\u0026code=IIU\\\"\\ntar -xf /tmp/backend/backend.tar.gz --strip-components=1 --directory /tmp/backend\\n\\necho 'configuring JB system config and caches aligned with runtime...'\\nprintf '\\\\nshared.indexes.download.auto.consent=true' \\u003e\\u003e \\\"/tmp/backend/bin/idea.properties\\\"\\nunset JAVA_TOOL_OPTIONS\\nexport IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains\\nexport IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains\\n\\necho 'running stable intellij backend in warmup mode...'\\n/tmp/backend/bin/remote-dev-server.sh warmup \\\"$GITPOD_REPO_ROOT\\\"\\n\\necho 'removing stable intellij backend...'\\nrm -rf /tmp/backend\\n\\necho 'warming up latest release of intellij...'\\necho 'downloading latest intellij backend...'\\nmkdir /tmp/backend-latest\\ncurl -sSLo /tmp/backend-latest/backend-latest.tar.gz \\\"https://download.jetbrains.com/product?type=release,eap,rc\\u0026distribution=linux\\u0026code=IIU\\\"\\ntar -xf /tmp/backend-latest/backend-latest.tar.gz --strip-components=1 --directory /tmp/backend-latest\\n\\necho 'configuring JB system config and caches aligned with runtime...'\\nprintf '\\\\nshared.indexes.download.auto.consent=true' \\u003e\\u003e \\\"/tmp/backend-latest/bin/idea.properties\\\"\\nunset JAVA_TOOL_OPTIONS\\nexport IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains-latest\\nexport IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains-latest\\n\\necho 'running intellij backend in warmup mode...'\\n/tmp/backend-latest/bin/remote-dev-server.sh warmup \\\"$GITPOD_REPO_ROOT\\\"\\n\\necho 'removing latest intellij backend...'\\nrm -rf /tmp/backend-latest\"}]" + }, + "Err": "" +} \ No newline at end of file diff --git a/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_intellij.json b/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_intellij.json new file mode 100644 index 00000000000000..29006e4670f1ae --- /dev/null +++ b/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_intellij.json @@ -0,0 +1,6 @@ +{ + "type": 1, + "context": "{\"isFile\":false,\"path\":\"\",\"title\":\"gitpod-io/empty \",\"revision\":\"\",\"repository\":{\"cloneUrl\":\"https://github.com/gitpod-io/empty.git\",\"host\":\"github.com\",\"name\":\"empty\",\"owner\":\"gitpod-io\",\"private\":false},\"normalizedContextURL\":\"https://github.com/gitpod-io/empty\",\"checkoutLocation\":\"empty\"}", + "ide_settings": "{\"settingVersion\":\"2.0\",\"defaultIde\":\"intellij\",\"useLatestVersion\":false}", + "workspace_config": "{\"tasks\":[{\"init\":\"echo 'init script'\",\"command\":\"echo 'start script'\"}],\"jetbrains\":{\"intellij\":{\"prebuilds\":{\"version\":\"both\"}}},\"_origin\":\"repo\",\"image\":\"docker.io/gitpod/workspace-full:latest\",\"vscode\":{\"extensions\":[]}}" +} diff --git a/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_multiple_ide.golden b/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_multiple_ide.golden new file mode 100644 index 00000000000000..1b93fe9234ba98 --- /dev/null +++ b/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_multiple_ide.golden @@ -0,0 +1,18 @@ +{ + "Resp": { + "envvars": [ + { + "name": "GITPOD_IDE_ALIAS", + "value": "intellij" + } + ], + "supervisor_image": "eu.gcr.io/gitpod-core-dev/build/supervisor:commit-ff38b98b7dde4929159bcaeec68d178898dc2139", + "web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9", + "ide_image_layers": [ + "eu.gcr.io/gitpod-core-dev/build/ide/intellij:commit-9a6c79a91b2b1f583d5bcb7f9f1ef54ee977e0df", + "eu.gcr.io/gitpod-core-dev/build/ide/jb-backend-plugin:commit-b38092639d1783a1957894ddd4f492b3cdc9794a" + ], + "tasks": "[{\"init\":\"echo 'warming up stable release of intellij...'\\necho 'downloading stable intellij backend...'\\nmkdir /tmp/backend\\ncurl -sSLo /tmp/backend/backend.tar.gz \\\"https://download.jetbrains.com/product?type=release\\u0026distribution=linux\\u0026code=IIU\\\"\\ntar -xf /tmp/backend/backend.tar.gz --strip-components=1 --directory /tmp/backend\\n\\necho 'configuring JB system config and caches aligned with runtime...'\\nprintf '\\\\nshared.indexes.download.auto.consent=true' \\u003e\\u003e \\\"/tmp/backend/bin/idea.properties\\\"\\nunset JAVA_TOOL_OPTIONS\\nexport IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains\\nexport IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains\\n\\necho 'running stable intellij backend in warmup mode...'\\n/tmp/backend/bin/remote-dev-server.sh warmup \\\"$GITPOD_REPO_ROOT\\\"\\n\\necho 'removing stable intellij backend...'\\nrm -rf /tmp/backend\\n\\necho 'warming up stable release of goland...'\\necho 'downloading stable goland backend...'\\nmkdir /tmp/backend\\ncurl -sSLo /tmp/backend/backend.tar.gz \\\"https://download.jetbrains.com/product?type=release\\u0026distribution=linux\\u0026code=GO\\\"\\ntar -xf /tmp/backend/backend.tar.gz --strip-components=1 --directory /tmp/backend\\n\\necho 'configuring JB system config and caches aligned with runtime...'\\nprintf '\\\\nshared.indexes.download.auto.consent=true' \\u003e\\u003e \\\"/tmp/backend/bin/idea.properties\\\"\\nunset JAVA_TOOL_OPTIONS\\nexport IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains\\nexport IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains\\n\\necho 'running stable goland backend in warmup mode...'\\n/tmp/backend/bin/remote-dev-server.sh warmup \\\"$GITPOD_REPO_ROOT\\\"\\n\\necho 'removing stable goland backend...'\\nrm -rf /tmp/backend\\n\\necho 'warming up latest release of goland...'\\necho 'downloading latest goland backend...'\\nmkdir /tmp/backend-latest\\ncurl -sSLo /tmp/backend-latest/backend-latest.tar.gz \\\"https://download.jetbrains.com/product?type=release,eap,rc\\u0026distribution=linux\\u0026code=GO\\\"\\ntar -xf /tmp/backend-latest/backend-latest.tar.gz --strip-components=1 --directory /tmp/backend-latest\\n\\necho 'configuring JB system config and caches aligned with runtime...'\\nprintf '\\\\nshared.indexes.download.auto.consent=true' \\u003e\\u003e \\\"/tmp/backend-latest/bin/idea.properties\\\"\\nunset JAVA_TOOL_OPTIONS\\nexport IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains-latest\\nexport IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains-latest\\n\\necho 'running goland backend in warmup mode...'\\n/tmp/backend-latest/bin/remote-dev-server.sh warmup \\\"$GITPOD_REPO_ROOT\\\"\\n\\necho 'removing latest goland backend...'\\nrm -rf /tmp/backend-latest\\n\\necho 'warming up latest release of phpstorm...'\\necho 'downloading latest phpstorm backend...'\\nmkdir /tmp/backend-latest\\ncurl -sSLo /tmp/backend-latest/backend-latest.tar.gz \\\"https://download.jetbrains.com/product?type=release,eap,rc\\u0026distribution=linux\\u0026code=PS\\\"\\ntar -xf /tmp/backend-latest/backend-latest.tar.gz --strip-components=1 --directory /tmp/backend-latest\\n\\necho 'configuring JB system config and caches aligned with runtime...'\\nprintf '\\\\nshared.indexes.download.auto.consent=true' \\u003e\\u003e \\\"/tmp/backend-latest/bin/idea.properties\\\"\\nunset JAVA_TOOL_OPTIONS\\nexport IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains-latest\\nexport IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains-latest\\n\\necho 'running phpstorm backend in warmup mode...'\\n/tmp/backend-latest/bin/remote-dev-server.sh warmup \\\"$GITPOD_REPO_ROOT\\\"\\n\\necho 'removing latest phpstorm backend...'\\nrm -rf /tmp/backend-latest\"}]" + }, + "Err": "" +} \ No newline at end of file diff --git a/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_multiple_ide.json b/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_multiple_ide.json new file mode 100644 index 00000000000000..10b31de2c34b5b --- /dev/null +++ b/components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild_multiple_ide.json @@ -0,0 +1,6 @@ +{ + "type": 1, + "context": "{\"isFile\":false,\"path\":\"\",\"title\":\"gitpod-io/empty \",\"revision\":\"\",\"repository\":{\"cloneUrl\":\"https://github.com/gitpod-io/empty.git\",\"host\":\"github.com\",\"name\":\"empty\",\"owner\":\"gitpod-io\",\"private\":false},\"normalizedContextURL\":\"https://github.com/gitpod-io/empty\",\"checkoutLocation\":\"empty\"}", + "ide_settings": "{\"settingVersion\":\"2.0\",\"defaultIde\":\"intellij\",\"useLatestVersion\":false}", + "workspace_config": "{\"tasks\":[{\"init\":\"echo 'init script'\",\"command\":\"echo 'start script'\"}],\"jetbrains\":{\"intellij\":{\"prebuilds\":{\"version\":\"stable\"}},\"phpstorm\":{\"prebuilds\":{\"version\":\"latest\"}},\"goland\":{\"prebuilds\":{\"version\":\"both\"}}},\"_origin\":\"repo\",\"image\":\"docker.io/gitpod/workspace-full:latest\",\"vscode\":{\"extensions\":[]}}" +} diff --git a/components/server/src/ide-service.ts b/components/server/src/ide-service.ts index ba0ef50e726e0b..538dec0957634e 100644 --- a/components/server/src/ide-service.ts +++ b/components/server/src/ide-service.ts @@ -46,7 +46,7 @@ export class IDEService { return this.ideService.resolveWorkspaceConfig(req); } - resolveGitpodTasks(ws: Workspace, ideConfig: IDEConfig): TaskConfig[] { + resolveGitpodTasks(ws: Workspace, ideConfig: ResolveWorkspaceConfigResponse): TaskConfig[] { const tasks: TaskConfig[] = []; if (ws.config.tasks) { tasks.push(...ws.config.tasks); @@ -57,7 +57,6 @@ export class IDEService { tasks.push(...ideTasks); } catch (e) { console.error("failed get tasks from ide config:", e); - // shall we throw? } } return tasks;