Skip to content

Commit 7531563

Browse files
committed
feat: Add DevURL support
This adds DevURLs as a property to a workspace agent. The resource is added to the Terraform provider here: coder/terraform-provider-coder#17 DevURLs 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.
1 parent 914a2f4 commit 7531563

24 files changed

+1036
-214
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"coderdtest",
88
"codersdk",
99
"devel",
10+
"apps",
1011
"drpc",
1112
"drpcconn",
1213
"drpcmux",

coderd/database/databasefake/databasefake.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func New() database.Store {
3434
templateVersions: make([]database.TemplateVersion, 0),
3535
templates: make([]database.Template, 0),
3636
workspaceBuilds: make([]database.WorkspaceBuild, 0),
37+
workspaceApps: make([]database.WorkspaceApp, 0),
3738
workspaces: make([]database.Workspace, 0),
3839
}
3940
}
@@ -62,6 +63,7 @@ type fakeQuerier struct {
6263
templateVersions []database.TemplateVersion
6364
templates []database.Template
6465
workspaceBuilds []database.WorkspaceBuild
66+
workspaceApps []database.WorkspaceApp
6567
workspaces []database.Workspace
6668
}
6769

@@ -328,6 +330,41 @@ func (q *fakeQuerier) GetWorkspaceByOwnerIDAndName(_ context.Context, arg databa
328330
return database.Workspace{}, sql.ErrNoRows
329331
}
330332

333+
func (q *fakeQuerier) GetWorkspaceAppsByAgentID(_ context.Context, id uuid.UUID) ([]database.WorkspaceApp, error) {
334+
q.mutex.RLock()
335+
defer q.mutex.RUnlock()
336+
337+
apps := make([]database.WorkspaceApp, 0)
338+
for _, app := range q.workspaceApps {
339+
if app.AgentID == id {
340+
apps = append(apps, app)
341+
}
342+
}
343+
if len(apps) == 0 {
344+
return nil, sql.ErrNoRows
345+
}
346+
return apps, nil
347+
}
348+
349+
func (q *fakeQuerier) GetWorkspaceAppsByAgentIDs(_ context.Context, ids []uuid.UUID) ([]database.WorkspaceApp, error) {
350+
q.mutex.RLock()
351+
defer q.mutex.RUnlock()
352+
353+
apps := make([]database.WorkspaceApp, 0)
354+
for _, app := range q.workspaceApps {
355+
for _, id := range ids {
356+
if app.AgentID.String() == id.String() {
357+
apps = append(apps, app)
358+
break
359+
}
360+
}
361+
}
362+
if len(apps) == 0 {
363+
return nil, sql.ErrNoRows
364+
}
365+
return apps, nil
366+
}
367+
331368
func (q *fakeQuerier) GetWorkspaceOwnerCountsByTemplateIDs(_ context.Context, templateIDs []uuid.UUID) ([]database.GetWorkspaceOwnerCountsByTemplateIDsRow, error) {
332369
q.mutex.RLock()
333370
defer q.mutex.RUnlock()
@@ -1353,6 +1390,23 @@ func (q *fakeQuerier) InsertWorkspaceBuild(_ context.Context, arg database.Inser
13531390
return workspaceBuild, nil
13541391
}
13551392

1393+
func (q *fakeQuerier) InsertWorkspaceApp(_ context.Context, arg database.InsertWorkspaceAppParams) (database.WorkspaceApp, error) {
1394+
q.mutex.Lock()
1395+
defer q.mutex.Unlock()
1396+
1397+
workspaceApp := database.WorkspaceApp{
1398+
ID: arg.ID,
1399+
AgentID: arg.AgentID,
1400+
CreatedAt: arg.CreatedAt,
1401+
Name: arg.Name,
1402+
Icon: arg.Icon,
1403+
Command: arg.Command,
1404+
Target: arg.Target,
1405+
}
1406+
q.workspaceApps = append(q.workspaceApps, workspaceApp)
1407+
return workspaceApp, nil
1408+
}
1409+
13561410
func (q *fakeQuerier) UpdateAPIKeyByID(_ context.Context, arg database.UpdateAPIKeyByIDParams) error {
13571411
q.mutex.Lock()
13581412
defer q.mutex.Unlock()

coderd/database/dump.sql

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE workspace_apps;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATE TABLE workspace_apps (
2+
id uuid NOT NULL,
3+
created_at timestamp with time zone NOT NULL,
4+
agent_id uuid NOT NULL REFERENCES workspace_agents (id) ON DELETE CASCADE,
5+
name varchar(64) NOT NULL,
6+
icon varchar(256) NOT NULL,
7+
-- A command to run when opened.
8+
command varchar(65534),
9+
-- A URL or port to target.
10+
target varchar(65534),
11+
PRIMARY KEY (id),
12+
UNIQUE(agent_id, name)
13+
)

coderd/database/models.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 118 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- name: GetWorkspaceAppsByAgentID :many
2+
SELECT * FROM workspace_apps WHERE agent_id = $1;
3+
4+
-- name: GetWorkspaceAppsByAgentIDs :many
5+
SELECT * FROM workspace_apps WHERE agent_id = ANY(@ids :: uuid [ ]);
6+
7+
-- name: InsertWorkspaceApp :one
8+
INSERT INTO
9+
workspace_apps (
10+
id,
11+
created_at,
12+
agent_id,
13+
name,
14+
icon,
15+
command,
16+
target
17+
)
18+
VALUES
19+
($1, $2, $3, $4, $5, $6, $7) RETURNING *;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy