Skip to content

Commit e51d974

Browse files
filiptronicekiQQBotcsweichel
authored
Local App v2 :) (#18971)
* Local App v2 :) * bind variables correctly * Play around with units * Port more commands over * Separate commands (1 per file) * `gitpod workspace delete` * Extract login * Show help text when run without a command * Fix login * `gitpod logout` * Simple logging * Remove unused import * Make host use consistent * Fix GetToken * Split distribution * 🤷‍♂️ * Fix paths 🤷🤦 * Change URL of binaries * Fix proxy binary handling Co-authored-by: Pudong <[email protected]> * Improve logging * Change workspace list to be up-to-spec * `gitpod organizations list` * Simplify table code * `gitpod workspace get` * Created at * `gitpod organization get <id>` * Hide open for now * `workspace start --ssh` * `ws start --open` * server: OAuth client * Use OAuth app * logs * `gitpod workspace create` * Rename to follow singular noun semantics * Fix nil pointers in list and go cmds * `--field` for `gitpod organizations list` * `gitpod ws list --field` * Simplify some of the ws code * Unify WS data structure * Allow opening browser-based WSs * `gitpod workspace open` * Constants package to get rid of circular dependency issues * No config file by default * Guidance when missing in path * Fix local companion maybe 🤷‍♂️ * Create wait for start by default * Align scopes * KeychainName constant * Provide token via flag instead * Host in scope error lookup message * 🤷‍♂️ * Name for consistency * Editors in go client of papi * `gitpod workspace list-classes` * `gitpod config` * Infer orgs if applicable * Remove redundant error log * Retry mechanism for streaming * More useful error message for unauthed * README update * Allow `function:getTeam` * return org inference errors properly * Replace config with context * Fix config file path * Wrap up pretty printer * Name changes * Remove unused vars * 🇺🇸 * Update README * Fix login * [local-app] Add whoami command * [local-app] Add context management * Refactor common package * Harmonise output and formatting * Add error resolution support * Improve resolution printing * Add apology for system exceptions * Add class resolutions * Apologise more * Add unknown field resolution * Add better login context name * Make it build * `gitpod workspace list-editors` * Fix multiple ws IDs for `ws get` * Simplify open code * Update local-app README with usage instructions * Help for editor options * Remove unused config code * Call workspace ID field ID instead of workspace * Improve long format output * Fix whoami output * Streamline workspace listing * Introduce fancy intro * Improve set-context feedback * Remove common package * Add first unit test * Harmonise field order * Consistency across get commands * Consistency among list command aliases * Fix column name in whoami * Fix nil refs for empty hosts * Make prettyprint writer typesafe * Add resolutions for no token or no host found * Fix typo * Fix CI build * Properly record org ID on login * Print orgs in wide format * Added "workspace up" functionality back in but hidden * Make "Git" casing consistent https://english.stackexchange.com/questions/611711/tech-related-should-i-capitalize-the-word-git-in-this-context-or-not * Introduce workspace up intermediary * Fix proxied binary name --------- Co-authored-by: Pudong <[email protected]> Co-authored-by: Christian Weichel (Chris) <[email protected]>
1 parent 0d19e87 commit e51d974

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3354
-266
lines changed

components/ide-proxy/Dockerfile

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@ FROM cgr.dev/chainguard/wolfi-base:latest@sha256:a8c9c2888304e62c133af76f520c9c9
66

77
RUN apk add brotli gzip
88

9-
COPY components-local-app--app/components-local-app--app-linux-amd64/local-app /bin/gitpod-local-companion-linux-amd64
10-
COPY components-local-app--app/components-local-app--app-darwin-amd64/local-app /bin/gitpod-local-companion-darwin-amd64
11-
COPY components-local-app--app/components-local-app--app-windows-amd64/local-app.exe /bin/gitpod-local-companion-windows-amd64.exe
12-
COPY components-local-app--app/components-local-app--app-linux-arm64/local-app /bin/gitpod-local-companion-linux-arm64
13-
COPY components-local-app--app/components-local-app--app-darwin-arm64/local-app /bin/gitpod-local-companion-darwin-arm64
14-
COPY components-local-app--app/components-local-app--app-windows-386/local-app.exe /bin/gitpod-local-companion-windows-arm64.exe
15-
COPY components-local-app--app/components-local-app--app-windows-386/local-app.exe /bin/gitpod-local-companion-windows-386.exe
9+
# Gitpod CLI and Local App
10+
COPY components-local-app--app/bin/* /bin/
1611

1712
RUN for FILE in `ls /bin/gitpod-local-companion*`;do \
1813
gzip -v -f -9 -k "$FILE"; \

components/local-app/BUILD.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const generatePackage = function (goos, goarch, binaryName, mainFile) {
2+
let name = binaryName + "-" + goos + "-" + goarch;
3+
let dontTest = !(goos === "linux" && goarch === "amd64");
4+
if (goos === "windows") {
5+
binaryName += ".exe";
6+
}
7+
let pkg = {
8+
name,
9+
type: "go",
10+
srcs: ["go.mod", "go.sum", "**/*.go"],
11+
deps: [
12+
"components/supervisor-api/go:lib",
13+
"components/gitpod-protocol/go:lib",
14+
"components/local-app-api/go:lib",
15+
"components/public-api/go:lib",
16+
],
17+
env: ["GOOS=" + goos, "GOARCH=" + goarch, "CGO_ENABLED=0"],
18+
config: {
19+
packaging: "app",
20+
dontTest: dontTest,
21+
buildCommand: [
22+
"go",
23+
"build",
24+
"-trimpath",
25+
"-ldflags",
26+
"-buildid= -w -s -X 'github.com/gitpod-io/local-app/pkg/common.Version=commit-${__git_commit}'",
27+
"-o",
28+
binaryName,
29+
mainFile,
30+
],
31+
},
32+
binaryName,
33+
};
34+
return pkg;
35+
};
36+
37+
const packages = [];
38+
for (binaryName of ["gitpod-local-companion", "gitpod-cli"]) {
39+
for (goos of ["linux", "darwin", "windows"]) {
40+
for (goarch of ["amd64", "arm64"]) {
41+
packages.push(generatePackage(goos, goarch, binaryName, "main/" + binaryName + "/main.go"));
42+
}
43+
}
44+
}
45+
46+
let appCmds = packages.map((p) => {
47+
let binName = p.name;
48+
if (p.name.includes("windows")) {
49+
binName += ".exe";
50+
}
51+
return ["cp", "components-local-app--" + p.name + "/" + p.binaryName, "bin/" + binName];
52+
});
53+
appCmds.unshift(["mkdir", "bin"]);
54+
appCmds.push(["sh", "-c", "rm -rf components-*"]);
55+
56+
packages.push({
57+
name: "app",
58+
type: "generic",
59+
deps: packages.map((d) => ":" + d.name),
60+
config: {
61+
commands: appCmds,
62+
},
63+
});

components/local-app/BUILD.yaml

