Skip to content

fix!: use devcontainer ID when rebuilding a devcontainer #18604

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
merged 2 commits into from
Jun 26, 2025

Conversation

DanielleMaywood
Copy link
Contributor

This PR replaces the use of the container ID with the devcontainer ID. This is a breaking change. This allows rebuilding a devcontainer when there is no valid container ID.

This PR replaces the use of the **container** ID with the
**devcontainer** ID. This is a breaking change. This allows rebuilding a
devcontainer when there is no valid container ID.
@DanielleMaywood DanielleMaywood marked this pull request as ready for review June 26, 2025 09:59
@DanielleMaywood DanielleMaywood requested a review from Copilot June 26, 2025 09:59
@github-actions github-actions bot added the release/breaking This label is applied to PRs to detect breaking changes as part of the release process label Jun 26, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR changes API endpoints and internal references to use the devcontainer ID rather than the container ID. Key changes include updating URL paths, parameter names, and related error messages in both the API and its documentation.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
site/src/modules/resources/AgentDevcontainerCard.tsx Updated the endpoint URL to use devcontainer.id
docs/reference/api/agents.md Updated the API documentation and parameter names
codersdk/workspacesdk/agentconn.go Changed function signature and URL path for recreating devcontainers
codersdk/workspaceagents.go Refactored the workspace agent recreate method to use devcontainerID
coderd/workspaceagents_test.go Updated tests to align with the new devcontainer ID usage
coderd/workspaceagents.go, coderd/coderd.go, coderd/apidoc/swagger.json, coderd/apidoc/docs.go Modified routing, error messages, and API docs for consistency
agent/agentcontainers/api_test.go, agent/agentcontainers/api.go Adjusted API routes and tests to reflect the devcontainer changes

return
var workspaceFolder string
for _, dc := range api.knownDevcontainers {
if dc.ID.String() == devcontainerID {
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

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

Consider refactoring the 'knownDevcontainers' map to be keyed by the devcontainer ID instead of the workspaceFolder. This change can improve lookup clarity and avoid potential key collisions when multiple devcontainers share the same workspace folder.

Copilot uses AI. Check for mistakes.

@DanielleMaywood DanielleMaywood requested review from mafredri and johnstcn and removed request for mafredri June 26, 2025 10:02
@johnstcn johnstcn requested a review from mafredri June 26, 2025 10:12
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Except for the minor nit, this looks good to me. A bit more invasive than I imagined but we should be OK and good to get this changed before GA 👍🏻

if dc.ID.String() == devcontainerID {
workspaceFolder = dc.WorkspaceFolder
break
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: This could be simplified by storing dc from the for-loop rather than doing two lookups first ID then workspace folder (which we already know).

@@ -494,8 +494,8 @@ func (api *API) Routes() http.Handler {
r.Get("/", api.handleList)
// TODO(mafredri): Simplify this route as the previous /devcontainers
// /-route was dropped. We can drop the /devcontainers prefix here too.
r.Route("/devcontainers", func(r chi.Router) {
r.Post("/container/{container}/recreate", api.handleDevcontainerRecreate)
r.Route("/devcontainers/{devcontainer}", func(r chi.Router) {
Copy link
Member

Choose a reason for hiding this comment

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

This dawned on me just now, but we could take workspaceFolder here instead, which will allow starting any non-started devcontainer even if it doesn't exist. 😅 We can table this for now though as implementing it would be preemptive and more thought behind it would be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh that could be good to add in the future.

@@ -626,7 +638,7 @@ func TestAPI(t *testing.T) {

for i := range tt.wantStatus {
// Simulate HTTP request to the recreate endpoint.
req := httptest.NewRequest(http.MethodPost, "/devcontainers/container/"+tt.containerID+"/recreate", nil).
req := httptest.NewRequest(http.MethodPost, "/devcontainers/"+tt.devcontainerID+"/recreate", nil).
Copy link
Member

Choose a reason for hiding this comment

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

This is a much more sensible URL 😍

@DanielleMaywood DanielleMaywood merged commit f2d229e into main Jun 26, 2025
39 checks passed
@DanielleMaywood DanielleMaywood deleted the danielle/container-rebuild branch June 26, 2025 10:42
@github-actions github-actions bot locked and limited conversation to collaborators Jun 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release/breaking This label is applied to PRs to detect breaking changes as part of the release process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants