Skip to content

Commit

Permalink
Merge branch 'main' into ft/config-overview
Browse files Browse the repository at this point in the history
  • Loading branch information
filiptronicek authored Nov 7, 2023
2 parents cd927ad + 1b90b8a commit 99dc62d
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/epic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ body:
id: press-release
attributes:
label: Press release (and FAQ's)
description: What would the future feature announcement look like from a customer/user point of view? Think about questions both Gitpodders, and users/customers might ask about this feature.
description: What would the future feature announcement look like from a customer/user point of view? Think about questions both Gitpodders, and users/customers might ask about this feature.
validations:
required: false
- type: textarea
Expand Down Expand Up @@ -35,14 +35,14 @@ body:
id: measurement
attributes:
label: Measurement
description: What will we measure to know whether we've been successful?
description: What will we measure to know whether we've been successful?
validations:
required: false
- type: textarea
id: personas
attributes:
label: Persona(s)
description: Optionally specifiy which user will be impacted by this change?
description: Optionally specifiy which user will be impacted by this change?
placeholder: Developer/Installer/Project Configurer/Customer/Security Reviewer - optionally the ecosystem persona e.g. Python Developers
validations:
required: false
Expand All @@ -64,6 +64,6 @@ body:
id: complexities
attributes:
label: Complexities
description: Optionally make explicit any complexities, e.g. dependencies on other teams, technical challenges, unknowns.
description: Optionally make explicit any complexities, e.g. dependencies on other teams, technical challenges, unknowns.
validations:
required: false
5 changes: 5 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ tasks:
gp env -u GCP_ADC_FILE
fi
exit 0
- name: Install `gitpod` CLI
command: |
leeway run components/local-app:install-cli
leeway run components/local-app:cli-completion
exit 0
# This task takes care of configuring your workspace so it can manage and interact
# with preview environments.
- name: Preview environment configuration
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ defaultArgs:
publishToNPM: true
publishToJBMarketplace: true
localAppVersion: unknown
codeCommit: 50b5698060d06fa4650f10651a8714fe1d3cffe2
codeVersion: 1.84.0
codeCommit: e8edec1d836142a8a82e9c372b8d146d2c53b2fa
codeVersion: 1.84.1
codeQuality: stable
noVerifyJBPlugin: false
intellijDownloadUrl: "https://download.jetbrains.com/idea/ideaIU-2023.2.3.tar.gz"
Expand Down
12 changes: 12 additions & 0 deletions components/local-app/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ packages:
image:
- ${imageRepoBase}/local-app:${version}
- ${imageRepoBase}/local-app:commit-${__git_commit}

scripts:
- name: install-cli
description: "Install gitpod-cli as `gitpod` command and add auto-completion. Usage: '. $(leeway run components/local-app:install-cli)'"
script: |
go build -o gitpod ./main/gitpod-cli
sudo mv gitpod /usr/bin/gitpod
sudo chmod +x /usr/bin/gitpod
- name: cli-completion
description: "Add completion of gitpod-cli to bash-completion. Usage: '. $(leeway run components/local-app:cli-completion)'"
script: |
sudo /usr/bin/gitpod completion bash | sudo tee /usr/share/bash-completion/completions/gitpod > /dev/null
16 changes: 15 additions & 1 deletion components/local-app/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# local-app
# local-app

## gitpod-cli

Expand Down Expand Up @@ -27,6 +27,20 @@ Start by logging in with `gitpod login`, which will also create a default contex

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.

#### in Gitpod workspace

[![Open in Gitpod](https://www.gitpod.io/svg/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/gitpod-io/gitpod)

You will have gitpod-cli ready as `gitpod` in your CDE (Cloud Development Environments) workspace, will commands below you can install again easily.

```
# Install as `gitpod` again
leeway run components/local-app:install-cli
# Add completion again
leeway run components/local-app:cli-completion
```

## local-app

**Beware**: this is very much work in progress and will likely break things.
Expand Down
19 changes: 17 additions & 2 deletions components/local-app/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ var loginCmd = &cobra.Command{

err = auth.SetToken(loginOpts.Host, token)
if err != nil {
slog.Warn("could not write token to keyring, storing in config file instead", "err", err)
if slog.Default().Enabled(cmd.Context(), slog.LevelDebug) {
slog.Debug("could not write token to keyring, storing in config file instead", "err", err)
} else {
slog.Warn("could not write token to keyring, storing in config file instead. Use -v to see the error.")
}
gpctx.Token = token
}

Expand Down Expand Up @@ -115,7 +119,18 @@ var loginCmd = &cobra.Command{
return err
}

return nil
client, err := getGitpodClient(config.ToContext(cmd.Context(), cfg))
if err != nil {
return err
}
who, err := whoami(cmd.Context(), client, gpctx)
if err != nil {
return err
}

slog.Info("Login succesfull")
fmt.Println()
return WriteTabular(who, formatOpts{}, prettyprint.WriterFormatNarrow)
},
}

Expand Down
25 changes: 25 additions & 0 deletions components/local-app/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,29 @@ var rootCmd = &cobra.Command{
var noColor bool
if !isatty.IsTerminal(os.Stdout.Fd()) {
noColor = true
color.Disable()
}
slog.SetDefault(slog.New(tint.NewHandler(os.Stdout, &tint.Options{
Level: level,
NoColor: noColor,
TimeFormat: time.StampMilli,
ReplaceAttr: func(groups []string, attr slog.Attr) slog.Attr {
if attr.Key != "level" {
return attr
}

switch attr.Value.String() {
case slog.LevelDebug.String():
attr.Value = slog.StringValue(color.Gray.Render("[DEBUG]"))
case slog.LevelInfo.String():
attr.Value = slog.StringValue(color.Green.Render("[INFO ]"))
case slog.LevelWarn.String():
attr.Value = slog.StringValue(color.Yellow.Render("[WARN ]"))
case slog.LevelError.String():
attr.Value = slog.StringValue(color.Red.Render("[ERROR]"))
}
return attr
},
})))

cfg, err := config.LoadConfig(rootOpts.ConfigLocation)
Expand Down Expand Up @@ -101,7 +119,13 @@ var rootTestingOpts struct {
WriterOut io.Writer
}

var clientCache *client.Gitpod

func getGitpodClient(ctx context.Context) (*client.Gitpod, error) {
// There will be only one client in a command context right now
if clientCache != nil {
return clientCache, nil
}
cfg := config.FromContext(ctx)
gpctx, err := cfg.GetActiveContext()
if err != nil {
Expand Down Expand Up @@ -154,6 +178,7 @@ func getGitpodClient(ctx context.Context) (*client.Gitpod, error) {
if err != nil {
return nil, err
}
clientCache = res

return res, nil
}
Expand Down
41 changes: 27 additions & 14 deletions components/local-app/cmd/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
package cmd

import (
"context"

"github.com/bufbuild/connect-go"
"github.com/gitpod-io/gitpod/components/public-api/go/client"
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
"github.com/gitpod-io/local-app/pkg/config"
"github.com/gitpod-io/local-app/pkg/prettyprint"
Expand All @@ -28,27 +31,37 @@ var whoamiCmd = &cobra.Command{
return err
}

user, err := client.User.GetAuthenticatedUser(cmd.Context(), &connect.Request[v1.GetAuthenticatedUserRequest]{})
if err != nil {
return err
}
org, err := client.Teams.GetTeam(cmd.Context(), &connect.Request[v1.GetTeamRequest]{Msg: &v1.GetTeamRequest{TeamId: gpctx.OrganizationID}})
who, err := whoami(cmd.Context(), client, gpctx)
if err != nil {
return err
}

return WriteTabular([]whoamiResult{
{
Name: user.Msg.GetUser().Name,
ID: user.Msg.GetUser().Id,
Org: org.Msg.GetTeam().Name,
OrgID: org.Msg.GetTeam().Id,
Host: gpctx.Host.String(),
},
}, whoamiOpts.Format, prettyprint.WriterFormatNarrow)
return WriteTabular(who, whoamiOpts.Format, prettyprint.WriterFormatNarrow)
},
}

// whoami returns information about the currently logged in user
func whoami(ctx context.Context, client *client.Gitpod, gpctx *config.ConnectionContext) ([]whoamiResult, error) {
user, err := client.User.GetAuthenticatedUser(ctx, &connect.Request[v1.GetAuthenticatedUserRequest]{})
if err != nil {
return nil, err
}
org, err := client.Teams.GetTeam(ctx, &connect.Request[v1.GetTeamRequest]{Msg: &v1.GetTeamRequest{TeamId: gpctx.OrganizationID}})
if err != nil {
return nil, err
}

return []whoamiResult{
{
Name: user.Msg.GetUser().Name,
ID: user.Msg.GetUser().Id,
Org: org.Msg.GetTeam().Name,
OrgID: org.Msg.GetTeam().Id,
Host: gpctx.Host.String(),
},
}, nil
}

type whoamiResult struct {
Name string `print:"user name"`
ID string `print:"user id"`
Expand Down
43 changes: 43 additions & 0 deletions components/local-app/cmd/workspace-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,53 @@ var workspaceCreateOpts struct {
Editor string
}

func classCompletionFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ctx := cmd.Context()
gitpod, err := getGitpodClient(ctx)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
resp, err := gitpod.Workspaces.ListWorkspaceClasses(ctx, connect.NewRequest(&v1.ListWorkspaceClassesRequest{}))
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
items := resp.Msg.GetResult()
completionStr := []string{}
for _, cls := range items {
defaultDesc := ""
if cls.IsDefault {
defaultDesc = "(default)"
}
completionStr = append(completionStr, fmt.Sprintf("%s\t%s%s - %s", cls.Id, cls.DisplayName, defaultDesc, cls.Description))
}
return completionStr, cobra.ShellCompDirectiveNoFileComp
}

func editorCompletionFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
ctx := cmd.Context()
gitpod, err := getGitpodClient(ctx)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
resp, err := gitpod.Editors.ListEditorOptions(ctx, connect.NewRequest(&v1.ListEditorOptionsRequest{}))
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
items := resp.Msg.GetResult()
completionStr := []string{}
for _, editor := range items {
completionStr = append(completionStr, fmt.Sprintf("%s\t%s", editor.Id, editor.Title))
}
return completionStr, cobra.ShellCompDirectiveNoFileComp
}

func init() {
workspaceCmd.AddCommand(workspaceCreateCmd)
addWorkspaceStartOptions(workspaceCreateCmd, &workspaceCreateOpts.StartOpts)

workspaceCreateCmd.Flags().StringVar(&workspaceCreateOpts.WorkspaceClass, "class", "", "the workspace class")
workspaceCreateCmd.Flags().StringVar(&workspaceCreateOpts.Editor, "editor", "code", "the editor to use")

_ = workspaceCreateCmd.RegisterFlagCompletionFunc("class", classCompletionFunc)
_ = workspaceCreateCmd.RegisterFlagCompletionFunc("editor", editorCompletionFunc)
}
3 changes: 3 additions & 0 deletions components/local-app/cmd/workspace-up.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,7 @@ func init() {

workspaceUpCmd.Flags().StringVar(&workspaceCreateOpts.WorkspaceClass, "class", "", "the workspace class")
workspaceUpCmd.Flags().StringVar(&workspaceCreateOpts.Editor, "editor", "code", "the editor to use")

_ = workspaceUpCmd.RegisterFlagCompletionFunc("class", classCompletionFunc)
_ = workspaceUpCmd.RegisterFlagCompletionFunc("editor", editorCompletionFunc)
}
2 changes: 1 addition & 1 deletion dev/preview/infrastructure/modules/gce/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ variable "harvester_ingress_ip" {
variable "vm_image" {
type = string
description = "The VM image"
default = "gitpod-k3s-202309220725"
default = "gitpod-k3s-202311030912"
}

variable "cert_issuer" {
Expand Down
2 changes: 1 addition & 1 deletion dev/preview/infrastructure/modules/harvester/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ variable "ssh_key" {
variable "vm_image" {
type = string
description = "The VM image"
default = "gitpod-k3s-202309220725"
default = "gitpod-k3s-202311030912"
}

variable "harvester_ingress_ip" {
Expand Down
2 changes: 1 addition & 1 deletion dev/preview/infrastructure/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ variable "vm_type" {
variable "vm_image" {
type = string
description = "The VM image"
default = "gitpod-k3s-202309220725"
default = "gitpod-k3s-202311030912"
}

variable "cert_issuer" {
Expand Down
2 changes: 1 addition & 1 deletion install/installer/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ func ServerComponentWaiterContainer(ctx *RenderContext) *corev1.Container {
// PublicApiServerComponentWaiterContainer is the container used to wait for the deployment/public-api-server to be ready
// it requires pods list access to the cluster
func PublicApiServerComponentWaiterContainer(ctx *RenderContext) *corev1.Container {
image := ctx.ImageName(ctx.Config.Repository, PublicApiComponent, ctx.VersionManifest.Components.Server.Version)
image := ctx.ImageName(ctx.Config.Repository, PublicApiComponent, ctx.VersionManifest.Components.PublicAPIServer.Version)
return componentWaiterContainer(ctx, PublicApiComponent, DefaultLabels(PublicApiComponent), image)
}

Expand Down
4 changes: 0 additions & 4 deletions install/installer/pkg/components/dashboard/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
DNSPolicy: corev1.DNSClusterFirst,
RestartPolicy: corev1.RestartPolicyAlways,
TerminationGracePeriodSeconds: pointer.Int64(30),
InitContainers: []corev1.Container{
*common.PublicApiServerComponentWaiterContainer(ctx),
*common.ServerComponentWaiterContainer(ctx),
},
Containers: []corev1.Container{{
Name: Component,
Image: ctx.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.Dashboard.Version),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package ide

const (
CodeIDEImage = "ide/code"
CodeIDEImageStableVersion = "commit-9126e605808f72ca6870fc881ce6583a8a0042bc" // stable version that will be updated manually on demand
CodeIDEImageStableVersion = "commit-0bfb871a1d539936e3ef9959d7db453ab59af352" // stable version that will be updated manually on demand
CodeHelperIDEImage = "ide/code-codehelper"
CodeWebExtensionImage = "ide/gitpod-code-web"
CodeWebExtensionVersion = "commit-49bb715b599dce2356dd02a6ede7ae8cf10d8d12" // gitpod-web extension version comes from https://github.com/gitpod-io/gitpod-code
Expand Down

0 comments on commit 99dc62d

Please sign in to comment.