Skip to content

Commit 49f5135

Browse files
committed
[jb] enable vmoptions config in .gitpod.yml
1 parent a705517 commit 49f5135

File tree

9 files changed

+99
-13
lines changed

9 files changed

+99
-13
lines changed

components/gitpod-protocol/data/gitpod-schema.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@
287287
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
288288
}
289289
}
290+
},
291+
"vmoptions": {
292+
"type": "string",
293+
"description": "Configure VM options, for instance '-Xmx=4096m'."
290294
}
291295
}
292296
},
@@ -317,6 +321,10 @@
317321
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
318322
}
319323
}
324+
},
325+
"vmoptions": {
326+
"type": "string",
327+
"description": "Configure VM options, for instance '-Xmx=4096m'."
320328
}
321329
}
322330
},
@@ -347,6 +355,10 @@
347355
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
348356
}
349357
}
358+
},
359+
"vmoptions": {
360+
"type": "string",
361+
"description": "Configure VM options, for instance '-Xmx=4096m'."
350362
}
351363
}
352364
},
@@ -377,6 +389,10 @@
377389
"description": "Whether only stable, latest or both versions should be warmed up. Default is stable only."
378390
}
379391
}
392+
},
393+
"vmoptions": {
394+
"type": "string",
395+
"description": "Configure VM options, for instance '-Xmx=4096m'."
380396
}
381397
}
382398
}

