Skip to content

Local Companion (alpha) #3958

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 11 commits into from
Apr 22, 2021
1 change: 1 addition & 0 deletions .werft/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ components:
replicas: 1
makeNewUsersAdmin: true # for development
theiaPluginsBucketName: gitpod-core-dev-plugins
enableLocalApp: true

registryFacade:
daemonSet: true
Expand Down
4 changes: 4 additions & 0 deletions chart/templates/server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ spec:
- name: MAKE_NEW_USERS_ADMIN
value: {{ $comp.makeNewUsersAdmin | quote }}
{{- end }}
{{- if $comp.enableLocalApp }}
- name: ENABLE_LOCAL_APP
value: "true"
{{- end }}
{{- if $comp.portAccessForUsersOnly }}
- name: PORT_ACCESS_FOR_USERS_ONLY
value: "true"
Expand Down
3 changes: 2 additions & 1 deletion components/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ packages:
- components/ide/code:docker
- components/ide/theia:docker
- components/image-builder:docker
- components/local-app:docker
- components/proxy:docker
- components/registry-facade:docker
- components/server:docker
- components/service-waiter:docker
- components/supervisor-api/typescript-grpc:publish
- components/supervisor:docker
- components/ws-daemon:docker
- components/ws-daemon/seccomp-profile-installer:docker
- components/ws-daemon/shiftfs-module-loader:docker
- components/ws-daemon:docker
- components/ws-manager-bridge:docker
- components/ws-manager:docker
- components/ws-proxy:docker
Expand Down
6 changes: 6 additions & 0 deletions components/gitpod-protocol/go/gitpod-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ func (gp *APIoverJSONRPC) handler(ctx context.Context, conn *jsonrpc2.Conn, req
default:
}
}
for chn := range gp.subs[""] {
select {
case chn <- &instance:
default:
}
}

return
}
Expand Down
61 changes: 61 additions & 0 deletions components/local-app/BUILD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
packages:
- name: app
type: generic
config:
commands: [["echo"]]
deps:
- :app-linux
- :app-darwin
- :app-windows
- name: app-linux
type: go
srcs:
- go.mod
- go.sum
- "**/*.go"
deps:
- components/supervisor-api/go:lib
- components/gitpod-protocol/go:lib
env:
- CGO_ENABLED=0
- GOOS=linux
config:
packaging: app
- name: app-darwin
type: go
srcs:
- go.mod
- go.sum
- "**/*.go"
deps:
- components/supervisor-api/go:lib
- components/gitpod-protocol/go:lib
env:
- CGO_ENABLED=0
- GOOS=darwin
config:
packaging: app
- name: app-windows
type: go
srcs:
- go.mod
- go.sum
- "**/*.go"
deps:
- components/supervisor-api/go:lib
- components/gitpod-protocol/go:lib
env:
- CGO_ENABLED=0
- GOOS=windows
config:
packaging: app
- name: docker
type: docker
deps:
- :app
argdeps:
- imageRepoBase
config:
dockerfile: leeway.Dockerfile
image:
- ${imageRepoBase}/local-app:${version}
19 changes: 19 additions & 0 deletions components/local-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# local-app

**Beware**: this is very much work in progress and will likely break things.

## How to install
```
docker run --rm -it -v /tmp/dest:/out eu.gcr.io/gitpod-core-dev/build/local-app:<version>
```

## How to run
```
./local-app
```

## How to run in Gitpod against a dev-staging environment
```
cd components/local-app
BROWSER= GITPOD_HOST=<URL-of-your-preview-env> go run main.go --mock-keyring run
```
20 changes: 20 additions & 0 deletions components/local-app/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/gitpod-io/local-app

go 1.16

require (
github.com/gitpod-io/gitpod/gitpod-protocol v0.0.0-00010101000000-000000000000
github.com/gitpod-io/gitpod/supervisor/api v0.0.0-00010101000000-000000000000
github.com/jpillora/chisel v1.7.6
github.com/kevinburke/ssh_config v1.1.0 // indirect
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
github.com/sirupsen/logrus v1.7.0
github.com/urfave/cli/v2 v2.3.0
github.com/zalando/go-keyring v0.1.1
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 // indirect
google.golang.org/grpc v1.36.0
)

replace github.com/gitpod-io/gitpod/gitpod-protocol => ../gitpod-protocol/go // leeway

replace github.com/gitpod-io/gitpod/supervisor/api => ../supervisor-api/go // leeway
437 changes: 437 additions & 0 deletions components/local-app/go.sum

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions components/local-app/leeway.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2021 Gitpod GmbH. All rights reserved.
# Licensed under the GNU Affero General Public License (AGPL).
# See License-AGPL.txt in the project root for license information.

FROM alpine:3.13

WORKDIR /app
COPY components-local-app--app/components-local-app--app-linux/local-app local-app-linux
COPY components-local-app--app/components-local-app--app-darwin/local-app local-app-darwin
COPY components-local-app--app/components-local-app--app-windows/local-app.exe local-app-windows.exe

CMD ["/bin/sh", "-c", "cp /app/* /out"]
107 changes: 107 additions & 0 deletions components/local-app/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package main

import (
"context"
"errors"
"log"
"os"
"strings"

gitpod "github.com/gitpod-io/gitpod/gitpod-protocol"
"github.com/gitpod-io/local-app/pkg/auth"
"github.com/gitpod-io/local-app/pkg/bastion"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"github.com/zalando/go-keyring"
)

func main() {
app := cli.App{
Name: "gitpod",
Action: DefaultCommand("run"),
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "gitpod-host",
Usage: "URL of the Gitpod installation to connect to",
EnvVars: []string{
"GITPOD_HOST",
},
},
&cli.BoolFlag{
Name: "mock-keyring",
Usage: "Don't use system native keyring, but store Gitpod token in memory",
},
},
Commands: []*cli.Command{
{
Name: "run",
Action: func(c *cli.Context) error {
if c.Bool("mock-keyring") {
keyring.MockInit()
}
return run(c.String("gitpod-host"), c.String("ssh_config"))
},
Flags: []cli.Flag{
&cli.PathFlag{
Name: "ssh_config",
Usage: "produce and update an OpenSSH compatible ssh_config file",
Value: "/tmp/gitpod_ssh_config",
},
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}

func DefaultCommand(name string) cli.ActionFunc {
return func(ctx *cli.Context) error {
return ctx.App.Command(name).Run(ctx)
}
}

func run(host, sshConfig string) error {
tkn, err := auth.GetToken(host)
if errors.Is(err, keyring.ErrNotFound) {
tkn, err = auth.Login(context.Background(), auth.LoginOpts{GitpodURL: host})
}
if err != nil {
return err
}

cb := bastion.CompositeCallbacks{
&logCallbacks{},
}
if sshConfig != "" {
cb = append(cb, &bastion.SSHConfigWritingCallback{Path: sshConfig})
}

wshost := host
wshost = strings.ReplaceAll(wshost, "https://", "wss://")
wshost = strings.ReplaceAll(wshost, "http://", "ws://")
wshost += "/api/v1"
client, err := gitpod.ConnectToServer(wshost, gitpod.ConnectToServerOpts{
Context: context.Background(),
Token: tkn,
Log: logrus.NewEntry(logrus.New()),
})
if err != nil {
return err
}
b := bastion.New(client, cb)
return b.Run()
}

type logCallbacks struct{}

func (*logCallbacks) InstanceUpdate(w *bastion.Workspace) {
logrus.WithField("workspace", w).Info("instance update")
}
Loading