feat(cli): improve devcontainer support for coder show (#18793)

Fixes coder/internal#747
This commit is contained in:
Mathias Fredriksson
2025-07-08 16:16:00 +00:00
committed by GitHub
parent 2f50b3b7bb
commit 5f50dcce5a
14 changed files with 600 additions and 32 deletions
+18 -2
View File
@@ -8,6 +8,7 @@ import (
"github.com/google/uuid"
"github.com/coder/coder/v2/agent/agentcontainers"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/serpent"
@@ -15,9 +16,18 @@ import (
func (r *RootCmd) show() *serpent.Command {
client := new(codersdk.Client)
var details bool
return &serpent.Command{
Use: "show <workspace>",
Short: "Display details of a workspace's resources and agents",
Options: serpent.OptionSet{
{
Flag: "details",
Description: "Show full error messages and additional details.",
Default: "false",
Value: serpent.BoolOf(&details),
},
},
Middleware: serpent.Chain(
serpent.RequireNArgs(1),
r.InitClient(client),
@@ -35,6 +45,7 @@ func (r *RootCmd) show() *serpent.Command {
options := cliui.WorkspaceResourcesOptions{
WorkspaceName: workspace.Name,
ServerVersion: buildInfo.Version,
ShowDetails: details,
}
if workspace.LatestBuild.Status == codersdk.WorkspaceStatusRunning {
// Get listening ports for each agent.
@@ -42,6 +53,7 @@ func (r *RootCmd) show() *serpent.Command {
options.ListeningPorts = ports
options.Devcontainers = devcontainers
}
return cliui.WorkspaceResources(inv.Stdout, workspace.LatestBuild.Resources, options)
},
}
@@ -68,13 +80,17 @@ func fetchRuntimeResources(inv *serpent.Invocation, client *codersdk.Client, res
ports[agent.ID] = lp
mu.Unlock()
}()
if agent.ParentID.Valid {
continue
}
wg.Add(1)
go func() {
defer wg.Done()
dc, err := client.WorkspaceAgentListContainers(inv.Context(), agent.ID, map[string]string{
// Labels set by VSCode Remote Containers and @devcontainers/cli.
"devcontainer.config_file": "",
"devcontainer.local_folder": "",
agentcontainers.DevcontainerConfigFileLabel: "",
agentcontainers.DevcontainerLocalFolderLabel: "",
})
if err != nil {
cliui.Warnf(inv.Stderr, "Failed to get devcontainers for agent %s: %v", agent.Name, err)