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

feat: Add workspace application support #1773

Merged
merged 42 commits into from
Jun 4, 2022
Merged

feat: Add workspace application support #1773

merged 42 commits into from
Jun 4, 2022

Conversation

kylecarbs
Copy link
Member

@kylecarbs kylecarbs commented May 26, 2022

This adds applications as a property to a workspace agent.

The resource is added to the Terraform provider here:
coder/terraform-provider-coder#17

Apps will be opened in the dashboard or via the CLI
with coder open <name>. If command is specified, a
terminal will appear locally and on the web. If target
is specified, the browser will open to an exposed instance
of that target.

  • Fix odd context cancel bug on HTTP transport.

This adds apps as a property to a workspace agent.

The resource is added to the Terraform provider here:
coder/terraform-provider-coder#17

Apps will be opened in the dashboard or via the CLI
with `coder open <name>`. If `command` is specified, a
terminal will appear locally and in the web. If `target`
is specified, the browser will open to an exposed instance
of that target.
Abstracting coderd into an interface added misdirection because
the interface was never intended to be fulfilled outside of a single
implementation.

This lifts the abstraction, and attaches all handlers to a root struct
named `*coderd.API`.
@kylecarbs kylecarbs self-assigned this May 26, 2022
CREATE TABLE workspace_apps (
id uuid NOT NULL,
created_at timestamp with time zone NOT NULL,
agent_id uuid NOT NULL REFERENCES workspace_agents (id) ON DELETE CASCADE,
Copy link
Contributor

Choose a reason for hiding this comment

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

I am unfamiliar with the schemas around agents, builds, templates, etc. I would expect this to be in lifecycle with the template version I think. Why is it related to the agent?

Copy link
Member Author

Choose a reason for hiding this comment

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

Workspace agents are attached to a template version too.

A workspace build can contain different agents than a template version based on variables. This introduces complexity for us, but is something we unfortunately need to account for.

@kylecarbs kylecarbs linked an issue May 31, 2022 that may be closed by this pull request
3 tasks
This is such an intermittent race it's difficult to track,
but regardless this is an improvement to the code.
This is such an intermittent race it's difficult to track,
but regardless this is an improvement to the code.
This is such an intermittent race it's difficult to track,
but regardless this is an improvement to the code.
This is such an intermittent race it's difficult to track,
but regardless this is an improvement to the code.
oneof auth {
string token = 8;
string instance_id = 9;
string token = 9;
Copy link
Contributor

Choose a reason for hiding this comment

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

generally a no-no to change field indexes. Any reason it's particularly important here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's nicer structurally from my perspective.

message App {
string name = 1;
string command = 2;
string url = 3;
Copy link
Contributor

Choose a reason for hiding this comment

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

in the terraform provider docs you say command or url but not both can be set. Should these be in a oneof?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch.

coderd/coderd.go Outdated Show resolved Hide resolved
coderd/coderd.go Outdated Show resolved Hide resolved
coderd/wsconncache/wsconncache.go Outdated Show resolved Hide resolved
coderd/wsconncache/wsconncache.go Outdated Show resolved Hide resolved
coderd/wsconncache/wsconncache.go Show resolved Hide resolved
coderd/wsconncache/wsconncache.go Outdated Show resolved Hide resolved
@spikecurtis
Copy link
Contributor

At a high level, I also find it a bit strange that we're having coderd negotiate a WebRTC connection to the agent, when the agent is already connected to coderd via the channel that the ICE negotiation is happening over.

@spikecurtis
Copy link
Contributor

Also missing from this (Ok if being tracked in other issues)

  • Authorization checks
  • Support for command apps (I'm only seeing URLs supported)

@kylecarbs kylecarbs marked this pull request as ready for review June 3, 2022 05:11
@kylecarbs kylecarbs requested a review from a team as a code owner June 3, 2022 05:11
// %40 is the encoded character of the @ symbol. VS Code Web does
// not handle character encoding properly, so it's safe to assume
// other applications might not as well.
r.Route("/%40{user}/{workspacename}/apps/{workspaceapp}", apps)
Copy link
Contributor

@greyscaled greyscaled Jun 3, 2022

Choose a reason for hiding this comment

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

Does this mean the FE should use encodeURIComponent ?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

so like

async (username: string, workspaceName: string, app: string) => {
  encoderURIComponent(`/api/v0/@{username}/{workspaceName}/apps/{app}`)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Nah, we should always use @ if possible. This is an edge-case for where certain client-side applications don't handle the @ properly.

Copy link
Contributor

Choose a reason for hiding this comment

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

TY!!

// metadata in error pages.
func WithAPIResponse(ctx context.Context, apiResponse APIResponse) context.Context {
return context.WithValue(ctx, apiResponseContextKey{}, apiResponse)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this dev url specific or is it related to the error message discussion from yesterday?

Copy link
Member Author

Choose a reason for hiding this comment

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

Specific to this. The content can be changed trivially too, I intentionally kept it pretty loose while we hash that out.

export interface WorkspaceApp {
readonly id: string
readonly name: string
readonly command?: string
Copy link
Contributor

Choose a reason for hiding this comment

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

what is command?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will open a command inside of a terminal. I'll be opening a subsequent PR to add this in. An issue to track it is here: #2023

Copy link
Contributor

@greyscaled greyscaled left a comment

Choose a reason for hiding this comment

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

FE = ✔️

Copy link
Contributor

@f0ssel f0ssel left a comment

Choose a reason for hiding this comment

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

Generally everything looks good to me. A little long so I didn't dive in super hard but the tests seem to cover enough bases to give me confidence.

@@ -51,7 +51,7 @@ This can be represented by the following truth table, where Y represents *positi

## Example Permissions

- `+site.*.*.read`: allowed to perform the `read` action against all objects of type `devurl` in a given Coder deployment.
Copy link
Contributor

Choose a reason for hiding this comment

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

kill it with 🔥

readonly name: string
readonly command?: string
readonly access_url?: string
readonly icon: string
Copy link
Contributor

Choose a reason for hiding this comment

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

Is icon required? I think we should have some fallback on the frontend and make it optional in terraform if it isn't already.

Copy link
Member Author

Choose a reason for hiding this comment

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

True. I shall fix

@kylecarbs kylecarbs merged commit 013f028 into main Jun 4, 2022
@kylecarbs kylecarbs deleted the apps branch June 4, 2022 20:13
kylecarbs added a commit that referenced this pull request Jun 10, 2022
* feat: Add app support

This adds apps as a property to a workspace agent.

The resource is added to the Terraform provider here:
coder/terraform-provider-coder#17

Apps will be opened in the dashboard or via the CLI
with `coder open <name>`. If `command` is specified, a
terminal will appear locally and in the web. If `target`
is specified, the browser will open to an exposed instance
of that target.

* Compare fields in apps test

* Update Terraform provider to use relative path

* Add some basic structure for routing

* chore: Remove interface from coderd and lift API surface

Abstracting coderd into an interface added misdirection because
the interface was never intended to be fulfilled outside of a single
implementation.

This lifts the abstraction, and attaches all handlers to a root struct
named `*coderd.API`.

* Add basic proxy logic

* Add proxying based on path

* Add app proxying for wildcards

* Add wsconncache

* fix: Race when writing to a closed pipe

This is such an intermittent race it's difficult to track,
but regardless this is an improvement to the code.

* fix: Race when writing to a closed pipe

This is such an intermittent race it's difficult to track,
but regardless this is an improvement to the code.

* fix: Race when writing to a closed pipe

This is such an intermittent race it's difficult to track,
but regardless this is an improvement to the code.

* fix: Race when writing to a closed pipe

This is such an intermittent race it's difficult to track,
but regardless this is an improvement to the code.

* Add workspace route proxying endpoint

- Makes the workspace conn cache concurrency-safe
- Reduces unnecessary open checks in `peer.Channel`
- Fixes the use of a temporary context when dialing a workspace agent

* Add embed errors

* chore: Refactor site to improve testing

It was difficult to develop this package due to the
embed build tag being mandatory on the tests. The logic
to test doesn't require any embedded files.

* Add test for error handler

* Remove unused access url

* Add RBAC tests

* Fix dial agent syntax

* Fix linting errors

* Fix gen

* Fix icon required

* Adjust migration number

* Fix proxy error status code

* Fix empty db lookup
@kylecarbs kylecarbs mentioned this pull request Jun 16, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workspace apps support
5 participants