components/gitpod-protocol/go/gitpod-config-types.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/gitpod-protocol/src/protocol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ export interface JetBrainsConfig {
640640
}
641641
export interface JetBrainsProductConfig {
642642
prebuilds?: JetBrainsPrebuilds;
643+
vmoptions?: string;
643644
}
644645
export interface JetBrainsPrebuilds {
645646
version?: "stable" | "latest" | "both";

components/ide/jetbrains/image/status/BUILD.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ packages:
22
- name: app
33
type: go
44
srcs:
5+
- "testdata/**"
56
- "**/*.go"
67
- "go.mod"
78
- "go.sum"

components/ide/jetbrains/image/status/go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ go 1.18
55
require (
66
github.com/gitpod-io/gitpod/supervisor/api v0.0.0-00010101000000-000000000000
77
github.com/google/go-cmp v0.5.7
8+
github.com/stretchr/testify v1.7.0
89
)
910

1011
require (
12+
github.com/davecgh/go-spew v1.1.1 // indirect
1113
github.com/golang/mock v1.6.0 // indirect
1214
github.com/gorilla/websocket v1.5.0 // indirect
15+
github.com/pmezard/go-difflib v1.0.0 // indirect
1316
github.com/sirupsen/logrus v1.8.1 // indirect
1417
github.com/sourcegraph/jsonrpc2 v0.0.0-20200429184054-15c2290dcb37 // indirect
18+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
1519
)
1620

1721
require (

components/ide/jetbrains/image/status/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
428428
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
429429
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
430430
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
431+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
431432
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
432433
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
433434
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

components/ide/jetbrains/image/status/main.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,14 @@ func main() {
7676
}
7777
log.WithField("cost", time.Now().Local().Sub(startTime).Milliseconds()).Info("content available")
7878

79+
repoRoot := wsInfo.GetCheckoutLocation()
80+
gitpodConfig, err := parseGitpodConfig(repoRoot)
81+
if err != nil {
82+
log.WithError(err).Error("failed to parse .gitpod.yml")
83+
}
7984
version_2022_1, _ := version.NewVersion("2022.1")
8085
if version_2022_1.LessThanOrEqual(backendVersion) {
81-
err = installPlugins(wsInfo, alias)
86+
err = installPlugins(repoRoot, gitpodConfig, alias)
8287
installPluginsCost := time.Now().Local().Sub(startTime).Milliseconds()
8388
if err != nil {
8489
log.WithError(err).WithField("cost", installPluginsCost).Error("installing repo plugins: done")
@@ -87,7 +92,7 @@ func main() {
8792
}
8893
}
8994

90-
err = configureVMOptions(alias)
95+
err = configureVMOptions(gitpodConfig, alias)
9196
if err != nil {
9297
log.WithError(err).Error("failed to configure vmoptions")
9398
}
@@ -307,7 +312,7 @@ func handleSignal(projectPath string) {
307312
log.Info("asked IDE to terminate")
308313
}
309314

310-
func configureVMOptions(alias string) error {
315+
func configureVMOptions(config *gitpod.GitpodConfig, alias string) error {
311316
idePrefix := alias
312317
if alias == "intellij" {
313318
idePrefix = "idea"
@@ -318,7 +323,7 @@ func configureVMOptions(alias string) error {
318323
if err != nil {
319324
return err
320325
}
321-
newContent := updateVMOptions(alias, string(content))
326+
newContent := updateVMOptions(config, alias, string(content))
322327
return ioutil.WriteFile(path, []byte(newContent), 0)
323328
}
324329

@@ -340,7 +345,7 @@ func deduplicateVMOption(oldLines []string, newLines []string, predicate func(l,
340345
return result
341346
}
342347

343-
func updateVMOptions(alias string, content string) string {
348+
func updateVMOptions(config *gitpod.GitpodConfig, alias string, content string) string {
344349
// inspired by how intellij platform merge the VMOptions
345350
// https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/openapi/application/ConfigImportHelper.java#L1115
346351
filterFunc := func(l, r string) bool {
@@ -358,12 +363,24 @@ func updateVMOptions(alias string, content string) string {
358363
gitpodVMOptions := []string{"-Dgtw.disable.exit.dialog=true"}
359364
vmoptions := deduplicateVMOption(ideaVMOptionsLines, gitpodVMOptions, filterFunc)
360365

361-
// user-defined vmoptions
366+
// user-defined vmoptions (EnvVar)
362367
userVMOptionsVar := os.Getenv(strings.ToUpper(alias) + "_VMOPTIONS")
363368
userVMOptions := strings.Fields(userVMOptionsVar)
364369
if len(userVMOptions) > 0 {
365370
vmoptions = deduplicateVMOption(vmoptions, userVMOptions, filterFunc)
366371
}
372+
373+
// project-defined vmoptions (.gitpod.yml)
374+
if config != nil {
375+
productConfig := getProductConfig(config, alias)
376+
if productConfig != nil {
377+
projectVMOptions := strings.Fields(productConfig.VMOptions)
378+
if len(projectVMOptions) > 0 {
379+
vmoptions = deduplicateVMOption(vmoptions, projectVMOptions, filterFunc)
380+
}
381+
}
382+
}
383+
367384
// vmoptions file should end with a newline
368385
return strings.Join(vmoptions, "\n") + "\n"
369386
}
@@ -410,8 +427,8 @@ func resolveBackendVersion() (*version.Version, error) {
410427
return version.NewVersion(info.Version)
411428
}
412429

413-
func installPlugins(wsInfo *supervisor.WorkspaceInfoResponse, alias string) error {
414-
plugins, err := getPlugins(wsInfo.GetCheckoutLocation(), alias)
430+
func installPlugins(repoRoot string, config *gitpod.GitpodConfig, alias string) error {
431+
plugins, err := getPlugins(config, alias)
415432
if err != nil {
416433
return err
417434
}
@@ -433,7 +450,7 @@ func installPlugins(wsInfo *supervisor.WorkspaceInfoResponse, alias string) erro
433450

434451
var args []string
435452
args = append(args, "installPlugins")
436-
args = append(args, wsInfo.GetCheckoutLocation())
453+
args = append(args, repoRoot)
437454
args = append(args, plugins...)
438455
cmd := remoteDevServerCmd(args)
439456
cmd.Stdout = io.MultiWriter(w, os.Stdout)
@@ -458,7 +475,7 @@ func installPlugins(wsInfo *supervisor.WorkspaceInfoResponse, alias string) erro
458475
return nil
459476
}
460477

461-
func getPlugins(repoRoot string, alias string) ([]string, error) {
478+
func parseGitpodConfig(repoRoot string) (*gitpod.GitpodConfig, error) {
462479
if repoRoot == "" {
463480
return nil, errors.New("repoRoot is empty")
464481
}
@@ -474,11 +491,14 @@ func getPlugins(repoRoot string, alias string) ([]string, error) {
474491
if err = yaml.Unmarshal(data, &config); err != nil {
475492
return nil, errors.New("unmarshal .gitpod.yml file failed" + err.Error())
476493
}
494+
return config, nil
495+
}
477496

497+
func getPlugins(config *gitpod.GitpodConfig, alias string) ([]string, error) {
498+
var plugins []string
478499
if config == nil || config.JetBrains == nil {
479500
return nil, nil
480501
}
481-
var plugins []string
482502
if config.JetBrains.Plugins != nil {
483503
plugins = append(plugins, config.JetBrains.Plugins...)
484504
}

components/ide/jetbrains/image/status/main_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
protocol "github.com/gitpod-io/gitpod/gitpod-protocol"
1212
"github.com/google/go-cmp/cmp"
1313
"github.com/google/go-cmp/cmp/cmpopts"
14+
"github.com/stretchr/testify/assert"
1415
)
1516

1617
func TestGetProductConfig(t *testing.T) {
@@ -26,6 +27,14 @@ func TestGetProductConfig(t *testing.T) {
2627
}
2728
}
2829

30+
func TestParseGitpodConfig(t *testing.T) {
31+
gitpodConfig, _ := parseGitpodConfig("testdata")
32+
assert.Equal(t, 1, len(gitpodConfig.JetBrains.IntelliJ.Plugins))
33+
assert.Equal(t, "both", gitpodConfig.JetBrains.IntelliJ.Prebuilds.Version)
34+
assert.Equal(t, "-Xmx3g", gitpodConfig.JetBrains.IntelliJ.VMOptions)
35+
assert.Equal(t, "-Xmx4096m -XX:MaxRAMPercentage=75", gitpodConfig.JetBrains.GoLand.VMOptions)
36+
}
37+
2938
func TestUpdateVMOptions(t *testing.T) {
3039
tests := []struct {
3140
Desc string
@@ -49,7 +58,7 @@ func TestUpdateVMOptions(t *testing.T) {
4958
lessFunc := func(a, b string) bool { return a < b }
5059

5160
t.Run(test.Desc, func(t *testing.T) {
52-
actual := updateVMOptions(test.Alias, test.Src)
61+
actual := updateVMOptions(nil, test.Alias, test.Src)
5362
if diff := cmp.Diff(strings.Fields(test.Expectation), strings.Fields(actual), cmpopts.SortSlices(lessFunc)); diff != "" {
5463
t.Errorf("unexpected output (-want +got):\n%s", diff)
5564
}
@@ -58,7 +67,7 @@ func TestUpdateVMOptions(t *testing.T) {
5867
t.Run("updateVMOptions multiple time should be stable", func(t *testing.T) {
5968
actual := test.Src
6069
for i := 0; i < 5; i++ {
61-
actual = updateVMOptions(test.Alias, actual)
70+
actual = updateVMOptions(nil, test.Alias, actual)
6271
if diff := cmp.Diff(strings.Fields(test.Expectation), strings.Fields(actual), cmpopts.SortSlices(lessFunc)); diff != "" {
6372
t.Errorf("unexpected output (-want +got):\n%s", diff)
6473
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
# Licensed under the GNU Affero General Public License (AGPL).
3+
# See License-AGPL.txt in the project root for license information.
4+
5+
# see https://github.com/gitpod-io/spring-petclinic/blob/master/.gitpod.yml
6+
tasks:
7+
- init: ./mvnw package -DskipTests
8+
command: java -jar target/*.jar
9+
name: Run PetClinic app
10+
11+
# exposed ports
12+
ports:
13+
- port: 8080
14+
onOpen: open-preview
15+
16+
vscode:
17+
extensions:
18+
- redhat.java
19+
- vscjava.vscode-java-debug
20+
- vscjava.vscode-java-test
21+
- pivotal.vscode-spring-boot
22+
23+
jetbrains:
24+
intellij:
25+
plugins:
26+
- com.haulmont.jpab
27+
prebuilds:
28+
version: both
29+
vmoptions: "-Xmx3g"
30+
goland:
31+
vmoptions: "-Xmx4096m -XX:MaxRAMPercentage=75"

0 commit comments

Comments
 (0)