Skip to content

Commit 97474bb

Browse files
authored
feat: support devcontainer agents in ui and unify backend (#18332)
This commit consolidates two container endpoints on the backend and improves the frontend devcontainer support by showing names and displaying apps as appropriate. With this change, the frontend now has knowledge of the subagent and we can also display things like port forwards. The frontend was updated to show dev container labels on the border as well as subagent connection status. The recreation flow was also adjusted a bit to show placeholder app icons when relevant. Support for apps was also added, although these are still WIP on the backend. And the port forwarding utility was added in since the sub agents now provide the necessary info. Fixes coder/internal#666
1 parent cda9208 commit 97474bb

File tree

22 files changed

+1261
-662
lines changed

22 files changed

+1261
-662
lines changed

agent/agentcontainers/api.go

Lines changed: 189 additions & 167 deletions
Large diffs are not rendered by default.

agent/agentcontainers/api_test.go

Lines changed: 112 additions & 68 deletions
Large diffs are not rendered by default.

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/workspaceagents_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,15 +1403,13 @@ func TestWorkspaceAgentRecreateDevcontainer(t *testing.T) {
14031403
agentcontainers.DevcontainerConfigFileLabel: configFile,
14041404
}
14051405
devContainer = codersdk.WorkspaceAgentContainer{
1406-
ID: uuid.NewString(),
1407-
CreatedAt: dbtime.Now(),
1408-
FriendlyName: testutil.GetRandomName(t),
1409-
Image: "busybox:latest",
1410-
Labels: dcLabels,
1411-
Running: true,
1412-
Status: "running",
1413-
DevcontainerDirty: true,
1414-
DevcontainerStatus: codersdk.WorkspaceAgentDevcontainerStatusRunning,
1406+
ID: uuid.NewString(),
1407+
CreatedAt: dbtime.Now(),
1408+
FriendlyName: testutil.GetRandomName(t),
1409+
Image: "busybox:latest",
1410+
Labels: dcLabels,
1411+
Running: true,
1412+
Status: "running",
14151413
}
14161414
plainContainer = codersdk.WorkspaceAgentContainer{
14171415
ID: uuid.NewString(),

codersdk/workspaceagents.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,6 @@ func (c *Client) WorkspaceAgentListeningPorts(ctx context.Context, agentID uuid.
393393
return listeningPorts, json.NewDecoder(res.Body).Decode(&listeningPorts)
394394
}
395395

396-
// WorkspaceAgentDevcontainersResponse is the response to the devcontainers
397-
// request.
398-
type WorkspaceAgentDevcontainersResponse struct {
399-
Devcontainers []WorkspaceAgentDevcontainer `json:"devcontainers"`
400-
}
401-
402396
// WorkspaceAgentDevcontainerStatus is the status of a devcontainer.
403397
type WorkspaceAgentDevcontainerStatus string
404398

@@ -422,6 +416,15 @@ type WorkspaceAgentDevcontainer struct {
422416
Status WorkspaceAgentDevcontainerStatus `json:"status"`
423417
Dirty bool `json:"dirty"`
424418
Container *WorkspaceAgentContainer `json:"container,omitempty"`
419+
Agent *WorkspaceAgentDevcontainerAgent `json:"agent,omitempty"`
420+
}
421+
422+
// WorkspaceAgentDevcontainerAgent represents the sub agent for a
423+
// devcontainer.
424+
type WorkspaceAgentDevcontainerAgent struct {
425+
ID uuid.UUID `json:"id" format:"uuid"`
426+
Name string `json:"name"`
427+
Directory string `json:"directory"`
425428
}
426429

427430
// WorkspaceAgentContainer describes a devcontainer of some sort
@@ -450,14 +453,6 @@ type WorkspaceAgentContainer struct {
450453
// Volumes is a map of "things" mounted into the container. Again, this
451454
// is somewhat implementation-dependent.
452455
Volumes map[string]string `json:"volumes"`
453-
// DevcontainerStatus is the status of the devcontainer, if this
454-
// container is a devcontainer. This is used to determine if the
455-
// devcontainer is running, stopped, starting, or in an error state.
456-
DevcontainerStatus WorkspaceAgentDevcontainerStatus `json:"devcontainer_status,omitempty"`
457-
// DevcontainerDirty is true if the devcontainer configuration has changed
458-
// since the container was created. This is used to determine if the
459-
// container needs to be rebuilt.
460-
DevcontainerDirty bool `json:"devcontainer_dirty"`
461456
}
462457

463458
func (c *WorkspaceAgentContainer) Match(idOrName string) bool {
@@ -486,6 +481,8 @@ type WorkspaceAgentContainerPort struct {
486481
// WorkspaceAgentListContainersResponse is the response to the list containers
487482
// request.
488483
type WorkspaceAgentListContainersResponse struct {
484+
// Devcontainers is a list of devcontainers visible to the workspace agent.
485+
Devcontainers []WorkspaceAgentDevcontainer `json:"devcontainers"`
489486
// Containers is a list of containers visible to the workspace agent.
490487
Containers []WorkspaceAgentContainer `json:"containers"`
491488
// Warnings is a list of warnings that may have occurred during the

docs/reference/api/agents.md

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

0 commit comments

Comments
 (0)