diff --git a/components/gitpod-cli/cmd/preview.go b/components/gitpod-cli/cmd/preview.go index 2be346344904b8..35c588bcaffdc9 100644 --- a/components/gitpod-cli/cmd/preview.go +++ b/components/gitpod-cli/cmd/preview.go @@ -6,9 +6,12 @@ package cmd import ( "log" + "os" + "os/exec" "regexp" "strconv" "strings" + "syscall" "github.com/spf13/cobra" @@ -32,6 +35,21 @@ var previewCmd = &cobra.Command{ url = replaceLocalhostInURL(service, url) _, err = service.OpenPreview(theialib.OpenPreviewRequest{URL: url}) + if err == theialib.ErrNotFound { + gpPreviewBrowser := os.Getenv("GP_PREVIEW_BROWSER") + if gpPreviewBrowser != "" { + gpPreviewArgs := strings.Fields(gpPreviewBrowser) + argv0, err := exec.LookPath(gpPreviewArgs[0]) + if err != nil { + log.Fatal(err) + } + err = syscall.Exec(argv0, append(gpPreviewArgs, url), os.Environ()) + if err != nil { + log.Fatal(err) + } + return + } + } if err != nil { log.Fatal(err) } @@ -49,12 +67,7 @@ func replaceLocalhostInURL(service theialib.TheiaCLIService, url string) string port, _ = strconv.Atoi(strings.TrimPrefix(segs[1], ":")) } - resp, err := service.GetPortURL(theialib.GetPortURLRequest{Port: uint16(port)}) - if err != nil { - return input - } - - result := resp.URL + result := GetWorkspaceURL(port) if !hasScheme { result = strings.TrimPrefix(strings.TrimPrefix(result, "http://"), "https://") } diff --git a/components/gitpod-cli/cmd/url.go b/components/gitpod-cli/cmd/url.go index 93a9f25e42533a..927328fef3a322 100644 --- a/components/gitpod-cli/cmd/url.go +++ b/components/gitpod-cli/cmd/url.go @@ -40,7 +40,7 @@ will print the URL of a service/server exposed on port 8080.`, return } - fmt.Println(getWorkspaceURL(port)) + fmt.Println(GetWorkspaceURL(port)) }, } @@ -48,7 +48,7 @@ func init() { rootCmd.AddCommand(urlCmd) } -func getWorkspaceURL(port int) (url string) { +func GetWorkspaceURL(port int) (url string) { wsurl := os.Getenv("GITPOD_WORKSPACE_URL") if port == 0 { return wsurl diff --git a/components/ide/code/leeway.Dockerfile b/components/ide/code/leeway.Dockerfile index cd83b74eca3f0a..df6b3a19818131 100644 --- a/components/ide/code/leeway.Dockerfile +++ b/components/ide/code/leeway.Dockerfile @@ -28,7 +28,7 @@ RUN sudo apt-get update \ && sudo apt-get clean -y \ && rm -rf /var/lib/apt/lists/* -ENV GP_CODE_COMMIT 845053f04b5d9efd17f6f7626ba362925bd0bfe5 +ENV GP_CODE_COMMIT f75d023a0b4954d2f5d74bc7a08a713673b93969 RUN mkdir gp-code \ && cd gp-code \ && git init \ @@ -62,3 +62,4 @@ ENV GITPOD_ENV_SET_EDITOR code ENV GITPOD_ENV_SET_VISUAL "$GITPOD_ENV_SET_EDITOR" ENV GITPOD_ENV_SET_GP_OPEN_EDITOR "$GITPOD_ENV_SET_EDITOR" ENV GITPOD_ENV_SET_GIT_EDITOR "$GITPOD_ENV_SET_EDITOR --wait" +ENV GITPOD_ENV_SET_GP_PREVIEW_BROWSER "code --command gitpod.api.preview"