From 14d20ceca988730a4f2607326fafe512cc1145b4 Mon Sep 17 00:00:00 2001 From: Jean Pierre Date: Mon, 9 Oct 2023 14:41:17 -0500 Subject: [PATCH] [code] Cleanup unused replace rules (#18888) --- components/ide/code/codehelper/main.go | 74 ------------------- .../pkg/components/blobserve/configmap.go | 42 ----------- 2 files changed, 116 deletions(-) diff --git a/components/ide/code/codehelper/main.go b/components/ide/code/codehelper/main.go index 05a776c46eecaa..c8ca87fe22d134 100644 --- a/components/ide/code/codehelper/main.go +++ b/components/ide/code/codehelper/main.go @@ -5,7 +5,6 @@ package main import ( - "bytes" "context" "errors" "fmt" @@ -49,10 +48,6 @@ 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") cstate, wsInfo, err := resolveWorkspaceInfo(context.Background()) if err != nil || wsInfo == nil { @@ -68,18 +63,6 @@ func main() { } domain := url.Hostname() - if wsInfo.DebugWorkspaceType != supervisor.DebugWorkspaceType_noDebug { - // TODO actually should be performed always - // the better way would be to apply replacements during a workspace start - // to aling with content in blobserve - if err := prepareWebWorkbenchMain(domain); err != nil { - log.WithError(err).Error("failed to prepare web workbench") - } - if err := prepareServerMain(domain); err != nil { - log.WithError(err).Error("failed to prepare server") - } - } - // code server args install extension with id args := []string{} @@ -237,60 +220,3 @@ 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()) - } - b = replaceOpenVSX(b) - if err := os.WriteFile(ProductJsonLocation, b, 0644); err != nil { - return errors.New("failed to write product.json: " + err.Error()) - } - return nil -} - -// TODO it is be applied as well by blobserve if served for regular workspace location -// reconsider how to configure in all modes, i.e. regular, debug, dev -func prepareWebWorkbenchMain(domain string) error { - phase := phaseLogging("prepareWebWorkbenchMain") - defer phase() - b, err := os.ReadFile(WebWorkbenchMainLocation) - if err != nil { - return errors.New("failed to read " + WebWorkbenchMainLocation + ": " + err.Error()) - } - b = bytes.ReplaceAll(b, []byte("vscode-cdn.net"), []byte(domain)) - b = bytes.ReplaceAll(b, []byte("ide.gitpod.io/code/markeplace.json"), []byte(fmt.Sprintf("ide.%s/code/marketplace.json", domain))) - - b = replaceOpenVSX(b) - - if err := os.WriteFile(WebWorkbenchMainLocation, b, 0644); err != nil { - return errors.New("failed to write " + WebWorkbenchMainLocation + ": " + err.Error()) - } - return nil -} - -func prepareServerMain(domain string) error { - phase := phaseLogging("prepareServerMain") - defer phase() - b, err := os.ReadFile(ServerMainLocation) - if err != nil { - return errors.New("failed to read " + ServerMainLocation + ": " + err.Error()) - } - b = bytes.ReplaceAll(b, []byte("https://*.vscode-cdn.net"), []byte(fmt.Sprintf("https://%s https://*.%s", domain, domain))) - if err := os.WriteFile(ServerMainLocation, b, 0644); err != nil { - return errors.New("failed to write " + ServerMainLocation + ": " + err.Error()) - } - return nil -} - -func replaceOpenVSX(b []byte) []byte { - 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")) - return bytes.ReplaceAll(b, []byte("{{trustedDomain}}"), []byte("https://open-vsx.org")) -} diff --git a/install/installer/pkg/components/blobserve/configmap.go b/install/installer/pkg/components/blobserve/configmap.go index 91bed48937286a..bdbd09579fb86c 100644 --- a/install/installer/pkg/components/blobserve/configmap.go +++ b/install/installer/pkg/components/blobserve/configmap.go @@ -21,21 +21,6 @@ import ( ) func configmap(ctx *common.RenderContext) ([]runtime.Object, error) { - // todo(sje): find this value - hasOpenVSXProxy := true - - // todo(sje): find this value - //nolint:typecheck - openVSXProxyUrl := "vsx-proxy-host" - if hasOpenVSXProxy { - openVSXProxyUrl = fmt.Sprintf("https://open-vsx.%s", ctx.Config.Domain) - } - - // Check also link below before change values - // https://github.com/gitpod-io/gitpod/blob/2cba7bd1d8a2accd294ab7733f6da4532e48984c/components/ide/code/startup.sh#L37 - extensionsGalleryItemUrl := "https://open-vsx.org/vscode/item" - trustedDomain := "https://open-vsx.org" - bscfg := blobserve_config.Config{ BlobServe: blobserve_config.BlobServe{ Port: ContainerPort, @@ -44,38 +29,11 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) { ctx.RepoName(ctx.Config.Repository, ide.CodeIDEImage): { PrePull: []string{}, Workdir: "/ide", - Replacements: []blobserve_config.StringReplacement{{ - Search: "vscode-cdn.net", - Replacement: ctx.Config.Domain, - Path: "/ide/out/vs/workbench/workbench.web.main.js", - }, { - Search: "https://open-vsx.org", - Replacement: openVSXProxyUrl, - Path: "/ide/out/vs/workbench/workbench.web.main.js", - }, { - Search: "{{extensionsGalleryItemUrl}}", - Replacement: extensionsGalleryItemUrl, - Path: "/ide/out/vs/workbench/workbench.web.main.js", - }, { - Search: "{{trustedDomain}}", - Replacement: trustedDomain, - Path: "/ide/out/vs/workbench/workbench.web.main.js", - }, { - Search: "ide.gitpod.io/code/markeplace.json", - Replacement: fmt.Sprintf("ide.%s/code/marketplace.json", ctx.Config.Domain), - Path: "/ide/out/vs/workbench/workbench.web.main.js", - }}, // TODO consider to provide it as a part of image label or rather inline ${ide} and ${supervisor} in index.html // to decouple blobserve and code image InlineStatic: []blobserve_config.InlineReplacement{{ Search: "{{WORKBENCH_WEB_BASE_URL}}", Replacement: "${ide}", - }, { - Search: "window.location.origin;", - Replacement: "'${ide}';", - }, { - Search: "./out", - Replacement: "${ide}/out", }, { Search: "/_supervisor/frontend", Replacement: "${supervisor}",