Skip to content

Commit c4fdd56

Browse files
committed
[supervisor] active client notifications
1 parent 57a0bb9 commit c4fdd56

File tree

38 files changed

+669
-254
lines changed

38 files changed

+669
-254
lines changed

WORKSPACE.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ defaultArgs:
77
publishToNPM: true
88
publishToJBMarketplace: true
99
localAppVersion: unknown
10-
codeCommit: 192057dab1df3cbfc64e83719306de0727a644e0
11-
codeVersion: 1.74.3
10+
codeCommit: 704aa0e3f54ba6b64dc1b443b4b61a5a717a38e9
11+
codeVersion: 1.75.0
1212
codeQuality: stable
1313
noVerifyJBPlugin: false
1414
intellijDownloadUrl: "https://download.jetbrains.com/idea/ideaIU-2022.3.1.tar.gz"

components/gitpod-cli/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gitpod-cli

components/gitpod-cli/cmd/docs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var docsCmd = &cobra.Command{
1515
Use: "docs",
1616
Short: "Open Gitpod Documentation in default browser",
1717
Run: func(cmd *cobra.Command, args []string) {
18-
openPreview("GP_EXTERNAL_BROWSER", DocsUrl)
18+
openPreview(cmd.Context(), DocsUrl, true)
1919
},
2020
}
2121

components/gitpod-cli/cmd/open.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
package cmd
66

