Skip to content

[code] Cleanup unused replace rules #18888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 0 additions & 74 deletions components/ide/code/codehelper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package main

import (
"bytes"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -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 {
Expand All @@ -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{}

Expand Down Expand Up @@ -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"))
}
42 changes: 0 additions & 42 deletions install/installer/pkg/components/blobserve/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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}",
Expand Down