Skip to content

Commit c49f6cf

Browse files
committed
feat: add agent devcontainers from provision
1 parent 3ac844a commit c49f6cf

File tree

8 files changed

+78
-0
lines changed

8 files changed

+78
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE workspace_agent_devcontainers;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE TABLE workspace_agent_devcontainers (
2+
id UUID PRIMARY KEY,
3+
workspace_agent_id UUID NOT NULL,
4+
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
5+
workspace_folder TEXT NOT NULL,
6+
config_path TEXT NOT NULL,
7+
FOREIGN KEY (workspace_agent_id) REFERENCES workspace_agents(id) ON DELETE CASCADE
8+
);
9+
10+
COMMENT ON TABLE workspace_agent_devcontainers IS 'Workspace agent devcontainer configuration';
11+
COMMENT ON COLUMN workspace_agent_devcontainers.id IS 'Unique identifier';
12+
COMMENT ON COLUMN workspace_agent_devcontainers.workspace_agent_id IS 'Workspace agent foreign key';
13+
COMMENT ON COLUMN workspace_agent_devcontainers.created_at IS 'Creation timestamp';
14+
COMMENT ON COLUMN workspace_agent_devcontainers.workspace_folder IS 'Workspace folder';
15+
COMMENT ON COLUMN workspace_agent_devcontainers.config_path IS 'Path to devcontainer.json.';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- name: InsertWorkspaceAgentDevcontainers :many
2+
INSERT INTO
3+
workspace_agent_devcontainers (workspace_agent_id, created_at, id, workspace_folder, config_path)
4+
SELECT
5+
@workspace_agent_id::uuid AS workspace_agent_id,
6+
@created_at::timestamptz AS created_at,
7+
unnest(@id::uuid[]) AS id,
8+
unnest(@workspace_folder::text[]) AS workspace_folder,
9+
unnest(@config_path::text[]) AS config_path
10+
RETURNING workspace_agent_devcontainers.*;

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,6 +2096,30 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
20962096
return xerrors.Errorf("insert agent scripts: %w", err)
20972097
}
20982098

2099+
if devcontainers := prAgent.GetDevcontainers(); len(devcontainers) > 0 {
2100+
var (
2101+
devContainerIDs = make([]uuid.UUID, 0, len(devcontainers))
2102+
devContainerWorkspaceFolders = make([]string, 0, len(devcontainers))
2103+
devContainerConfigPaths = make([]string, 0, len(devcontainers))
2104+
)
2105+
for _, dc := range devcontainers {
2106+
devContainerIDs = append(devContainerIDs, uuid.New())
2107+
devContainerWorkspaceFolders = append(devContainerWorkspaceFolders, dc.WorkspaceFolder)
2108+
devContainerConfigPaths = append(devContainerConfigPaths, dc.ConfigPath)
2109+
}
2110+
2111+
_, err = db.InsertWorkspaceAgentDevcontainers(ctx, database.InsertWorkspaceAgentDevcontainersParams{
2112+
WorkspaceAgentID: agentID,
2113+
CreatedAt: dbtime.Now(),
2114+
ID: devContainerIDs,
2115+
WorkspaceFolder: devContainerWorkspaceFolders,
2116+
ConfigPath: devContainerConfigPaths,
2117+
})
2118+
if err != nil {
2119+
return xerrors.Errorf("insert agent devcontainer: %w", err)
2120+
}
2121+
}
2122+
20992123
for _, app := range prAgent.Apps {
21002124
// Similar logic is duplicated in terraform/resources.go.
21012125
slug := app.Slug

codersdk/agentsdk/agentsdk.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ type Manifest struct {
121121
DisableDirectConnections bool `json:"disable_direct_connections"`
122122
Metadata []codersdk.WorkspaceAgentMetadataDescription `json:"metadata"`
123123
Scripts []codersdk.WorkspaceAgentScript `json:"scripts"`
124+
Devcontainers []codersdk.WorkspaceAgentDevcontainer `json:"devcontainers"`
124125
}
125126

126127
type LogSource struct {

codersdk/workspaceagents.go

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

395+
// WorkspaceAgentDevcontainer defines the location of a devcontainer
396+
// configuration in a workspace that is visible to the workspace agent.
397+
type WorkspaceAgentDevcontainer struct {
398+
ID uuid.UUID `json:"id" format:"uuid"`
399+
WorkspaceFolder string `json:"workspace_folder"`
400+
ConfigPath string `json:"config_path,omitempty"`
401+
}
402+
395403
// WorkspaceAgentContainer describes a devcontainer of some sort
396404
// that is visible to the workspace agent. This struct is an abstraction
397405
// of potentially multiple implementations, and the fields will be

provisioner/terraform/resources.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ type agentAttributes struct {
5757
DisplayApps []agentDisplayAppsAttributes `mapstructure:"display_apps"`
5858
Order int64 `mapstructure:"order"`
5959
ResourcesMonitoring []agentResourcesMonitoring `mapstructure:"resources_monitoring"`
60+
Devcontainers []agentDevcontainer `mapstructure:"devcontainers"`
61+
}
62+
63+
type agentDevcontainer struct {
64+
WorkspaceFolder string `mapstructure:"workspace_folder"`
65+
ConfigPath string `mapstructure:"config_path"`
6066
}
6167

6268
type agentResourcesMonitoring struct {
@@ -347,6 +353,13 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
347353
agent.Auth = &proto.Agent_InstanceId{}
348354
}
349355

356+
for _, devcontainer := range attrs.Devcontainers {
357+
agent.Devcontainers = append(agent.Devcontainers, &proto.Devcontainer{
358+
WorkspaceFolder: devcontainer.WorkspaceFolder,
359+
ConfigPath: devcontainer.ConfigPath,
360+
})
361+
}
362+
350363
// The label is used to find the graph node!
351364
agentLabel := convertAddressToLabel(tfResource.Address)
352365

provisionersdk/proto/provisioner.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ message Agent {
141141
repeated Env extra_envs = 22;
142142
int64 order = 23;
143143
ResourcesMonitoring resources_monitoring = 24;
144+
repeated Devcontainer devcontainers = 25;
144145
}
145146

146147
enum AppSharingLevel {
@@ -191,6 +192,11 @@ message Script {
191192
string log_path = 9;
192193
}
193194

195+
message Devcontainer {
196+
string workspace_folder = 1;
197+
string config_path = 2;
198+
}
199+
194200
enum AppOpenIn {
195201
WINDOW = 0 [deprecated = true];
196202
SLIM_WINDOW = 1;

0 commit comments

Comments
 (0)