-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Local Companion (alpha) #3958
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4381e05
[server] Support local app login
csweichel 278b021
[local-app] Start local app
csweichel fa4fca2
[gitpod-protocol] Support listening to all instance updates
csweichel ec9658e
[supervisor] Add chisel server
csweichel 7ecfb5a
[ws-proxy] Support `x-gitpod-owner-token` for authentication
csweichel 2060b98
[workspacekit] Relax IWS socket wait time
csweichel e396249
[ws-manager] Reduce owner token char set
csweichel 592c841
[workspacekit] Ignore chown /dev/pts
csweichel 02b8964
[supervisor] Add SSH support
csweichel e07cf00
[local-app] auto-establish SSH connection
csweichel a064c77
[local-app] Make part of the regular build
csweichel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.