Skip to content
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

[codehelper] replace product.json only #14821

Merged
merged 1 commit into from
Nov 21, 2022
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
29 changes: 28 additions & 1 deletion components/ide/code/codehelper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"bytes"
"context"
"errors"
"io"
Expand Down Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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"))
Comment on lines +281 to +282
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mustard-mh I have a dumb question, why this got added 😅? I see they are added in dockerfile and then replaced here and in blobserve and they are just harcoded constant values 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember, maybe just a dumb action I did. 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akosyakov @iQQBot do you remember?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like can be removed.

Copy link
Contributor Author

@mustard-mh mustard-mh Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remembered what happened, https://open-vsx.org ({{trustedDomain}}) is too normal to replace in startup.sh, so I need to replace it to something more special, in case it is replaced by our openvsx-proxy in startup.sh.

Looks like we still need it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the final value is harcoded here and in blobserve, where is openvsx-proxy updating this variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will replace them

b = bytes.ReplaceAll(b, []byte("https://open-vsx.org"), []byte(registryUrl))

And installer will replace https://open-vsx.org again

Copy link
Member

@jeanp413 jeanp413 Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah proxy url is fine, that needs to be replaced and that's why the first grep was needed.

I'm referring to {{extensionsGalleryItemUrl}}, {{trustedDomain}} they are replaced with constant values, the same values that are already in product.json in gp-code/main branch, it doesn't change like VSX_REGISTRY_URL that changes for each SH installation.

So just remove them then?

Copy link
Contributor Author

@mustard-mh mustard-mh Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constant value are https://open-vsx.org and https://open-vsx.org/vscode/item they all contains open-vsx.org which will be replaced in installer and codehelper (startup.sh).

But we don't want them to be changed.

  • In codehelper, we can use sjson to Set value with json path we want
  • In installer, it's just global replacement

So we still need them because of installer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I get it now 💡 , but then can we make the search more specific (with a regex maybe) so it doesn't replace the other values, right now it's not obvious at all

if err := os.WriteFile(ProductJsonLocation, b, 0644); err != nil {
return errors.New("failed to write product.json: " + err.Error())
}
return nil
}
4 changes: 0 additions & 4 deletions components/ide/code/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"