Skip to content

feat(agent/agentcontainers): add devcontainers list endpoint #17389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mafredri
Copy link
Member

This change allows listing both predefined and runtime-detected
devcontainers, as well as showing whether or not the devcontainer is
running and which container represents it.

Fixes coder/internal#478


The intent here is to replace the currently used containers endpoint with this one as it provides more context on devcontainers, including ones that have not been started yet, or removed at some point.

This change allows listing both predefined and runtime-detected
devcontainers, as well as showing whether or not the devcontainer is
running and which container represents it.

Fixes coder/internal#478
@mafredri mafredri self-assigned this Apr 14, 2025
@@ -121,12 +148,11 @@ func (api *API) getContainers(ctx context.Context) (codersdk.WorkspaceAgentListC
select {
case <-ctx.Done():
return codersdk.WorkspaceAgentListContainersResponse{}, ctx.Err()
default:
api.lockCh <- struct{}{}
case api.lockCh <- struct{}{}:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Drive-by bug fix.

@@ -158,7 +234,7 @@ func (api *API) handleRecreate(w http.ResponseWriter, r *http.Request) {
return
}

containers, err := api.cl.List(ctx)
containers, err := api.getContainers(ctx)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Drive-by bug fix.

lockCh chan struct{}
containers codersdk.WorkspaceAgentListContainersResponse
mtime time.Time

devcontainersMu sync.Mutex // Protects following.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a separate mutex here? Can we not reuse lockCh?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not as ergonomic but sure, switched to it 😄


// Check if the container is running and update the known devcontainers.
for _, container := range updated.Containers {
workspaceFolder := container.Labels[DevcontainerLocalFolderLabel]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought, non-blocking: Given that a WorkspaceAgentDevcontainer is a superset of a WorkspaceAgentContainer, I wonder if we could instead store the optional devcontainer-specific fields in WorkspaceAgentContainer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue with that approach is: how do we represent a devcontainer we know about but that has no container? (I.e. either it wasn't started, or it was deleted.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha 👍

Copy link
Contributor

@DanielleMaywood DanielleMaywood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

@mafredri mafredri merged commit 00b5f56 into main Apr 15, 2025
35 of 37 checks passed
@mafredri mafredri deleted the mafredri/feat-agent-agentcontainers-add-devcontainers-endpoint branch April 15, 2025 14:53
@github-actions github-actions bot locked and limited conversation to collaborators Apr 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

agent: implement the capability to list devcontainer config file paths relevant to all running devcontainers
3 participants