Lines changed: 1 addition & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,135 +1,5 @@
11
packages:
2-
- name: app
3-
type: generic
4-
config:
5-
commands: [["echo"]]
6-
deps:
7-
- :app-linux-amd64
8-
- :app-linux-arm64
9-
- :app-darwin-amd64
10-
- :app-darwin-arm64
11-
- :app-windows-386
12-
- :app-windows-amd64
13-
- :app-windows-arm64
14-
- name: app-linux-amd64
15-
type: go
16-
srcs:
17-
- go.mod
18-
- go.sum
19-
- "**/*.go"
20-
deps:
21-
- components/supervisor-api/go:lib
22-
- components/gitpod-protocol/go:lib
23-
- components/local-app-api/go:lib
24-
env:
25-
- CGO_ENABLED=0
26-
- GOOS=linux
27-
- GOARCH=amd64
28-
config:
29-
packaging: app
30-
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'github.com/gitpod-io/local-app.Version=commit-${__git_commit}'"]
31-
- name: app-linux-arm64
32-
type: go
33-
srcs:
34-
- go.mod
35-
- go.sum
36-
- "**/*.go"
37-
deps:
38-
- components/supervisor-api/go:lib
39-
- components/gitpod-protocol/go:lib
40-
- components/local-app-api/go:lib
41-
env:
42-
- CGO_ENABLED=0
43-
- GOOS=linux
44-
- GOARCH=arm64
45-
config:
46-
packaging: app
47-
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'github.com/gitpod-io/local-app.Version=commit-${__git_commit}'"]
48-
- name: app-darwin-amd64
49-
type: go
50-
srcs:
51-
- go.mod
52-
- go.sum
53-
- "**/*.go"
54-
deps:
55-
- components/supervisor-api/go:lib
56-
- components/gitpod-protocol/go:lib
57-
- components/local-app-api/go:lib
58-
env:
59-
- CGO_ENABLED=0
60-
- GOOS=darwin
61-
- GOARCH=amd64
62-
config:
63-
packaging: app
64-
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'github.com/gitpod-io/local-app.Version=commit-${__git_commit}'"]
65-
- name: app-darwin-arm64
66-
type: go
67-
srcs:
68-
- go.mod
69-
- go.sum
70-
- "**/*.go"
71-
deps:
72-
- components/supervisor-api/go:lib
73-
- components/gitpod-protocol/go:lib
74-
- components/local-app-api/go:lib
75-
env:
76-
- CGO_ENABLED=0
77-
- GOOS=darwin
78-
- GOARCH=arm64
79-
config:
80-
packaging: app
81-
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'github.com/gitpod-io/local-app.Version=commit-${__git_commit}'"]
82-
- name: app-windows-amd64
83-
type: go
84-
srcs:
85-
- go.mod
86-
- go.sum
87-
- "**/*.go"
88-
deps:
89-
- components/supervisor-api/go:lib
90-
- components/gitpod-protocol/go:lib
91-
- components/local-app-api/go:lib
92-
env:
93-
- CGO_ENABLED=0
94-
- GOOS=windows
95-
- GOARCH=amd64
96-
config:
97-
packaging: app
98-
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'github.com/gitpod-io/local-app.Version=commit-${__git_commit}'"]
99-
- name: app-windows-386
100-
type: go
101-
srcs:
102-
- go.mod
103-
- go.sum
104-
- "**/*.go"
105-
deps:
106-
- components/supervisor-api/go:lib
107-
- components/gitpod-protocol/go:lib
108-
- components/local-app-api/go:lib
109-
env:
110-
- CGO_ENABLED=0
111-
- GOOS=windows
112-
- GOARCH=386
113-
config:
114-
packaging: app
115-
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'github.com/gitpod-io/local-app.Version=commit-${__git_commit}'"]
116-
- name: app-windows-arm64
117-
type: go
118-
srcs:
119-
- go.mod
120-
- go.sum
121-
- "**/*.go"
122-
deps:
123-
- components/supervisor-api/go:lib
124-
- components/gitpod-protocol/go:lib
125-
- components/local-app-api/go:lib
126-
env:
127-
- CGO_ENABLED=0
128-
- GOOS=windows
129-
- GOARCH=arm64
130-
config:
131-
packaging: app
132-
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'github.com/gitpod-io/local-app.Version=commit-${__git_commit}'"]
2+
# remaining packages are added by the BUILD.js generator
1333
- name: docker
1344
type: docker
1355
deps:

components/local-app/README.md

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,50 @@
1-
# local-app
1+
# local-app
2+
3+
## gitpod-cli
4+
5+
All of the accessible commands can be listed with `gitpod --help` .
6+
7+
### Installing
8+
9+
1. Download the CLI for your platform and make it executable:
10+
11+
```bash
12+
wget -O gitpod https://gitpod.io/static/bin/gitpod-cli-darwin-arm64
13+
chmod u+x gitpod
14+
```
15+
16+
2. Optionally, make it available globally. On macOS:
17+
18+
```bash
19+
sudo mv gitpod /usr/local/bin/
20+
```
21+
22+
### Usage
23+
24+
Start by logging in with `gitpod login`, which will also create a default context in the configuration file (`~/.gitpod/config.yaml`).
25+
26+
### Development
27+
28+
To develop the CLI with Gitpod, you can run it just like locally, but in Gitpod workspaces, a browser and a keyring are not available. To log in despite these limitations, provide a PAT via the `GITPOD_TOKEN` environment variable, or use the `--token` flag with the login command.
29+
30+
## local-app
231

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

