Skip to content
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
25 changes: 19 additions & 6 deletions components/gitpod-cli/cmd/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ package cmd

import (
"log"
"os"
"os/exec"
"regexp"
"strconv"
"strings"
"syscall"

"github.com/spf13/cobra"

Expand All @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

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

@csweichel Does it look correct to support command with args? We probably should the same for GP_OPEN_EDITOR otherwise exec.LookPath will fail

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, we should do that for GP_OPEN_EDITOR as well.
I'd be happy to do this in a follow-up PR.

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)
}
Expand All @@ -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://")
}
Expand Down
4 changes: 2 additions & 2 deletions components/gitpod-cli/cmd/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ will print the URL of a service/server exposed on port 8080.`,
return
}

fmt.Println(getWorkspaceURL(port))
fmt.Println(GetWorkspaceURL(port))
},
}

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
Expand Down
3 changes: 2 additions & 1 deletion components/ide/code/leeway.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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"