Skip to content

Commit 75753c1

Browse files
authored
[code] Pass GITPOD_CODE_HOST when starting vscode server (#18730)
* Pass GITPOD_CODE_HOST when starting vscode server * 🧹 * Fix
1 parent 0bc9cb3 commit 75753c1

File tree

4 files changed

+21
-44
lines changed

4 files changed

+21
-44
lines changed

WORKSPACE.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ defaultArgs:
77
publishToNPM: true
88
publishToJBMarketplace: true
99
localAppVersion: unknown
10-
codeCommit: 7a889d86d94c160fa1a4cab832cdbcf45eac0f88
11-
codeVersion: 1.82.2
10+
codeCommit: 8bcdbe5e6e097191649984c8329af15a3e6b3066
11+
codeVersion: 1.83.0
1212
codeQuality: stable
1313
noVerifyJBPlugin: false
1414
intellijDownloadUrl: "https://download.jetbrains.com/idea/ideaIU-2023.2.2.tar.gz"

components/ide/code/codehelper/main.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,21 @@ func main() {
6161
}
6262
phaseDone()
6363

64+
url, err := url.Parse(wsInfo.GitpodHost)
65+
if err != nil {
66+
log.WithError(err).Errorf("failed to parse GitpodHost %s", wsInfo.GitpodHost)
67+
return
68+
}
69+
domain := url.Hostname()
70+
6471
if wsInfo.DebugWorkspaceType != supervisor.DebugWorkspaceType_noDebug {
6572
// TODO actually should be performed always
6673
// the better way would be to apply replacements during a workspace start
6774
// to aling with content in blobserve
68-
if err := prepareWebWorkbenchMain(wsInfo); err != nil {
75+
if err := prepareWebWorkbenchMain(domain); err != nil {
6976
log.WithError(err).Error("failed to prepare web workbench")
7077
}
71-
if err := prepareServerMain(wsInfo); err != nil {
78+
if err := prepareServerMain(domain); err != nil {
7279
log.WithError(err).Error("failed to prepare server")
7380
}
7481
}
@@ -132,8 +139,9 @@ func main() {
132139
args = append(args, os.Args[1:]...)
133140
args = append(args, "--do-not-sync")
134141
args = append(args, "--start-server")
142+
cmdEnv := append(os.Environ(), fmt.Sprintf("GITPOD_CODE_HOST=%s", domain))
135143
log.WithField("cost", time.Now().Local().Sub(startTime).Milliseconds()).Info("starting server")
136-
if err := syscall.Exec(Code, append([]string{"gitpod-code"}, args...), os.Environ()); err != nil {
144+
if err := syscall.Exec(Code, append([]string{"gitpod-code"}, args...), cmdEnv); err != nil {
137145
log.WithError(err).Error("install ext and start code server failed")
138146
}
139147
}
@@ -246,18 +254,13 @@ func replaceOpenVSXUrl() error {
246254

247255
// TODO it is be applied as well by blobserve if served for regular workspace location
248256
// reconsider how to configure in all modes, i.e. regular, debug, dev
249-
func prepareWebWorkbenchMain(wsInfo *supervisor.WorkspaceInfoResponse) error {
257+
func prepareWebWorkbenchMain(domain string) error {
250258
phase := phaseLogging("prepareWebWorkbenchMain")
251259
defer phase()
252260
b, err := os.ReadFile(WebWorkbenchMainLocation)
253261
if err != nil {
254262
return errors.New("failed to read " + WebWorkbenchMainLocation + ": " + err.Error())
255263
}
256-
url, err := url.Parse(wsInfo.GitpodHost)
257-
if err != nil {
258-
return errors.New("failed to parse " + wsInfo.GitpodHost + ": " + err.Error())
259-
}
260-
domain := url.Hostname()
261264
b = bytes.ReplaceAll(b, []byte("vscode-cdn.net"), []byte(domain))
262265
b = bytes.ReplaceAll(b, []byte("ide.gitpod.io/code/markeplace.json"), []byte(fmt.Sprintf("ide.%s/code/marketplace.json", domain)))
263266

@@ -269,18 +272,13 @@ func prepareWebWorkbenchMain(wsInfo *supervisor.WorkspaceInfoResponse) error {
269272
return nil
270273
}
271274

272-
func prepareServerMain(wsInfo *supervisor.WorkspaceInfoResponse) error {
275+
func prepareServerMain(domain string) error {
273276
phase := phaseLogging("prepareServerMain")
274277
defer phase()
275278
b, err := os.ReadFile(ServerMainLocation)
276279
if err != nil {
277280
return errors.New("failed to read " + ServerMainLocation + ": " + err.Error())
278281
}
279-
url, err := url.Parse(wsInfo.GitpodHost)
280-
if err != nil {
281-
return errors.New("failed to parse " + wsInfo.GitpodHost + ": " + err.Error())
282-
}
283-
domain := url.Hostname()
284282
b = bytes.ReplaceAll(b, []byte("https://*.vscode-cdn.net"), []byte(fmt.Sprintf("https://%s https://*.%s", domain, domain)))
285283
if err := os.WriteFile(ServerMainLocation, b, 0644); err != nil {
286284
return errors.New("failed to write " + ServerMainLocation + ": " + err.Error())

components/ide/code/leeway.Dockerfile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ RUN nameShort=$(jq --raw-output '.nameShort' product.json) && \
5555
setNameShort="setpath([\"nameShort\"]; \"$nameShort\")" && \
5656
setNameLong="setpath([\"nameLong\"]; \"$nameLong\")" && \
5757
setSegmentKey="setpath([\"segmentKey\"]; \"untrusted-dummy-key\")" && \
58-
setExtensionsGalleryItemUrl="setpath([\"extensionsGallery\", \"itemUrl\"]; \"{{extensionsGalleryItemUrl}}\")" && \
59-
addTrustedDomain=".linkProtectionTrustedDomains += [\"{{trustedDomain}}\"]" && \
60-
jqCommands="${setQuality} | ${setNameShort} | ${setNameLong} | ${setSegmentKey} | ${setExtensionsGalleryItemUrl} | ${addTrustedDomain}" && \
58+
jqCommands="${setQuality} | ${setNameShort} | ${setNameLong} | ${setSegmentKey}" && \
6159
cat product.json | jq "${jqCommands}" > product.json.tmp && \
6260
mv product.json.tmp product.json && \
6361
jq '{quality,nameLong,nameShort}' product.json
@@ -69,15 +67,10 @@ RUN yarn gulp compile-build \
6967
&& yarn gulp vscode-reh-linux-x64-min-ci
7068

7169
# config for first layer needed by blobserve
72-
# we also remove `static/` from resource urls as that's needed by blobserve,
7370
# this custom urls will be then replaced by blobserve.
7471
# Check pkg/blobserve/blobserve.go, `inlineVars` method
7572
RUN cp /vscode-web/out/vs/gitpod/browser/workbench/workbench.html /vscode-web/index.html \
7673
&& cp /vscode-web/out/vs/gitpod/browser/workbench/callback.html /vscode-web/callback.html \
77-
# TODO: remove next line when workbench.html changes are merged to gp-code/main
78-
&& sed -i -e 's#static/##g' /vscode-web/index.html \
79-
&& sed -i -e 's#baseUrl =.*;#baseUrl = window.location.origin;#g' /vscode-web/index.html \
80-
&& sed -i -e 's#{{WORKBENCH_WEB_BASE_URL}}#.#g' /vscode-web/index.html \
8174
&& sed -i -e "s/{{VERSION}}/$CODE_QUALITY-$CODE_COMMIT/g" /vscode-web/index.html
8275

8376
# cli config: alises to gitpod-code

install/installer/pkg/components/blobserve/configmap.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
2828
//nolint:typecheck
2929
openVSXProxyUrl := "vsx-proxy-host"
3030
if hasOpenVSXProxy {
31-
openVSXProxyUrl = fmt.Sprintf("open-vsx.%s", ctx.Config.Domain)
31+
openVSXProxyUrl = fmt.Sprintf("https://open-vsx.%s", ctx.Config.Domain)
3232
}
3333

3434
// Check also link below before change values
@@ -49,21 +49,13 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
4949
Replacement: ctx.Config.Domain,
5050
Path: "/ide/out/vs/workbench/workbench.web.main.js",
5151
}, {
52-
Search: "open-vsx.org",
52+
Search: "https://open-vsx.org",
5353
Replacement: openVSXProxyUrl,
5454
Path: "/ide/out/vs/workbench/workbench.web.main.js",
55-
}, {
56-
Search: "{{extensionsGalleryItemUrl}}",
57-
Replacement: extensionsGalleryItemUrl,
58-
Path: "/ide/out/vs/workbench/workbench.web.api.js",
5955
}, {
6056
Search: "{{extensionsGalleryItemUrl}}",
6157
Replacement: extensionsGalleryItemUrl,
6258
Path: "/ide/out/vs/workbench/workbench.web.main.js",
63-
}, {
64-
Search: "{{trustedDomain}}",
65-
Replacement: trustedDomain,
66-
Path: "/ide/out/vs/workbench/workbench.web.api.js",
6759
}, {
6860
Search: "{{trustedDomain}}",
6961
Replacement: trustedDomain,
@@ -76,20 +68,14 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
7668
// TODO consider to provide it as a part of image label or rather inline ${ide} and ${supervisor} in index.html
7769
// to decouple blobserve and code image
7870
InlineStatic: []blobserve_config.InlineReplacement{{
71+
Search: "{{WORKBENCH_WEB_BASE_URL}}",
72+
Replacement: "${ide}",
73+
}, {
7974
Search: "window.location.origin;",
8075
Replacement: "'${ide}';",
81-
}, {
82-
Search: "${window.location.origin}",
83-
Replacement: ".",
84-
}, {
85-
Search: "value.startsWith(window.location.origin)",
86-
Replacement: "value.startsWith(window.location.origin) || value.startsWith('${ide}')",
8776
}, {
8877
Search: "./out",
8978
Replacement: "${ide}/out",
90-
}, {
91-
Search: "./node_modules",
92-
Replacement: "${ide}/node_modules",
9379
}, {
9480
Search: "/_supervisor/frontend",
9581
Replacement: "${supervisor}",

0 commit comments

Comments
 (0)