Skip to content
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

[public-api] Initial scaffolding and draft #8683

Merged
merged 8 commits into from
Mar 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
/components/local-app @gitpod-io/engineering-ide
/components/openvsx-proxy @gitpod-io/engineering-ide
/components/proxy @gitpod-io/engineering-webapp
/components/public-api @csweichel @akosyakov @geropl
/components/registry-facade-api @csweichel @aledbf
/components/registry-facade @gitpod-io/engineering-workspace
/components/server @gitpod-io/engineering-webapp
Expand Down
9 changes: 9 additions & 0 deletions components/public-api/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"protoc": {
"compile_on_save": false,
"options": [
"--proto_path=.",
"--proto_path=${workspaceRoot}/components/public-api"
]
}
}
101 changes: 101 additions & 0 deletions components/public-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Public-API

# Example Flows
This section gives examples how clients would use this API.

## Create Workspace

### Not prebuild aware
```go
workspaces.CreateWorkspace({
idempotency_token: "<random_string>",
csweichel marked this conversation as resolved.
Show resolved Hide resolved
context_url: "https://github.com/gitpod-io/gitpod",
})
```

### Prebuild aware but no log support
```go
workspaces.CreateWorkspace({
idempotency_token: "<random_string>",
context_url: "https://github.com/gitpod-io/gitpod",
prebuild: {
if_available: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be the default behavior.

}
})
```

### Prebuild aware with log support
```go
contextURL := "https://github.com/gitpod-io/gitpod"
prb := prebuilds.GetRunningPrebuild({ context_url: contextURL })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe starting prebuilds and starting workspaces have so much in common, that we should rather generalize over them and make 'prebuild' a property on the workspaces API rather than duplicating everything in a prebuilds API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for listening to logs and status updates, we could use a prebuild's workspace instance. Also there might be an image build ongoing.

logs := prebuilds.ListenToPrebuild({ context_url: contextURL, prebuild_id: prb.PrebuildID })
csweichel marked this conversation as resolved.
Show resolved Hide resolved

for logs.Recv() {
// display logs
}
// once logs are done, prebuild is done (errors notwithstanding)

workspaces.CreateWorkspace({
idempotency_token: "<random_string>",
context_url: contextURL,
prebuild: {
prebuild_id: prb.PrebuildID,
}
})
```

## Start Workspace

### Ignoring image-build logs
```Go
// Get ahold of a workspace ID, either by finding an existing workspace
// or creating a new one.
workspaceID := ...

// Start the workspace
workspaces.StartWorkspace({
idempotency_token: "<random_string>",
workspace_id: workspaceID,
})
```

### With image build log support
```Go
// Get ahold of a workspace ID, either by finding an existing workspace
// or creating a new one.
workspaceID := ...

// Start the workspace
resp := workspaces.StartWorkspace({
idempotency_token: "<random_string>",
workspace_id: workspaceID,
})

// Listen to updates for the instance we just created
updates := workspaces.ListenToWorkspaceInstance({
instance_id: resp.InstanceId
})
var lastSeenVersion uint64
for {
update := updates.Recv()
if lastSeenVersion == update.Version {
continue
}
lastSeenVersion = update.Version

switch update.Phase {
case ImageBuild:
go showImageBuildLogs(instanceID)
case Running:
// do something with this running workspace
}
}

func showImageBuildLogs(instanceID string) {
logs := workspaces.ListenToImageBuildLogs({instance_id: instanceID})
for {
resp := logs.Recv()
fmt.Println(resp.Line)
}
}
```
7 changes: 7 additions & 0 deletions components/public-api/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1
breaking:
use:
- FILE
lint:
use:
- DEFAULT
27 changes: 27 additions & 0 deletions components/public-api/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

if [ -n "$DEBUG" ]; then
set -x
fi

set -o errexit
set -o nounset
set -o pipefail

ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)/../../
COMPONENTS_DIR="$ROOT_DIR"/components

# include protoc bash functions
# shellcheck disable=SC1090,SC1091
source "$ROOT_DIR"/scripts/protoc-generator.sh

lint

install_dependencies
go_protoc "$COMPONENTS_DIR" "gitpod/v1"
mkdir -p go/v1
mv go/gitpod/v1/*.pb.go go/v1
rm -rf go/gitpod
typescript_protoc "$COMPONENTS_DIR" "gitpod/v1"

update_license
13 changes: 13 additions & 0 deletions components/public-api/gitpod/v1/pagination.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";

package gitpod.v1;

option go_package = "github.com/gitpod-io/gitpod/public-api/v1";

message Pagination {
// page_size is the maximum number of results we expect
int32 page_size = 1;

// page_token points to a specific page of the results
string page_token = 2;
}
26 changes: 26 additions & 0 deletions components/public-api/gitpod/v1/prebuilds.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";

package gitpod.v1;

option go_package = "github.com/gitpod-io/gitpod/public-api/v1";

// import "gitpod/v1/pagination.proto";

service PrebuildsService {

// GetRunningPrebuild returns the prebuild ID of a running prebuild,
// or NOT_FOUND if there is no prebuild running for the content_url.
rpc GetRunningPrebuild(GetRunningPrebuildRequest) returns (GetRunningPrebuildResponse) {}

}

message GetRunningPrebuildRequest {
string context_url = 1;
}

message GetRunningPrebuildResponse {
// Status status = 1;

string prebuild_id = 2;
}

Loading