feat(site): allow recreating devcontainers and showing dirty status (#18049)

This change allows showing the devcontainer dirty status in the UI as
well as a recreate button to update the devcontainer.

Closes #16424
This commit is contained in:
Mathias Fredriksson
2025-05-27 19:42:24 +03:00
committed by GitHub
parent 23d14233bf
commit a18eb9d08f
14 changed files with 275 additions and 46 deletions
+13 -5
View File
@@ -450,6 +450,10 @@ type WorkspaceAgentContainer struct {
// Volumes is a map of "things" mounted into the container. Again, this
// is somewhat implementation-dependent.
Volumes map[string]string `json:"volumes"`
// DevcontainerStatus is the status of the devcontainer, if this
// container is a devcontainer. This is used to determine if the
// devcontainer is running, stopped, starting, or in an error state.
DevcontainerStatus WorkspaceAgentDevcontainerStatus `json:"devcontainer_status,omitempty"`
// DevcontainerDirty is true if the devcontainer configuration has changed
// since the container was created. This is used to determine if the
// container needs to be rebuilt.
@@ -518,16 +522,20 @@ func (c *Client) WorkspaceAgentListContainers(ctx context.Context, agentID uuid.
}
// WorkspaceAgentRecreateDevcontainer recreates the devcontainer with the given ID.
func (c *Client) WorkspaceAgentRecreateDevcontainer(ctx context.Context, agentID uuid.UUID, containerIDOrName string) error {
func (c *Client) WorkspaceAgentRecreateDevcontainer(ctx context.Context, agentID uuid.UUID, containerIDOrName string) (Response, error) {
res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/v2/workspaceagents/%s/containers/devcontainers/container/%s/recreate", agentID, containerIDOrName), nil)
if err != nil {
return err
return Response{}, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusNoContent {
return ReadBodyAsError(res)
if res.StatusCode != http.StatusAccepted {
return Response{}, ReadBodyAsError(res)
}
return nil
var m Response
if err := json.NewDecoder(res.Body).Decode(&m); err != nil {
return Response{}, xerrors.Errorf("decode response body: %w", err)
}
return m, nil
}
//nolint:revive // Follow is a control flag on the server as well.
+8 -4
View File
@@ -389,18 +389,22 @@ func (c *AgentConn) ListContainers(ctx context.Context) (codersdk.WorkspaceAgent
// RecreateDevcontainer recreates a devcontainer with the given container.
// This is a blocking call and will wait for the container to be recreated.
func (c *AgentConn) RecreateDevcontainer(ctx context.Context, containerIDOrName string) error {
func (c *AgentConn) RecreateDevcontainer(ctx context.Context, containerIDOrName string) (codersdk.Response, error) {
ctx, span := tracing.StartSpan(ctx)
defer span.End()
res, err := c.apiRequest(ctx, http.MethodPost, "/api/v0/containers/devcontainers/container/"+containerIDOrName+"/recreate", nil)
if err != nil {
return xerrors.Errorf("do request: %w", err)
return codersdk.Response{}, xerrors.Errorf("do request: %w", err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusAccepted {
return codersdk.ReadBodyAsError(res)
return codersdk.Response{}, codersdk.ReadBodyAsError(res)
}
return nil
var m codersdk.Response
if err := json.NewDecoder(res.Body).Decode(&m); err != nil {
return codersdk.Response{}, xerrors.Errorf("decode response body: %w", err)
}
return m, nil
}
// apiRequest makes a request to the workspace agent's HTTP API server.