5-
## How to install
34+
### How to install
35+
636
```
737
docker run --rm -it -v /tmp/dest:/out eu.gcr.io/gitpod-core-dev/build/local-app:<version>
838
```
939

10-
## How to run
40+
### How to run
41+
1142
```
1243
./local-app
1344
```
1445

15-
## How to run in Gitpod against a dev-staging environment
46+
### How to run in Gitpod against a dev-staging environment
47+
1648
```
1749
cd components/local-app
1850
BROWSER= GITPOD_HOST=<URL-of-your-preview-env> go run main.go --mock-keyring run
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package cmd
6+
7+
import (
8+
"log/slog"
9+
10+
"github.com/gitpod-io/local-app/pkg/auth"
11+
"github.com/gitpod-io/local-app/pkg/config"
12+
"github.com/spf13/cobra"
13+
)
14+
15+
var configDeleteCmd = &cobra.Command{
16+
Use: "delete-context <name>",
17+
Short: "Deletes a context",
18+
Args: cobra.ExactArgs(1),
19+
RunE: func(cmd *cobra.Command, args []string) (err error) {
20+
cmd.SilenceUsage = true
21+
22+
targetContext := args[0]
23+
cfg := config.FromContext(cmd.Context())
24+
25+
var update bool
26+
defer func() {
27+
if err == nil && update {
28+
slog.Debug("saving config", "filename", cfg.Filename)
29+
err = config.SaveConfig(cfg.Filename, cfg)
30+
}
31+
}()
32+
33+
if cfg.ActiveContext == targetContext {
34+
slog.Info("deleting active context - use `gitpod config use-context` to set a new active context")
35+
cfg.ActiveContext = ""
36+
update = true
37+
}
38+
39+
gpctx := cfg.Contexts[targetContext]
40+
if gpctx == nil {
41+
return nil
42+
}
43+
delete(cfg.Contexts, targetContext)
44+
update = true
45+
46+
err = auth.DeleteToken(gpctx.Host.String())
47+
if err != nil {
48+
slog.Warn("did not delete token from keyring", "err", err)
49+
err = nil
50+
}
51+
52+
return nil
53+
},
54+
}
55+
56+
func init() {
57+
configCmd.AddCommand(configDeleteCmd)
58+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package cmd
6+
7+
import (
8+
"github.com/gitpod-io/local-app/pkg/config"
9+
"github.com/gitpod-io/local-app/pkg/prettyprint"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var configGetContextsCmd = &cobra.Command{
14+
Use: "get-contexts",
15+
Short: "Lists the available contexts",
16+
RunE: func(cmd *cobra.Command, args []string) error {
17+
cmd.SilenceUsage = true
18+
19+
cfg := config.FromContext(cmd.Context())
20+
21+
res := make([]tabularContext, 0, len(cfg.Contexts))
22+
for name, ctx := range cfg.Contexts {
23+
res = append(res, tabularContext{
24+
Active: name == cfg.ActiveContext,
25+
Name: name,
26+
Host: ctx.Host.String(),
27+
Organization: ctx.OrganizationID,
28+
})
29+
}
30+
31+
return WriteTabular(res, configGetContextsOpts.Format, prettyprint.WriterFormatWide)
32+
},
33+
}
34+
35+
type tabularContext struct {
36+
Active bool
37+
Name string
38+
Host string
39+
Organization string
40+
}
41+
42+
var configGetContextsOpts struct {
43+
Format formatOpts
44+
}
45+
46+
func init() {
47+
configCmd.AddCommand(configGetContextsCmd)
48+
addFormatFlags(configGetContextsCmd, &configGetContextsOpts.Format)
49+
}

0 commit comments

Comments
 (0)