diff --git a/components/ide/code/codehelper/main.go b/components/ide/code/codehelper/main.go index 51b55c1727a768..e85db584ac9455 100644 --- a/components/ide/code/codehelper/main.go +++ b/components/ide/code/codehelper/main.go @@ -5,6 +5,7 @@ package main import ( + "bytes" "context" "errors" "io" @@ -36,7 +37,10 @@ var ( Version = "" ) -const Code = "/ide/bin/gitpod-code" +const ( + Code = "/ide/bin/gitpod-code" + ProductJsonLocation = "/ide/product.json" +) func main() { enableDebug := os.Getenv("SUPERVISOR_DEBUG_ENABLE") == "true" @@ -45,6 +49,10 @@ func main() { log.Info("codehelper started") startTime := time.Now() + if err := replaceOpenVSXUrl(); err != nil { + log.WithError(err).Error("failed to replace OpenVSX URL") + } + phaseDone := phaseLogging("ResolveWsInfo") wsInfo, err := resolveWorkspaceInfo(context.Background()) if err != nil || wsInfo == nil { @@ -258,3 +266,22 @@ func phaseLogging(phase string) context.CancelFunc { }() return cancel } + +func replaceOpenVSXUrl() error { + phase := phaseLogging("ReplaceOpenVSXUrl") + defer phase() + b, err := os.ReadFile(ProductJsonLocation) + if err != nil { + return errors.New("failed to read product.json: " + err.Error()) + } + registryUrl := os.Getenv("VSX_REGISTRY_URL") + if registryUrl != "" { + b = bytes.ReplaceAll(b, []byte("https://open-vsx.org"), []byte(registryUrl)) + } + b = bytes.ReplaceAll(b, []byte("{{extensionsGalleryItemUrl}}"), []byte("https://open-vsx.org/vscode/item")) + b = bytes.ReplaceAll(b, []byte("{{trustedDomain}}"), []byte("https://open-vsx.org")) + if err := os.WriteFile(ProductJsonLocation, b, 0644); err != nil { + return errors.New("failed to write product.json: " + err.Error()) + } + return nil +} diff --git a/components/ide/code/startup.sh b/components/ide/code/startup.sh index 913c96d14fbf35..4de39812c71bb6 100755 --- a/components/ide/code/startup.sh +++ b/components/ide/code/startup.sh @@ -32,9 +32,5 @@ export USER=gitpod # shellcheck disable=SC1090,SC1091 [ -s ~/.nvm/nvm-lazy.sh ] && source /home/gitpod/.nvm/nvm-lazy.sh -# Replace OpenVSX URL -grep -rl open-vsx.org /ide | xargs sed -i "s|https://open-vsx.org|$VSX_REGISTRY_URL|g" -grep -rl "{{extensionsGalleryItemUrl}}\|{{trustedDomain}}" /ide | xargs sed -i "s|{{extensionsGalleryItemUrl}}|https://open-vsx.org/vscode/item|g;s|{{trustedDomain}}|https://open-vsx.org|g" - cd /ide || exit exec /ide/codehelper "$@"