Skip to content

Commit 377ca81

Browse files
Andrea Falzettiakosyakovfelladrin
committed
jetbrains: run warmup as last task
Co-authored-by: Anton Kosyakov <[email protected]> Co-authored-by: Victor Nogueira <[email protected]>
1 parent cd289d4 commit 377ca81

10 files changed

+174
-153
lines changed

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

Lines changed: 88 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,6 @@ type WorkspaceContext struct {
188188
ReferrerIde string `json:"referrerIde,omitempty"`
189189
}
190190

191-
var JetbrainsCode map[string]string
192-
193-
func init() {
194-
JetbrainsCode = make(map[string]string)
195-
JetbrainsCode["intellij"] = "IIU"
196-
JetbrainsCode["goland"] = "GO"
197-
JetbrainsCode["pycharm"] = "PCP"
198-
JetbrainsCode["phpstorm"] = "PS"
199-
JetbrainsCode["rubymine"] = "RM"
200-
JetbrainsCode["webstorm"] = "WS"
201-
JetbrainsCode["rider"] = "RD"
202-
JetbrainsCode["clion"] = "CL"
203-
}
204-
205191
func (s *IDEServiceServer) resolveReferrerIDE(ideConfig *config.IDEConfig, wsCtx *WorkspaceContext, chosenIDEName string) (ideName string, ideOption *config.IDEOption) {
206192
if wsCtx == nil || wsCtx.Referrer == "" {
207193
return
@@ -264,166 +250,150 @@ func (s *IDEServiceServer) ResolveWorkspaceConfig(ctx context.Context, req *api.
264250
WebImage: defaultIde.Image,
265251
}
266252

267-
// TODO: reconsider this
268-
// if req.Type != api.WorkspaceType_REGULAR {
269-
// return resp, nil
270-
// }
271-
272253
var wsConfig *gitpodapi.GitpodConfig
273-
var wsContext *WorkspaceContext
274-
var ideSettings *IDESettings
275254

276-
if req.IdeSettings != "" {
277-
if err := json.Unmarshal([]byte(req.IdeSettings), &ideSettings); err != nil {
278-
log.WithError(err).WithField("ideSetting", req.IdeSettings).Error("failed to parse ide settings")
279-
}
280-
}
281255
if req.WorkspaceConfig != "" {
282256
if err := json.Unmarshal([]byte(req.WorkspaceConfig), &wsConfig); err != nil {
283257
log.WithError(err).WithField("workspaceConfig", req.WorkspaceConfig).Error("failed to parse workspace config")
284258
}
285259
}
286-
if req.Context != "" {
287-
if err := json.Unmarshal([]byte(req.Context), &wsContext); err != nil {
288-
log.WithError(err).WithField("context", req.Context).Error("failed to parse context")
289-
}
290-
}
291260

292-
userIdeName := ""
293-
useLatest := false
261+
if req.Type == api.WorkspaceType_REGULAR {
262+
var ideSettings *IDESettings
263+
var wsContext *WorkspaceContext
294264

295-
if ideSettings != nil {
296-
userIdeName = ideSettings.DefaultIde
297-
useLatest = ideSettings.UseLatestVersion
298-
}
265+
if req.IdeSettings != "" {
266+
if err := json.Unmarshal([]byte(req.IdeSettings), &ideSettings); err != nil {
267+
log.WithError(err).WithField("ideSetting", req.IdeSettings).Error("failed to parse ide settings")
268+
}
269+
}
270+
271+
if req.Context != "" {
272+
if err := json.Unmarshal([]byte(req.Context), &wsContext); err != nil {
273+
log.WithError(err).WithField("context", req.Context).Error("failed to parse context")
274+
}
275+
}
299276

300-
chosenIDE := defaultIde
277+
userIdeName := ""
278+
useLatest := false
301279

302-
getUserIDEImage := func(ideOption *config.IDEOption) string {
303-
if useLatest && ideOption.LatestImage != "" {
304-
return ideOption.LatestImage
280+
if ideSettings != nil {
281+
userIdeName = ideSettings.DefaultIde
282+
useLatest = ideSettings.UseLatestVersion
305283
}
306284

307-
return ideOption.Image
308-
}
285+
chosenIDE := defaultIde
286+
287+
getUserIDEImage := func(ideOption *config.IDEOption) string {
288+
if useLatest && ideOption.LatestImage != "" {
289+
return ideOption.LatestImage
290+
}
309291

310-
getUserPluginImage := func(ideOption *config.IDEOption) string {
311-
if useLatest && ideOption.PluginLatestImage != "" {
312-
return ideOption.PluginLatestImage
292+
return ideOption.Image
313293
}
314294

315-
return ideOption.PluginImage
316-
}
295+
getUserPluginImage := func(ideOption *config.IDEOption) string {
296+
if useLatest && ideOption.PluginLatestImage != "" {
297+
return ideOption.PluginLatestImage
298+
}
299+
300+
return ideOption.PluginImage
301+
}
317302

318-
if userIdeName != "" {
319-
if ide, ok := ideConfig.IdeOptions.Options[userIdeName]; ok {
320-
chosenIDE = &ide
303+
if userIdeName != "" {
304+
if ide, ok := ideConfig.IdeOptions.Options[userIdeName]; ok {
305+
chosenIDE = &ide
321306

322-
// TODO: Currently this variable reflects the IDE selected in
323-
// user's settings for backward compatibility but in the future
324-
// we want to make it represent the actual IDE.
325-
ideAlias := api.EnvironmentVariable{
326-
Name: "GITPOD_IDE_ALIAS",
327-
Value: userIdeName,
307+
// TODO: Currently this variable reflects the IDE selected in
308+
// user's settings for backward compatibility but in the future
309+
// we want to make it represent the actual IDE.
310+
ideAlias := api.EnvironmentVariable{
311+
Name: "GITPOD_IDE_ALIAS",
312+
Value: userIdeName,
313+
}
314+
resp.Envvars = append(resp.Envvars, &ideAlias)
328315
}
329-
resp.Envvars = append(resp.Envvars, &ideAlias)
330316
}
331-
}
332317

333-
// we always need WebImage for when the user chooses a desktop ide
334-
resp.WebImage = getUserIDEImage(defaultIde)
318+
// we always need WebImage for when the user chooses a desktop ide
319+
resp.WebImage = getUserIDEImage(defaultIde)
335320

336-
var desktopImageLayer string
337-
var desktopPluginImageLayer string
338-
if chosenIDE.Type == config.IDETypeDesktop {
339-
desktopImageLayer = getUserIDEImage(chosenIDE)
340-
desktopPluginImageLayer = getUserPluginImage(chosenIDE)
341-
} else {
342-
resp.WebImage = getUserIDEImage(chosenIDE)
343-
}
321+
var desktopImageLayer string
322+
var desktopPluginImageLayer string
323+
if chosenIDE.Type == config.IDETypeDesktop {
324+
desktopImageLayer = getUserIDEImage(chosenIDE)
325+
desktopPluginImageLayer = getUserPluginImage(chosenIDE)
326+
} else {
327+
resp.WebImage = getUserIDEImage(chosenIDE)
328+
}
344329

345-
ideName, referrer := s.resolveReferrerIDE(ideConfig, wsContext, userIdeName)
346-
if ideName != "" {
347-
resp.RefererIde = ideName
348-
desktopImageLayer = getUserIDEImage(referrer)
349-
desktopPluginImageLayer = getUserPluginImage(referrer)
350-
}
330+
ideName, referrer := s.resolveReferrerIDE(ideConfig, wsContext, userIdeName)
331+
if ideName != "" {
332+
resp.RefererIde = ideName
333+
desktopImageLayer = getUserIDEImage(referrer)
334+
desktopPluginImageLayer = getUserPluginImage(referrer)
335+
}
351336

352-
if desktopImageLayer != "" {
353-
resp.IdeImageLayers = append(resp.IdeImageLayers, desktopImageLayer)
354-
if desktopPluginImageLayer != "" {
355-
resp.IdeImageLayers = append(resp.IdeImageLayers, desktopPluginImageLayer)
337+
if desktopImageLayer != "" {
338+
resp.IdeImageLayers = append(resp.IdeImageLayers, desktopImageLayer)
339+
if desktopPluginImageLayer != "" {
340+
resp.IdeImageLayers = append(resp.IdeImageLayers, desktopPluginImageLayer)
341+
}
356342
}
357343
}
358344

359345
jbGW, ok := ideConfig.IdeOptions.Clients["jetbrains-gateway"]
360346
if req.Type == api.WorkspaceType_PREBUILD && ok {
361347
warmUpTask := ""
348+
var pluginStableImage string
349+
var pluginLatestImage string
362350
for _, alias := range jbGW.DesktopIDEs {
363351
prebuilds := getPrebuilds(wsConfig, alias)
364352
if prebuilds != nil {
365353
if prebuilds.Version != "latest" {
366-
template := `
354+
if ide, ok := ideConfig.IdeOptions.Options[alias]; ok {
355+
pluginStableImage = ide.PluginImage
356+
resp.IdeImageLayers = append(resp.IdeImageLayers, ide.Image)
357+
template := `
367358
echo 'warming up stable release of ${key}...'
368-
echo 'downloading stable ${key} backend...'
369-
mkdir /tmp/backend
370-
curl -sSLo /tmp/backend/backend.tar.gz "https://download.jetbrains.com/product?type=release&distribution=linux&code=${productCode}"
371-
tar -xf /tmp/backend/backend.tar.gz --strip-components=1 --directory /tmp/backend
372-
373-
echo 'configuring JB system config and caches aligned with runtime...'
374-
printf '\nshared.indexes.download.auto.consent=true' >> "/tmp/backend/bin/idea.properties"
375-
unset JAVA_TOOL_OPTIONS
376-
export IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains
377-
export IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains
378-
379-
echo 'running stable ${key} backend in warmup mode...'
380-
/tmp/backend/bin/remote-dev-server.sh warmup "$GITPOD_REPO_ROOT"
381-
382-
echo 'removing stable ${key} backend...'
383-
rm -rf /tmp/backend
359+
JETBRAINS_BACKEND_QUALIFIER=stable /ide-desktop/${key}/status warmup ${key}
384360
`
385-
if code, ok := JetbrainsCode[alias]; ok {
386361
template = strings.ReplaceAll(template, "${key}", alias)
387-
template = strings.ReplaceAll(template, "${productCode}", code)
388362
warmUpTask += template
389363
}
390364
}
391365

392366
if prebuilds.Version != "stable" {
393-
template := `
367+
if ide, ok := ideConfig.IdeOptions.Options[alias]; ok {
368+
pluginLatestImage = ide.PluginLatestImage
369+
resp.IdeImageLayers = append(resp.IdeImageLayers, ide.LatestImage)
370+
template := `
394371
echo 'warming up latest release of ${key}...'
395-
echo 'downloading latest ${key} backend...'
396-
mkdir /tmp/backend-latest
397-
curl -sSLo /tmp/backend-latest/backend-latest.tar.gz "https://download.jetbrains.com/product?type=release,eap,rc&distribution=linux&code=${productCode}"
398-
tar -xf /tmp/backend-latest/backend-latest.tar.gz --strip-components=1 --directory /tmp/backend-latest
399-
400-
echo 'configuring JB system config and caches aligned with runtime...'
401-
printf '\nshared.indexes.download.auto.consent=true' >> "/tmp/backend-latest/bin/idea.properties"
402-
unset JAVA_TOOL_OPTIONS
403-
export IJ_HOST_CONFIG_BASE_DIR=/workspace/.config/JetBrains-latest
404-
export IJ_HOST_SYSTEM_BASE_DIR=/workspace/.cache/JetBrains-latest
405-
406-
echo 'running ${key} backend in warmup mode...'
407-
/tmp/backend-latest/bin/remote-dev-server.sh warmup "$GITPOD_REPO_ROOT"
408-
409-
echo 'removing latest ${key} backend...'
410-
rm -rf /tmp/backend-latest
372+
JETBRAINS_BACKEND_QUALIFIER=latest /ide-desktop/${key}-latest/status warmup ${key}
411373
`
412-
if code, ok := JetbrainsCode[alias]; ok {
413374
template = strings.ReplaceAll(template, "${key}", alias)
414-
template = strings.ReplaceAll(template, "${productCode}", code)
415375
warmUpTask += template
416376
}
417377
}
418378
}
419379
}
380+
381+
if pluginStableImage != "" {
382+
resp.IdeImageLayers = append(resp.IdeImageLayers, pluginStableImage)
383+
}
384+
385+
if pluginLatestImage != "" {
386+
resp.IdeImageLayers = append(resp.IdeImageLayers, pluginLatestImage)
387+
}
388+
420389
if warmUpTask != "" {
421390
warmUpEncoded := new(bytes.Buffer)
422391
enc := json.NewEncoder(warmUpEncoded)
423392
enc.SetEscapeHTML(false)
424393

425394
err := enc.Encode(&[]gitpodapi.TaskConfig{{
426395
Init: strings.TrimSpace(warmUpTask),
396+
Name: "GITPOD_JB_WARMUP_TASK",
427397
}})
428398
if err != nil {
429399
log.WithError(err).Error("cannot marshal warm up task")
@@ -432,6 +402,7 @@ rm -rf /tmp/backend-latest
432402
resp.Tasks = warmUpEncoded.String()
433403
}
434404
}
405+
435406
return
436407
}
437408

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
{
22
"Resp": {
3-
"envvars": [
4-
{
5-
"name": "GITPOD_IDE_ALIAS",
6-
"value": "code"
7-
}
8-
],
93
"supervisor_image": "eu.gcr.io/gitpod-core-dev/build/supervisor:commit-ff38b98b7dde4929159bcaeec68d178898dc2139",
104
"web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9"
115
},
126
"Err": ""
13-
}
7+
}

components/ide-service/pkg/server/testdata/resolve_ws_config_prebuild.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"Resp": {
3+
"supervisor_image": "eu.gcr.io/gitpod-core-dev/build/supervisor:commit-ff38b98b7dde4929159bcaeec68d178898dc2139",
4+
"web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9",
5+
"ide_image_layers": [
6+
"eu.gcr.io/gitpod-core-dev/build/ide/intellij:commit-9a6c79a91b2b1f583d5bcb7f9f1ef54ee977e0df",
7+
"eu.gcr.io/gitpod-core-dev/build/ide/goland:commit-9a6c79a91b2b1f583d5bcb7f9f1ef54ee977e0df",
8+
"eu.gcr.io/gitpod-core-dev/build/ide/goland:latest@sha256:e07524e52089829dc8d3b38f7d18fb51b24f07aed7d8e4e6e447899687978d43",
9+
"eu.gcr.io/gitpod-core-dev/build/ide/phpstorm:latest@sha256:e07524e52089829dc8d3b38f7d18fb51b24f07aed7d8e4e6e447899687978d43",
10+
"eu.gcr.io/gitpod-core-dev/build/ide/jb-backend-plugin:commit-b38092639d1783a1957894ddd4f492b3cdc9794a",
11+
"eu.gcr.io/gitpod-core-dev/build/ide/jb-backend-plugin:commit-b38092639d1783a1957894ddd4f492b3cdc9794a-latest"
12+
],
13+
"tasks": "[{\"init\":\"echo 'warming up stable release of intellij...'\\nJETBRAINS_BACKEND_QUALIFIER=stable /ide-desktop/intellij/status warmup intellij\\n\\necho 'warming up stable release of goland...'\\nJETBRAINS_BACKEND_QUALIFIER=stable /ide-desktop/goland/status warmup goland\\n\\necho 'warming up latest release of goland...'\\nJETBRAINS_BACKEND_QUALIFIER=latest /ide-desktop/goland-latest/status warmup goland\\n\\necho 'warming up latest release of phpstorm...'\\nJETBRAINS_BACKEND_QUALIFIER=latest /ide-desktop/phpstorm-latest/status warmup phpstorm\",\"name\":\"GITPOD_JB_WARMUP_TASK\"}]\n"
14+
},
15+
"Err": ""
16+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": 1,
3+
"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\"}",
4+
"ide_settings": "{\"settingVersion\":\"2.0\",\"defaultIde\":\"code-desktop\",\"useLatestVersion\":false}",
5+
"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\":[]}}"
6+
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
{
22
"Resp": {
3-
"envvars": [
4-
{
5-
"name": "GITPOD_IDE_ALIAS",
6-
"value": "code"
7-
}
8-
],
93
"supervisor_image": "eu.gcr.io/gitpod-core-dev/build/supervisor:commit-ff38b98b7dde4929159bcaeec68d178898dc2139",
104
"web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9"
115
},
126
"Err": ""
13-
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": 1,
3+
"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\"}",
4+
"ide_settings": "{\"settingVersion\":\"2.0\",\"defaultIde\":\"intellj\",\"useLatestVersion\":false}",
5+
"workspace_config": "{\"tasks\":[{\"init\":\"echo 'init script'\",\"command\":\"echo 'start script'\"}],\"_origin\":\"repo\",\"image\":\"docker.io/gitpod/workspace-full:latest\",\"vscode\":{\"extensions\":[]}}"
6+
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
{
22
"Resp": {
3-
"envvars": [
4-
{
5-
"name": "GITPOD_IDE_ALIAS",
6-
"value": "intellij"
7-
}
8-
],
93
"supervisor_image": "eu.gcr.io/gitpod-core-dev/build/supervisor:commit-ff38b98b7dde4929159bcaeec68d178898dc2139",
104
"web_image": "eu.gcr.io/gitpod-core-dev/build/ide/code:commit-d6329814c2aa34c414574fd0d1301447d6fe82c9",
115
"ide_image_layers": [
126
"eu.gcr.io/gitpod-core-dev/build/ide/intellij:commit-9a6c79a91b2b1f583d5bcb7f9f1ef54ee977e0df",
13-
"eu.gcr.io/gitpod-core-dev/build/ide/jb-backend-plugin:commit-b38092639d1783a1957894ddd4f492b3cdc9794a"
7+
"eu.gcr.io/gitpod-core-dev/build/ide/intellij:latest@sha256:e07524e52089829dc8d3b38f7d18fb51b24f07aed7d8e4e6e447899687978d43",
8+
"eu.gcr.io/gitpod-core-dev/build/ide/jb-backend-plugin:commit-b38092639d1783a1957894ddd4f492b3cdc9794a",
9+
"eu.gcr.io/gitpod-core-dev/build/ide/jb-backend-plugin:commit-b38092639d1783a1957894ddd4f492b3cdc9794a-latest"
1410
],
15-
"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\"}]\n"
11+
"tasks": "[{\"init\":\"echo 'warming up stable release of intellij...'\\nJETBRAINS_BACKEND_QUALIFIER=stable /ide-desktop/intellij/status warmup intellij\\n\\necho 'warming up latest release of intellij...'\\nJETBRAINS_BACKEND_QUALIFIER=latest /ide-desktop/intellij-latest/status warmup intellij\",\"name\":\"GITPOD_JB_WARMUP_TASK\"}]\n"
1612
},
1713
"Err": ""
1814
}

0 commit comments

Comments
 (0)