chore(codersdk): rename WorkspaceAgent(Dev)container structs (#16996)

This is to free up the devcontainer name space for more targeted
structs.

Updates #16423
This commit is contained in:
Mathias Fredriksson
2025-03-19 12:16:14 +02:00
committed by GitHub
parent ef62e626c8
commit 3ac844ad3d
14 changed files with 98 additions and 99 deletions

View File

@ -269,7 +269,7 @@ func (dcl *DockerCLILister) List(ctx context.Context) (codersdk.WorkspaceAgentLi
} }
res := codersdk.WorkspaceAgentListContainersResponse{ res := codersdk.WorkspaceAgentListContainersResponse{
Containers: make([]codersdk.WorkspaceAgentDevcontainer, 0, len(ids)), Containers: make([]codersdk.WorkspaceAgentContainer, 0, len(ids)),
Warnings: make([]string, 0), Warnings: make([]string, 0),
} }
dockerPsStderr := strings.TrimSpace(stderrBuf.String()) dockerPsStderr := strings.TrimSpace(stderrBuf.String())
@ -380,13 +380,13 @@ func (dis dockerInspectState) String() string {
return sb.String() return sb.String()
} }
func convertDockerInspect(raw []byte) ([]codersdk.WorkspaceAgentDevcontainer, []string, error) { func convertDockerInspect(raw []byte) ([]codersdk.WorkspaceAgentContainer, []string, error) {
var warns []string var warns []string
var ins []dockerInspect var ins []dockerInspect
if err := json.NewDecoder(bytes.NewReader(raw)).Decode(&ins); err != nil { if err := json.NewDecoder(bytes.NewReader(raw)).Decode(&ins); err != nil {
return nil, nil, xerrors.Errorf("decode docker inspect output: %w", err) return nil, nil, xerrors.Errorf("decode docker inspect output: %w", err)
} }
outs := make([]codersdk.WorkspaceAgentDevcontainer, 0, len(ins)) outs := make([]codersdk.WorkspaceAgentContainer, 0, len(ins))
// Say you have two containers: // Say you have two containers:
// - Container A with Host IP 127.0.0.1:8000 mapped to container port 8001 // - Container A with Host IP 127.0.0.1:8000 mapped to container port 8001
@ -402,14 +402,14 @@ func convertDockerInspect(raw []byte) ([]codersdk.WorkspaceAgentDevcontainer, []
hostPortContainers := make(map[int][]string) hostPortContainers := make(map[int][]string)
for _, in := range ins { for _, in := range ins {
out := codersdk.WorkspaceAgentDevcontainer{ out := codersdk.WorkspaceAgentContainer{
CreatedAt: in.Created, CreatedAt: in.Created,
// Remove the leading slash from the container name // Remove the leading slash from the container name
FriendlyName: strings.TrimPrefix(in.Name, "/"), FriendlyName: strings.TrimPrefix(in.Name, "/"),
ID: in.ID, ID: in.ID,
Image: in.Config.Image, Image: in.Config.Image,
Labels: in.Config.Labels, Labels: in.Config.Labels,
Ports: make([]codersdk.WorkspaceAgentDevcontainerPort, 0), Ports: make([]codersdk.WorkspaceAgentContainerPort, 0),
Running: in.State.Running, Running: in.State.Running,
Status: in.State.String(), Status: in.State.String(),
Volumes: make(map[string]string, len(in.Mounts)), Volumes: make(map[string]string, len(in.Mounts)),
@ -452,7 +452,7 @@ func convertDockerInspect(raw []byte) ([]codersdk.WorkspaceAgentDevcontainer, []
// Also keep track of the host port and the container ID. // Also keep track of the host port and the container ID.
hostPortContainers[hp] = append(hostPortContainers[hp], in.ID) hostPortContainers[hp] = append(hostPortContainers[hp], in.ID)
} }
out.Ports = append(out.Ports, codersdk.WorkspaceAgentDevcontainerPort{ out.Ports = append(out.Ports, codersdk.WorkspaceAgentContainerPort{
Network: network, Network: network,
Port: cp, Port: cp,
HostPort: uint16(hp), HostPort: uint16(hp),

View File

@ -206,7 +206,7 @@ func TestContainersHandler(t *testing.T) {
fakeCt := fakeContainer(t) fakeCt := fakeContainer(t)
fakeCt2 := fakeContainer(t) fakeCt2 := fakeContainer(t)
makeResponse := func(cts ...codersdk.WorkspaceAgentDevcontainer) codersdk.WorkspaceAgentListContainersResponse { makeResponse := func(cts ...codersdk.WorkspaceAgentContainer) codersdk.WorkspaceAgentListContainersResponse {
return codersdk.WorkspaceAgentListContainersResponse{Containers: cts} return codersdk.WorkspaceAgentListContainersResponse{Containers: cts}
} }
@ -425,13 +425,13 @@ func TestConvertDockerInspect(t *testing.T) {
//nolint:paralleltest // variable recapture no longer required //nolint:paralleltest // variable recapture no longer required
for _, tt := range []struct { for _, tt := range []struct {
name string name string
expect []codersdk.WorkspaceAgentDevcontainer expect []codersdk.WorkspaceAgentContainer
expectWarns []string expectWarns []string
expectError string expectError string
}{ }{
{ {
name: "container_simple", name: "container_simple",
expect: []codersdk.WorkspaceAgentDevcontainer{ expect: []codersdk.WorkspaceAgentContainer{
{ {
CreatedAt: time.Date(2025, 3, 11, 17, 55, 58, 91280203, time.UTC), CreatedAt: time.Date(2025, 3, 11, 17, 55, 58, 91280203, time.UTC),
ID: "6b539b8c60f5230b8b0fde2502cd2332d31c0d526a3e6eb6eef1cc39439b3286", ID: "6b539b8c60f5230b8b0fde2502cd2332d31c0d526a3e6eb6eef1cc39439b3286",
@ -440,14 +440,14 @@ func TestConvertDockerInspect(t *testing.T) {
Labels: map[string]string{}, Labels: map[string]string{},
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{}, Ports: []codersdk.WorkspaceAgentContainerPort{},
Volumes: map[string]string{}, Volumes: map[string]string{},
}, },
}, },
}, },
{ {
name: "container_labels", name: "container_labels",
expect: []codersdk.WorkspaceAgentDevcontainer{ expect: []codersdk.WorkspaceAgentContainer{
{ {
CreatedAt: time.Date(2025, 3, 11, 20, 3, 28, 71706536, time.UTC), CreatedAt: time.Date(2025, 3, 11, 20, 3, 28, 71706536, time.UTC),
ID: "bd8818e670230fc6f36145b21cf8d6d35580355662aa4d9fe5ae1b188a4c905f", ID: "bd8818e670230fc6f36145b21cf8d6d35580355662aa4d9fe5ae1b188a4c905f",
@ -456,14 +456,14 @@ func TestConvertDockerInspect(t *testing.T) {
Labels: map[string]string{"baz": "zap", "foo": "bar"}, Labels: map[string]string{"baz": "zap", "foo": "bar"},
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{}, Ports: []codersdk.WorkspaceAgentContainerPort{},
Volumes: map[string]string{}, Volumes: map[string]string{},
}, },
}, },
}, },
{ {
name: "container_binds", name: "container_binds",
expect: []codersdk.WorkspaceAgentDevcontainer{ expect: []codersdk.WorkspaceAgentContainer{
{ {
CreatedAt: time.Date(2025, 3, 11, 17, 58, 43, 522505027, time.UTC), CreatedAt: time.Date(2025, 3, 11, 17, 58, 43, 522505027, time.UTC),
ID: "fdc75ebefdc0243c0fce959e7685931691ac7aede278664a0e2c23af8a1e8d6a", ID: "fdc75ebefdc0243c0fce959e7685931691ac7aede278664a0e2c23af8a1e8d6a",
@ -472,7 +472,7 @@ func TestConvertDockerInspect(t *testing.T) {
Labels: map[string]string{}, Labels: map[string]string{},
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{}, Ports: []codersdk.WorkspaceAgentContainerPort{},
Volumes: map[string]string{ Volumes: map[string]string{
"/tmp/test/a": "/var/coder/a", "/tmp/test/a": "/var/coder/a",
"/tmp/test/b": "/var/coder/b", "/tmp/test/b": "/var/coder/b",
@ -482,7 +482,7 @@ func TestConvertDockerInspect(t *testing.T) {
}, },
{ {
name: "container_sameport", name: "container_sameport",
expect: []codersdk.WorkspaceAgentDevcontainer{ expect: []codersdk.WorkspaceAgentContainer{
{ {
CreatedAt: time.Date(2025, 3, 11, 17, 56, 34, 842164541, time.UTC), CreatedAt: time.Date(2025, 3, 11, 17, 56, 34, 842164541, time.UTC),
ID: "4eac5ce199d27b2329d0ff0ce1a6fc595612ced48eba3669aadb6c57ebef3fa2", ID: "4eac5ce199d27b2329d0ff0ce1a6fc595612ced48eba3669aadb6c57ebef3fa2",
@ -491,7 +491,7 @@ func TestConvertDockerInspect(t *testing.T) {
Labels: map[string]string{}, Labels: map[string]string{},
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{ Ports: []codersdk.WorkspaceAgentContainerPort{
{ {
Network: "tcp", Network: "tcp",
Port: 12345, Port: 12345,
@ -505,7 +505,7 @@ func TestConvertDockerInspect(t *testing.T) {
}, },
{ {
name: "container_differentport", name: "container_differentport",
expect: []codersdk.WorkspaceAgentDevcontainer{ expect: []codersdk.WorkspaceAgentContainer{
{ {
CreatedAt: time.Date(2025, 3, 11, 17, 57, 8, 862545133, time.UTC), CreatedAt: time.Date(2025, 3, 11, 17, 57, 8, 862545133, time.UTC),
ID: "3090de8b72b1224758a94a11b827c82ba2b09c45524f1263dc4a2d83e19625ea", ID: "3090de8b72b1224758a94a11b827c82ba2b09c45524f1263dc4a2d83e19625ea",
@ -514,7 +514,7 @@ func TestConvertDockerInspect(t *testing.T) {
Labels: map[string]string{}, Labels: map[string]string{},
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{ Ports: []codersdk.WorkspaceAgentContainerPort{
{ {
Network: "tcp", Network: "tcp",
Port: 23456, Port: 23456,
@ -528,7 +528,7 @@ func TestConvertDockerInspect(t *testing.T) {
}, },
{ {
name: "container_sameportdiffip", name: "container_sameportdiffip",
expect: []codersdk.WorkspaceAgentDevcontainer{ expect: []codersdk.WorkspaceAgentContainer{
{ {
CreatedAt: time.Date(2025, 3, 11, 17, 56, 34, 842164541, time.UTC), CreatedAt: time.Date(2025, 3, 11, 17, 56, 34, 842164541, time.UTC),
ID: "a", ID: "a",
@ -537,7 +537,7 @@ func TestConvertDockerInspect(t *testing.T) {
Labels: map[string]string{}, Labels: map[string]string{},
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{ Ports: []codersdk.WorkspaceAgentContainerPort{
{ {
Network: "tcp", Network: "tcp",
Port: 8001, Port: 8001,
@ -555,7 +555,7 @@ func TestConvertDockerInspect(t *testing.T) {
Labels: map[string]string{}, Labels: map[string]string{},
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{ Ports: []codersdk.WorkspaceAgentContainerPort{
{ {
Network: "tcp", Network: "tcp",
Port: 8001, Port: 8001,
@ -570,7 +570,7 @@ func TestConvertDockerInspect(t *testing.T) {
}, },
{ {
name: "container_volume", name: "container_volume",
expect: []codersdk.WorkspaceAgentDevcontainer{ expect: []codersdk.WorkspaceAgentContainer{
{ {
CreatedAt: time.Date(2025, 3, 11, 17, 59, 42, 39484134, time.UTC), CreatedAt: time.Date(2025, 3, 11, 17, 59, 42, 39484134, time.UTC),
ID: "b3688d98c007f53402a55e46d803f2f3ba9181d8e3f71a2eb19b392cf0377b4e", ID: "b3688d98c007f53402a55e46d803f2f3ba9181d8e3f71a2eb19b392cf0377b4e",
@ -579,7 +579,7 @@ func TestConvertDockerInspect(t *testing.T) {
Labels: map[string]string{}, Labels: map[string]string{},
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{}, Ports: []codersdk.WorkspaceAgentContainerPort{},
Volumes: map[string]string{ Volumes: map[string]string{
"/var/lib/docker/volumes/testvol/_data": "/testvol", "/var/lib/docker/volumes/testvol/_data": "/testvol",
}, },
@ -588,7 +588,7 @@ func TestConvertDockerInspect(t *testing.T) {
}, },
{ {
name: "devcontainer_simple", name: "devcontainer_simple",
expect: []codersdk.WorkspaceAgentDevcontainer{ expect: []codersdk.WorkspaceAgentContainer{
{ {
CreatedAt: time.Date(2025, 3, 11, 17, 1, 5, 751972661, time.UTC), CreatedAt: time.Date(2025, 3, 11, 17, 1, 5, 751972661, time.UTC),
ID: "0b2a9fcf5727d9562943ce47d445019f4520e37a2aa7c6d9346d01af4f4f9aed", ID: "0b2a9fcf5727d9562943ce47d445019f4520e37a2aa7c6d9346d01af4f4f9aed",
@ -600,14 +600,14 @@ func TestConvertDockerInspect(t *testing.T) {
}, },
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{}, Ports: []codersdk.WorkspaceAgentContainerPort{},
Volumes: map[string]string{}, Volumes: map[string]string{},
}, },
}, },
}, },
{ {
name: "devcontainer_forwardport", name: "devcontainer_forwardport",
expect: []codersdk.WorkspaceAgentDevcontainer{ expect: []codersdk.WorkspaceAgentContainer{
{ {
CreatedAt: time.Date(2025, 3, 11, 17, 3, 55, 22053072, time.UTC), CreatedAt: time.Date(2025, 3, 11, 17, 3, 55, 22053072, time.UTC),
ID: "4a16af2293fb75dc827a6949a3905dd57ea28cc008823218ce24fab1cb66c067", ID: "4a16af2293fb75dc827a6949a3905dd57ea28cc008823218ce24fab1cb66c067",
@ -619,14 +619,14 @@ func TestConvertDockerInspect(t *testing.T) {
}, },
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{}, Ports: []codersdk.WorkspaceAgentContainerPort{},
Volumes: map[string]string{}, Volumes: map[string]string{},
}, },
}, },
}, },
{ {
name: "devcontainer_appport", name: "devcontainer_appport",
expect: []codersdk.WorkspaceAgentDevcontainer{ expect: []codersdk.WorkspaceAgentContainer{
{ {
CreatedAt: time.Date(2025, 3, 11, 17, 2, 42, 613747761, time.UTC), CreatedAt: time.Date(2025, 3, 11, 17, 2, 42, 613747761, time.UTC),
ID: "52d23691f4b954d083f117358ea763e20f69af584e1c08f479c5752629ee0be3", ID: "52d23691f4b954d083f117358ea763e20f69af584e1c08f479c5752629ee0be3",
@ -638,7 +638,7 @@ func TestConvertDockerInspect(t *testing.T) {
}, },
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{ Ports: []codersdk.WorkspaceAgentContainerPort{
{ {
Network: "tcp", Network: "tcp",
Port: 8080, Port: 8080,
@ -809,9 +809,9 @@ func TestDockerEnvInfoer(t *testing.T) {
} }
} }
func fakeContainer(t *testing.T, mut ...func(*codersdk.WorkspaceAgentDevcontainer)) codersdk.WorkspaceAgentDevcontainer { func fakeContainer(t *testing.T, mut ...func(*codersdk.WorkspaceAgentContainer)) codersdk.WorkspaceAgentContainer {
t.Helper() t.Helper()
ct := codersdk.WorkspaceAgentDevcontainer{ ct := codersdk.WorkspaceAgentContainer{
CreatedAt: time.Now().UTC(), CreatedAt: time.Now().UTC(),
ID: uuid.New().String(), ID: uuid.New().String(),
FriendlyName: testutil.GetRandomName(t), FriendlyName: testutil.GetRandomName(t),
@ -820,7 +820,7 @@ func fakeContainer(t *testing.T, mut ...func(*codersdk.WorkspaceAgentDevcontaine
testutil.GetRandomName(t): testutil.GetRandomName(t), testutil.GetRandomName(t): testutil.GetRandomName(t),
}, },
Running: true, Running: true,
Ports: []codersdk.WorkspaceAgentDevcontainerPort{ Ports: []codersdk.WorkspaceAgentContainerPort{
{ {
Network: "tcp", Network: "tcp",
Port: testutil.RandomPortNoListen(t), Port: testutil.RandomPortNoListen(t),

View File

@ -182,7 +182,7 @@ func renderDevcontainers(wro WorkspaceResourcesOptions, agentID uuid.UUID, index
return rows return rows
} }
func renderDevcontainerRow(container codersdk.WorkspaceAgentDevcontainer, index, total int) table.Row { func renderDevcontainerRow(container codersdk.WorkspaceAgentContainer, index, total int) table.Row {
var row table.Row var row table.Row
var sb strings.Builder var sb strings.Builder
_, _ = sb.WriteString(" ") _, _ = sb.WriteString(" ")

View File

@ -1997,7 +1997,7 @@ func TestSSH_Container(t *testing.T) {
_ = coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait() _ = coderdtest.NewWorkspaceAgentWaiter(t, client, workspace.ID).Wait()
mLister.EXPECT().List(gomock.Any()).Return(codersdk.WorkspaceAgentListContainersResponse{ mLister.EXPECT().List(gomock.Any()).Return(codersdk.WorkspaceAgentListContainersResponse{
Containers: []codersdk.WorkspaceAgentDevcontainer{ Containers: []codersdk.WorkspaceAgentContainer{
{ {
ID: uuid.NewString(), ID: uuid.NewString(),
FriendlyName: "something_completely_different", FriendlyName: "something_completely_different",

8
coderd/apidoc/docs.go generated
View File

@ -16180,7 +16180,7 @@ const docTemplate = `{
} }
} }
}, },
"codersdk.WorkspaceAgentDevcontainer": { "codersdk.WorkspaceAgentContainer": {
"type": "object", "type": "object",
"properties": { "properties": {
"created_at": { "created_at": {
@ -16211,7 +16211,7 @@ const docTemplate = `{
"description": "Ports includes ports exposed by the container.", "description": "Ports includes ports exposed by the container.",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/codersdk.WorkspaceAgentDevcontainerPort" "$ref": "#/definitions/codersdk.WorkspaceAgentContainerPort"
} }
}, },
"running": { "running": {
@ -16231,7 +16231,7 @@ const docTemplate = `{
} }
} }
}, },
"codersdk.WorkspaceAgentDevcontainerPort": { "codersdk.WorkspaceAgentContainerPort": {
"type": "object", "type": "object",
"properties": { "properties": {
"host_ip": { "host_ip": {
@ -16299,7 +16299,7 @@ const docTemplate = `{
"description": "Containers is a list of containers visible to the workspace agent.", "description": "Containers is a list of containers visible to the workspace agent.",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/codersdk.WorkspaceAgentDevcontainer" "$ref": "#/definitions/codersdk.WorkspaceAgentContainer"
} }
}, },
"warnings": { "warnings": {

View File

@ -14753,7 +14753,7 @@
} }
} }
}, },
"codersdk.WorkspaceAgentDevcontainer": { "codersdk.WorkspaceAgentContainer": {
"type": "object", "type": "object",
"properties": { "properties": {
"created_at": { "created_at": {
@ -14784,7 +14784,7 @@
"description": "Ports includes ports exposed by the container.", "description": "Ports includes ports exposed by the container.",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/codersdk.WorkspaceAgentDevcontainerPort" "$ref": "#/definitions/codersdk.WorkspaceAgentContainerPort"
} }
}, },
"running": { "running": {
@ -14804,7 +14804,7 @@
} }
} }
}, },
"codersdk.WorkspaceAgentDevcontainerPort": { "codersdk.WorkspaceAgentContainerPort": {
"type": "object", "type": "object",
"properties": { "properties": {
"host_ip": { "host_ip": {
@ -14872,7 +14872,7 @@
"description": "Containers is a list of containers visible to the workspace agent.", "description": "Containers is a list of containers visible to the workspace agent.",
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/definitions/codersdk.WorkspaceAgentDevcontainer" "$ref": "#/definitions/codersdk.WorkspaceAgentContainer"
} }
}, },
"warnings": { "warnings": {

View File

@ -765,7 +765,7 @@ func (api *API) workspaceAgentListContainers(rw http.ResponseWriter, r *http.Req
} }
// Filter in-place by labels // Filter in-place by labels
cts.Containers = slices.DeleteFunc(cts.Containers, func(ct codersdk.WorkspaceAgentDevcontainer) bool { cts.Containers = slices.DeleteFunc(cts.Containers, func(ct codersdk.WorkspaceAgentContainer) bool {
return !maputil.Subset(labels, ct.Labels) return !maputil.Subset(labels, ct.Labels)
}) })

View File

@ -1164,7 +1164,7 @@ func TestWorkspaceAgentContainers(t *testing.T) {
"com.coder.test": uuid.New().String(), "com.coder.test": uuid.New().String(),
} }
testResponse := codersdk.WorkspaceAgentListContainersResponse{ testResponse := codersdk.WorkspaceAgentListContainersResponse{
Containers: []codersdk.WorkspaceAgentDevcontainer{ Containers: []codersdk.WorkspaceAgentContainer{
{ {
ID: uuid.NewString(), ID: uuid.NewString(),
CreatedAt: dbtime.Now(), CreatedAt: dbtime.Now(),
@ -1173,7 +1173,7 @@ func TestWorkspaceAgentContainers(t *testing.T) {
Labels: testLabels, Labels: testLabels,
Running: true, Running: true,
Status: "running", Status: "running",
Ports: []codersdk.WorkspaceAgentDevcontainerPort{ Ports: []codersdk.WorkspaceAgentContainerPort{
{ {
Network: "tcp", Network: "tcp",
Port: 80, Port: 80,

View File

@ -392,11 +392,11 @@ func (c *Client) WorkspaceAgentListeningPorts(ctx context.Context, agentID uuid.
return listeningPorts, json.NewDecoder(res.Body).Decode(&listeningPorts) return listeningPorts, json.NewDecoder(res.Body).Decode(&listeningPorts)
} }
// WorkspaceAgentDevcontainer describes a devcontainer of some sort // WorkspaceAgentContainer describes a devcontainer of some sort
// that is visible to the workspace agent. This struct is an abstraction // that is visible to the workspace agent. This struct is an abstraction
// of potentially multiple implementations, and the fields will be // of potentially multiple implementations, and the fields will be
// somewhat implementation-dependent. // somewhat implementation-dependent.
type WorkspaceAgentDevcontainer struct { type WorkspaceAgentContainer struct {
// CreatedAt is the time the container was created. // CreatedAt is the time the container was created.
CreatedAt time.Time `json:"created_at" format:"date-time"` CreatedAt time.Time `json:"created_at" format:"date-time"`
// ID is the unique identifier of the container. // ID is the unique identifier of the container.
@ -410,7 +410,7 @@ type WorkspaceAgentDevcontainer struct {
// Running is true if the container is currently running. // Running is true if the container is currently running.
Running bool `json:"running"` Running bool `json:"running"`
// Ports includes ports exposed by the container. // Ports includes ports exposed by the container.
Ports []WorkspaceAgentDevcontainerPort `json:"ports"` Ports []WorkspaceAgentContainerPort `json:"ports"`
// Status is the current status of the container. This is somewhat // Status is the current status of the container. This is somewhat
// implementation-dependent, but should generally be a human-readable // implementation-dependent, but should generally be a human-readable
// string. // string.
@ -420,8 +420,8 @@ type WorkspaceAgentDevcontainer struct {
Volumes map[string]string `json:"volumes"` Volumes map[string]string `json:"volumes"`
} }
// WorkspaceAgentDevcontainerPort describes a port as exposed by a container. // WorkspaceAgentContainerPort describes a port as exposed by a container.
type WorkspaceAgentDevcontainerPort struct { type WorkspaceAgentContainerPort struct {
// Port is the port number *inside* the container. // Port is the port number *inside* the container.
Port uint16 `json:"port"` Port uint16 `json:"port"`
// Network is the network protocol used by the port (tcp, udp, etc). // Network is the network protocol used by the port (tcp, udp, etc).
@ -437,7 +437,7 @@ type WorkspaceAgentDevcontainerPort struct {
// request. // request.
type WorkspaceAgentListContainersResponse struct { type WorkspaceAgentListContainersResponse struct {
// Containers is a list of containers visible to the workspace agent. // Containers is a list of containers visible to the workspace agent.
Containers []WorkspaceAgentDevcontainer `json:"containers"` Containers []WorkspaceAgentContainer `json:"containers"`
// Warnings is a list of warnings that may have occurred during the // Warnings is a list of warnings that may have occurred during the
// process of listing containers. This should not include fatal errors. // process of listing containers. This should not include fatal errors.
Warnings []string `json:"warnings,omitempty"` Warnings []string `json:"warnings,omitempty"`

View File

@ -7843,7 +7843,7 @@ If the schedule is empty, the user will be updated to use the default schedule.|
| `updated_at` | string | false | | | | `updated_at` | string | false | | |
| `version` | string | false | | | | `version` | string | false | | |
## codersdk.WorkspaceAgentDevcontainer ## codersdk.WorkspaceAgentContainer
```json ```json
{ {
@ -7874,21 +7874,21 @@ If the schedule is empty, the user will be updated to use the default schedule.|
### Properties ### Properties
| Name | Type | Required | Restrictions | Description | | Name | Type | Required | Restrictions | Description |
|--------------------|---------------------------------------------------------------------------------------------|----------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------| |--------------------|---------------------------------------------------------------------------------------|----------|--------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `created_at` | string | false | | Created at is the time the container was created. | | `created_at` | string | false | | Created at is the time the container was created. |
| `id` | string | false | | ID is the unique identifier of the container. | | `id` | string | false | | ID is the unique identifier of the container. |
| `image` | string | false | | Image is the name of the container image. | | `image` | string | false | | Image is the name of the container image. |
| `labels` | object | false | | Labels is a map of key-value pairs of container labels. | | `labels` | object | false | | Labels is a map of key-value pairs of container labels. |
| » `[any property]` | string | false | | | | » `[any property]` | string | false | | |
| `name` | string | false | | Name is the human-readable name of the container. | | `name` | string | false | | Name is the human-readable name of the container. |
| `ports` | array of [codersdk.WorkspaceAgentDevcontainerPort](#codersdkworkspaceagentdevcontainerport) | false | | Ports includes ports exposed by the container. | | `ports` | array of [codersdk.WorkspaceAgentContainerPort](#codersdkworkspaceagentcontainerport) | false | | Ports includes ports exposed by the container. |
| `running` | boolean | false | | Running is true if the container is currently running. | | `running` | boolean | false | | Running is true if the container is currently running. |
| `status` | string | false | | Status is the current status of the container. This is somewhat implementation-dependent, but should generally be a human-readable string. | | `status` | string | false | | Status is the current status of the container. This is somewhat implementation-dependent, but should generally be a human-readable string. |
| `volumes` | object | false | | Volumes is a map of "things" mounted into the container. Again, this is somewhat implementation-dependent. | | `volumes` | object | false | | Volumes is a map of "things" mounted into the container. Again, this is somewhat implementation-dependent. |
| » `[any property]` | string | false | | | | » `[any property]` | string | false | | |
## codersdk.WorkspaceAgentDevcontainerPort ## codersdk.WorkspaceAgentContainerPort
```json ```json
{ {
@ -7984,10 +7984,10 @@ If the schedule is empty, the user will be updated to use the default schedule.|
### Properties ### Properties
| Name | Type | Required | Restrictions | Description | | Name | Type | Required | Restrictions | Description |
|--------------|-------------------------------------------------------------------------------------|----------|--------------|---------------------------------------------------------------------------------------------------------------------------------------| |--------------|-------------------------------------------------------------------------------|----------|--------------|---------------------------------------------------------------------------------------------------------------------------------------|
| `containers` | array of [codersdk.WorkspaceAgentDevcontainer](#codersdkworkspaceagentdevcontainer) | false | | Containers is a list of containers visible to the workspace agent. | | `containers` | array of [codersdk.WorkspaceAgentContainer](#codersdkworkspaceagentcontainer) | false | | Containers is a list of containers visible to the workspace agent. |
| `warnings` | array of string | false | | Warnings is a list of warnings that may have occurred during the process of listing containers. This should not include fatal errors. | | `warnings` | array of string | false | | Warnings is a list of warnings that may have occurred during the process of listing containers. This should not include fatal errors. |
## codersdk.WorkspaceAgentListeningPort ## codersdk.WorkspaceAgentListeningPort

View File

@ -3058,20 +3058,20 @@ export interface WorkspaceAgent {
} }
// From codersdk/workspaceagents.go // From codersdk/workspaceagents.go
export interface WorkspaceAgentDevcontainer { export interface WorkspaceAgentContainer {
readonly created_at: string; readonly created_at: string;
readonly id: string; readonly id: string;
readonly name: string; readonly name: string;
readonly image: string; readonly image: string;
readonly labels: Record<string, string>; readonly labels: Record<string, string>;
readonly running: boolean; readonly running: boolean;
readonly ports: readonly WorkspaceAgentDevcontainerPort[]; readonly ports: readonly WorkspaceAgentContainerPort[];
readonly status: string; readonly status: string;
readonly volumes: Record<string, string>; readonly volumes: Record<string, string>;
} }
// From codersdk/workspaceagents.go // From codersdk/workspaceagents.go
export interface WorkspaceAgentDevcontainerPort { export interface WorkspaceAgentContainerPort {
readonly port: number; readonly port: number;
readonly network: string; readonly network: string;
readonly host_ip?: string; readonly host_ip?: string;
@ -3110,7 +3110,7 @@ export const WorkspaceAgentLifecycles: WorkspaceAgentLifecycle[] = [
// From codersdk/workspaceagents.go // From codersdk/workspaceagents.go
export interface WorkspaceAgentListContainersResponse { export interface WorkspaceAgentListContainersResponse {
readonly containers: readonly WorkspaceAgentDevcontainer[]; readonly containers: readonly WorkspaceAgentContainer[];
readonly warnings?: readonly string[]; readonly warnings?: readonly string[];
} }

View File

@ -1,8 +1,8 @@
import type { Meta, StoryObj } from "@storybook/react"; import type { Meta, StoryObj } from "@storybook/react";
import { import {
MockWorkspace, MockWorkspace,
MockWorkspaceAgentDevcontainer, MockWorkspaceAgentContainer,
MockWorkspaceAgentDevcontainerPorts, MockWorkspaceAgentContainerPorts,
} from "testHelpers/entities"; } from "testHelpers/entities";
import { AgentDevcontainerCard } from "./AgentDevcontainerCard"; import { AgentDevcontainerCard } from "./AgentDevcontainerCard";
@ -10,7 +10,7 @@ const meta: Meta<typeof AgentDevcontainerCard> = {
title: "modules/resources/AgentDevcontainerCard", title: "modules/resources/AgentDevcontainerCard",
component: AgentDevcontainerCard, component: AgentDevcontainerCard,
args: { args: {
container: MockWorkspaceAgentDevcontainer, container: MockWorkspaceAgentContainer,
workspace: MockWorkspace, workspace: MockWorkspace,
wildcardHostname: "*.wildcard.hostname", wildcardHostname: "*.wildcard.hostname",
agentName: "dev", agentName: "dev",
@ -25,8 +25,8 @@ export const NoPorts: Story = {};
export const WithPorts: Story = { export const WithPorts: Story = {
args: { args: {
container: { container: {
...MockWorkspaceAgentDevcontainer, ...MockWorkspaceAgentContainer,
ports: MockWorkspaceAgentDevcontainerPorts, ports: MockWorkspaceAgentContainerPorts,
}, },
}, },
}; };

View File

@ -1,6 +1,6 @@
import Link from "@mui/material/Link"; import Link from "@mui/material/Link";
import Tooltip, { type TooltipProps } from "@mui/material/Tooltip"; import Tooltip, { type TooltipProps } from "@mui/material/Tooltip";
import type { Workspace, WorkspaceAgentDevcontainer } from "api/typesGenerated"; import type { Workspace, WorkspaceAgentContainer } from "api/typesGenerated";
import { ExternalLinkIcon } from "lucide-react"; import { ExternalLinkIcon } from "lucide-react";
import type { FC } from "react"; import type { FC } from "react";
import { portForwardURL } from "utils/portForward"; import { portForwardURL } from "utils/portForward";
@ -9,7 +9,7 @@ import { AgentDevcontainerSSHButton } from "./SSHButton/SSHButton";
import { TerminalLink } from "./TerminalLink/TerminalLink"; import { TerminalLink } from "./TerminalLink/TerminalLink";
type AgentDevcontainerCardProps = { type AgentDevcontainerCardProps = {
container: WorkspaceAgentDevcontainer; container: WorkspaceAgentContainer;
workspace: Workspace; workspace: Workspace;
wildcardHostname: string; wildcardHostname: string;
agentName: string; agentName: string;

View File

@ -4277,7 +4277,7 @@ function mockTwoDaysAgo() {
return date.toISOString(); return date.toISOString();
} }
export const MockWorkspaceAgentDevcontainerPorts: TypesGen.WorkspaceAgentDevcontainerPort[] = export const MockWorkspaceAgentContainerPorts: TypesGen.WorkspaceAgentContainerPort[] =
[ [
{ {
port: 1000, port: 1000,
@ -4297,25 +4297,24 @@ export const MockWorkspaceAgentDevcontainerPorts: TypesGen.WorkspaceAgentDevcont
}, },
]; ];
export const MockWorkspaceAgentDevcontainer: TypesGen.WorkspaceAgentDevcontainer = export const MockWorkspaceAgentContainer: TypesGen.WorkspaceAgentContainer = {
{ created_at: "2024-01-04T15:53:03.21563Z",
created_at: "2024-01-04T15:53:03.21563Z", id: "abcd1234",
id: "abcd1234", name: "container-1",
name: "container-1", image: "ubuntu:latest",
image: "ubuntu:latest", labels: {
labels: { foo: "bar",
foo: "bar", },
}, ports: [],
ports: [], running: true,
running: true, status: "running",
status: "running", volumes: {
volumes: { "/mnt/volume1": "/volume1",
"/mnt/volume1": "/volume1", },
}, };
};
export const MockWorkspaceAgentListContainersResponse: TypesGen.WorkspaceAgentListContainersResponse = export const MockWorkspaceAgentListContainersResponse: TypesGen.WorkspaceAgentListContainersResponse =
{ {
containers: [MockWorkspaceAgentDevcontainer], containers: [MockWorkspaceAgentContainer],
warnings: ["This is a warning"], warnings: ["This is a warning"],
}; };