Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1ef8fc1

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#17DevURLs will be opened in the dashboard or via the CLIwith `coder open <name>`. If `command` is specified, aterminal will appear locally and in the web. If `target`is specified, the browser will open to an exposed instanceof that target.
1 parent914a2f4 commit1ef8fc1

21 files changed

+790
-212
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+
"devurls",
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+
workspaceDevurls:make([]database.WorkspaceDevurl,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+
workspaceDevurls []database.WorkspaceDevurl
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)GetWorkspaceDevurlsByAgentID(_ context.Context,id uuid.UUID) ([]database.WorkspaceDevurl,error) {
334+
q.mutex.RLock()
335+
deferq.mutex.RUnlock()
336+
337+
devurls:=make([]database.WorkspaceDevurl,0)
338+
for_,devurl:=rangeq.workspaceDevurls {
339+
ifdevurl.AgentID==id {
340+
devurls=append(devurls,devurl)
341+
}
342+
}
343+
iflen(devurls)==0 {
344+
returnnil,sql.ErrNoRows
345+
}
346+
returndevurls,nil
347+
}
348+
349+
func (q*fakeQuerier)GetWorkspaceDevurlsByAgentIDs(_ context.Context,ids []uuid.UUID) ([]database.WorkspaceDevurl,error) {
350+
q.mutex.RLock()
351+
deferq.mutex.RUnlock()
352+
353+
devurls:=make([]database.WorkspaceDevurl,0)
354+
for_,devurl:=rangeq.workspaceDevurls {
355+
for_,id:=rangeids {
356+
ifdevurl.AgentID.String()==id.String() {
357+
devurls=append(devurls,devurl)
358+
break
359+
}
360+
}
361+
}
362+
iflen(devurls)==0 {
363+
returnnil,sql.ErrNoRows
364+
}
365+
returndevurls,nil
366+
}
367+
331368
func (q*fakeQuerier)GetWorkspaceOwnerCountsByTemplateIDs(_ context.Context,templateIDs []uuid.UUID) ([]database.GetWorkspaceOwnerCountsByTemplateIDsRow,error) {
332369
q.mutex.RLock()
333370
deferq.mutex.RUnlock()
@@ -1353,6 +1390,23 @@ func (q *fakeQuerier) InsertWorkspaceBuild(_ context.Context, arg database.Inser
13531390
returnworkspaceBuild,nil
13541391
}
13551392

1393+
func (q*fakeQuerier)InsertWorkspaceDevurl(_ context.Context,arg database.InsertWorkspaceDevurlParams) (database.WorkspaceDevurl,error) {
1394+
q.mutex.Lock()
1395+
deferq.mutex.Unlock()
1396+
1397+
workspaceDevurl:= database.WorkspaceDevurl{
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.workspaceDevurls=append(q.workspaceDevurls,workspaceDevurl)
1407+
returnworkspaceDevurl,nil
1408+
}
1409+
13561410
func (q*fakeQuerier)UpdateAPIKeyByID(_ context.Context,arg database.UpdateAPIKeyByIDParams)error {
13571411
q.mutex.Lock()
13581412
deferq.mutex.Unlock()

‎coderd/database/dump.sql

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROPTABLE workspace_devurls;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CREATETABLEworkspace_devurls (
2+
id uuidNOT NULL,
3+
created_attimestamp with time zoneNOT NULL,
4+
agent_id uuidNOT NULLREFERENCES workspace_agents (id)ON DELETE CASCADE,
5+
namevarchar(64)NOT NULL,
6+
iconvarchar(256)NOT NULL,
7+
-- A command to run when opened.
8+
commandvarchar(65534),
9+
-- A URL or port to target.
10+
targetvarchar(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 aboutcustomizing 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 aboutcustomizing 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 aboutcustomizing 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: GetWorkspaceDevurlsByAgentID :many
2+
SELECT*FROM workspace_devurlsWHERE agent_id= $1;
3+
4+
-- name: GetWorkspaceDevurlsByAgentIDs :many
5+
SELECT*FROM workspace_devurlsWHERE agent_id= ANY(@ids :: uuid [ ]);
6+
7+
-- name: InsertWorkspaceDevurl :one
8+
INSERT INTO
9+
workspace_devurls (
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*;

‎coderd/provisionerdaemons.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ func insertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
625625
}
626626
}
627627

628-
_,err:=db.InsertWorkspaceAgent(ctx, database.InsertWorkspaceAgentParams{
628+
dbAgent,err:=db.InsertWorkspaceAgent(ctx, database.InsertWorkspaceAgentParams{
629629
ID:uuid.New(),
630630
CreatedAt:database.Now(),
631631
UpdatedAt:database.Now(),
@@ -645,6 +645,27 @@ func insertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
645645
iferr!=nil {
646646
returnxerrors.Errorf("insert agent: %w",err)
647647
}
648+
649+
for_,devurl:=rangeagent.Devurls {
650+
_,err:=db.InsertWorkspaceDevurl(ctx, database.InsertWorkspaceDevurlParams{
651+
ID:uuid.New(),
652+
CreatedAt:database.Now(),
653+
AgentID:dbAgent.ID,
654+
Name:devurl.Name,
655+
Icon:devurl.Icon,
656+
Command: sql.NullString{
657+
String:devurl.Command,
658+
Valid:devurl.Command!="",
659+
},
660+
Target: sql.NullString{
661+
String:devurl.Target,
662+
Valid:devurl.Target!="",
663+
},
664+
})
665+
iferr!=nil {
666+
returnxerrors.Errorf("insert devurl: %w",err)
667+
}
668+
}
648669
}
649670
returnnil
650671
}

‎coderd/provisionerjobs.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,20 @@ func (api *api) provisionerJobResources(rw http.ResponseWriter, r *http.Request,
209209
})
210210
return
211211
}
212+
resourceAgentIDs:=make([]uuid.UUID,0)
213+
for_,agent:=rangeresourceAgents {
214+
resourceAgentIDs=append(resourceAgentIDs,agent.ID)
215+
}
216+
devurls,err:=api.Database.GetWorkspaceDevurlsByAgentIDs(r.Context(),resourceAgentIDs)
217+
iferrors.Is(err,sql.ErrNoRows) {
218+
err=nil
219+
}
220+
iferr!=nil {
221+
httpapi.Write(rw,http.StatusInternalServerError, httpapi.Response{
222+
Message:fmt.Sprintf("get workspace devurls: %s",err),
223+
})
224+
return
225+
}
212226

213227
apiResources:=make([]codersdk.WorkspaceResource,0)
214228
for_,resource:=rangeresources {
@@ -217,7 +231,14 @@ func (api *api) provisionerJobResources(rw http.ResponseWriter, r *http.Request,
217231
ifagent.ResourceID!=resource.ID {
218232
continue
219233
}
220-
apiAgent,err:=convertWorkspaceAgent(agent,api.AgentConnectionUpdateFrequency)
234+
dbDevurls:=make([]database.WorkspaceDevurl,0)
235+
for_,devurl:=rangedevurls {
236+
ifdevurl.AgentID==agent.ID {
237+
dbDevurls=append(dbDevurls,devurl)
238+
}
239+
}
240+
241+
apiAgent,err:=convertWorkspaceAgent(agent,convertDevurls(dbDevurls),api.AgentConnectionUpdateFrequency)
221242
iferr!=nil {
222243
httpapi.Write(rw,http.StatusInternalServerError, httpapi.Response{
223244
Message:fmt.Sprintf("convert provisioner job agent: %s",err),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp