-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[public-api] Initial scaffolding and draft #8683
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
Changes from 7 commits
0a5172a
e4aee70
d0991f7
81fc69d
63ca2a4
d955fc6
46f5ab6
f8edb19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
scripts: | ||
- name: lint | ||
deps: | ||
- components/public-api/hack/protoc-gen-gplint:app | ||
script: | | ||
protoc \ | ||
-I /usr/lib/protoc/include -I. \ | ||
--gplint_out=. \ | ||
gitpod/v1/*.proto |
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>", | ||
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: v1 | ||
breaking: | ||
use: | ||
- FILE | ||
lint: | ||
use: | ||
- DEFAULT | ||
ignore: | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/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 | ||
leeway run .: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 |
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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
syntax = "proto3"; | ||
|
||
package gitpod.v1; | ||
|
||
import "google/rpc/status.proto"; | ||
|
||
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 { | ||
google.rpc.Status response_status = 1; | ||
|
||
string prebuild_id = 2; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.