77
import (
8-
"context"
98
"log"
109
"os"
1110
"os/exec"
11+
"path/filepath"
1212

1313
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor"
14+
"github.com/gitpod-io/gitpod/supervisor/api"
1415

1516
"github.com/google/shlex"
1617
"github.com/spf13/cobra"
@@ -23,25 +24,41 @@ var openCmd = &cobra.Command{
2324
Short: "Opens a file in Gitpod",
2425
Args: cobra.MinimumNArgs(1),
2526
Run: func(cmd *cobra.Command, args []string) {
26-
// TODO(ak) use NotificationService.NotifyActive supervisor API instead
27-
28-
ctx := context.Background()
29-
27+
ctx := cmd.Context()
3028
client, err := supervisor.New(ctx)
3129
if err != nil {
3230
log.Fatal(err)
3331
}
3432
defer client.Close()
35-
3633
client.WaitForIDEReady(ctx)
3734

3835
wait, _ := cmd.Flags().GetBool("wait")
3936

4037
pcmd := os.Getenv("GP_OPEN_EDITOR")
4138
if pcmd == "" {
42-
log.Fatal("GP_OPEN_EDITOR is not set")
39+
var paths []string
40+
for _, path := range args {
41+
absPath, err := filepath.Abs(path)
42+
if err == nil {
43+
path = absPath
44+
}
45+
paths = append(paths, path)
46+
}
47+
48+
_, err := client.Notification.NotifyActive(ctx, &api.NotifyActiveRequest{
49+
ActionData: &api.NotifyActiveRequest_Open{
50+
Open: &api.NotifyActiveRequest_OpenData{
51+
Paths: paths,
52+
Await: wait,
53+
},
54+
},
55+
})
56+
if err != nil && ctx.Err() == nil {
57+
log.Fatal(err)
58+
}
4359
return
4460
}
61+
// TODO: backward compatibilty, remove when all IDEs are updated
4562
pargs, err := shlex.Split(pcmd)
4663
if err != nil {
4764
log.Fatalf("cannot parse GP_OPEN_EDITOR: %v", err)

components/gitpod-cli/cmd/preview.go

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"strings"
1515

1616
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/supervisor"
17+
"github.com/gitpod-io/gitpod/supervisor/api"
1718
"github.com/google/shlex"
1819
"github.com/spf13/cobra"
1920
"golang.org/x/sys/unix"
@@ -31,31 +32,42 @@ var previewCmd = &cobra.Command{
3132
Short: "Opens a URL in the IDE's preview",
3233
Args: cobra.ExactArgs(1),
3334
Run: func(cmd *cobra.Command, args []string) {
34-
// TODO(ak) use NotificationService.NotifyActive supervisor API instead
35-
36-
ctx := context.Background()
37-
38-
client, err := supervisor.New(ctx)
39-
if err != nil {
40-
log.Fatal(err)
41-
}
42-
defer client.Close()
43-
client.WaitForIDEReady(ctx)
44-
45-
url := replaceLocalhostInURL(args[0])
46-
if previewCmdOpts.External {
47-
if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {
48-
url = "https://" + url
49-
}
50-
openPreview("GP_EXTERNAL_BROWSER", url)
51-
return
52-
}
53-
openPreview("GP_PREVIEW_BROWSER", url)
35+
openPreview(cmd.Context(), args[0], previewCmdOpts.External)
5436
},
5537
}
5638

57-
func openPreview(gpBrowserEnvVar string, url string) {
39+
func openPreview(ctx context.Context, url string, external bool) {
40+
client, err := supervisor.New(ctx)
41+
if err != nil {
42+
log.Fatal(err)
43+
}
44+
defer client.Close()
45+
client.WaitForIDEReady(ctx)
46+
47+
url = replaceLocalhostInURL(url)
48+
gpBrowserEnvVar := "GP_PREVIEW_BROWSER"
49+
if external {
50+
gpBrowserEnvVar = "GP_EXTERNAL_BROWSER"
51+
if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {
52+
url = "https://" + url
53+
}
54+
}
5855
pcmd := os.Getenv(gpBrowserEnvVar)
56+
if pcmd == "" {
57+
_, err := client.Notification.NotifyActive(ctx, &api.NotifyActiveRequest{
58+
ActionData: &api.NotifyActiveRequest_Preview{
59+
Preview: &api.NotifyActiveRequest_PreviewData{
60+
Url: url,
61+
External: external,
62+
},
63+
},
64+
})
65+
if err != nil && ctx.Err() == nil {
66+
log.Fatal(err)
67+
}
68+
return
69+
}
70+
// TODO: backward compatibilty, remove when all IDEs are updated
5971
if pcmd == "" {
6072
log.Fatalf("%s is not set", gpBrowserEnvVar)
6173
return

components/gitpod-cli/hot-swap.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
# Licensed under the GNU Affero General Public License (AGPL).
4+
# See License.AGPL.txt in the project root for license information.
5+
6+
set -Eeuo pipefail
7+
8+
component=${PWD##*/}
9+
workspaceUrl=$(echo "${1}" |sed -e "s/\/$//")
10+
echo "URL: $workspaceUrl"
11+
12+
workspaceDesc=$(gpctl workspaces describe "$workspaceUrl" -o=json)
13+
14+
podName=$(echo "$workspaceDesc" | jq .runtime.pod_name -r)
15+
echo "Pod: $podName"
16+
17+
workspaceId=$(echo "$workspaceDesc" | jq .metadata.meta_id -r)
18+
echo "ID: $workspaceId"
19+
20+
clusterHost=$(kubectl exec -it "$podName" -- printenv GITPOD_WORKSPACE_CLUSTER_HOST |sed -e "s/\s//g")
21+
echo "Cluster Host: $clusterHost"
22+
23+
# prepare ssh
24+
ownerToken=$(kubectl get pod "$podName" -o=json | jq ".metadata.annotations.\"gitpod\/ownerToken\"" -r)
25+
sshConfig=$(mktemp)
26+
echo "Host $workspaceId" > "$sshConfig"
27+
echo " Hostname \"$workspaceId.ssh.$clusterHost\"" >> "$sshConfig"
28+
echo " User \"$workspaceId#$ownerToken\"" >> "$sshConfig"
29+
30+
# build
31+
go build .
32+
echo "$component built"
33+
34+
# upload
35+
uploadDest="/.supervisor/$component"
36+
echo "Upload Dest: $uploadDest"
37+
ssh -F "$sshConfig" "$workspaceId" "sudo chown -R gitpod:gitpod /.supervisor && rm $uploadDest 2> /dev/null"
38+
echo "Permissions granted"
39+
scp -F "$sshConfig" -r "./$component" "$workspaceId":"$uploadDest"
40+
echo "Swap complete"

components/gitpod-cli/pkg/supervisor/client.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ type SupervisorClient struct {
2121
conn *grpc.ClientConn
2222
closeOnce sync.Once
2323

24-
Status api.StatusServiceClient
25-
Terminal api.TerminalServiceClient
26-
Info api.InfoServiceClient
24+
Status api.StatusServiceClient
25+
Terminal api.TerminalServiceClient
26+
Info api.InfoServiceClient
27+
Notification api.NotificationServiceClient
2728
}
2829

2930
type SupervisorClientOption struct {
@@ -43,10 +44,11 @@ func New(ctx context.Context, options ...*SupervisorClientOption) (*SupervisorCl
4344
}
4445

4546
return &SupervisorClient{
46-
conn: conn,
47-
Status: api.NewStatusServiceClient(conn),
48-
Terminal: api.NewTerminalServiceClient(conn),
49-
Info: api.NewInfoServiceClient(conn),
47+
conn: conn,
48+
Status: api.NewStatusServiceClient(conn),
49+
Terminal: api.NewTerminalServiceClient(conn),
50+
Info: api.NewInfoServiceClient(conn),
51+
Notification: api.NewNotificationServiceClient(conn),
5052
}, nil
5153
}
5254

components/ide/code/leeway.Dockerfile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,9 @@ COPY --from=code_builder --chown=33333:33333 /vscode-web/ /ide/
9999
COPY --from=code_builder --chown=33333:33333 /vscode-reh-linux-x64/ /ide/
100100
COPY --chown=33333:33333 supervisor-ide-config.json components-ide-code-codehelper--app/codehelper /ide/
101101

102+
# TODO(ak) get rid of it as well
102103
ENV GITPOD_ENV_APPEND_PATH=/ide/bin/remote-cli:
103104

104-
# editor config
105-
ENV GITPOD_ENV_SET_EDITOR=/ide/bin/remote-cli/gitpod-code
106-
ENV GITPOD_ENV_SET_VISUAL="$GITPOD_ENV_SET_EDITOR"
107-
ENV GITPOD_ENV_SET_GP_OPEN_EDITOR="$GITPOD_ENV_SET_EDITOR"
108-
ENV GITPOD_ENV_SET_GIT_EDITOR="$GITPOD_ENV_SET_EDITOR --wait"
109-
ENV GITPOD_ENV_SET_GP_PREVIEW_BROWSER="/ide/bin/remote-cli/gitpod-code --preview"
110-
ENV GITPOD_ENV_SET_GP_EXTERNAL_BROWSER="/ide/bin/remote-cli/gitpod-code --openExternal"
111-
112105
ARG CODE_VERSION
113106
ARG CODE_COMMIT
114107
LABEL "io.gitpod.ide.version"=$CODE_VERSION

0 commit comments

Comments
 (0)