handleDevcontainerRecreate handles the HTTP request to recreate a devcontainer by referencing the container.
(w http.ResponseWriter, r *http.Request)
| 1383 | // handleDevcontainerRecreate handles the HTTP request to recreate a |
| 1384 | // devcontainer by referencing the container. |
| 1385 | func (api *API) handleDevcontainerRecreate(w http.ResponseWriter, r *http.Request) { |
| 1386 | ctx := r.Context() |
| 1387 | devcontainerID := chi.URLParam(r, "devcontainer") |
| 1388 | |
| 1389 | if devcontainerID == "" { |
| 1390 | httpapi.Write(ctx, w, http.StatusBadRequest, codersdk.Response{ |
| 1391 | Message: "Missing devcontainer ID", |
| 1392 | Detail: "Devcontainer ID is required to recreate a devcontainer.", |
| 1393 | }) |
| 1394 | return |
| 1395 | } |
| 1396 | |
| 1397 | api.mu.Lock() |
| 1398 | |
| 1399 | dc, err := api.devcontainerByIDLocked(devcontainerID) |
| 1400 | if err != nil { |
| 1401 | api.mu.Unlock() |
| 1402 | httperror.WriteResponseError(ctx, w, err) |
| 1403 | return |
| 1404 | } |
| 1405 | if dc.Status.Transitioning() { |
| 1406 | api.mu.Unlock() |
| 1407 | |
| 1408 | httpapi.Write(ctx, w, http.StatusConflict, codersdk.Response{ |
| 1409 | Message: "Unable to recreate transitioning devcontainer", |
| 1410 | Detail: fmt.Sprintf("Devcontainer %q is currently %s and cannot be restarted.", dc.Name, dc.Status), |
| 1411 | }) |
| 1412 | return |
| 1413 | } |
| 1414 | |
| 1415 | // Update the status so that we don't try to recreate the |
| 1416 | // devcontainer multiple times in parallel. |
| 1417 | dc.Status = codersdk.WorkspaceAgentDevcontainerStatusStarting |
| 1418 | dc.Container = nil |
| 1419 | dc.Error = "" |
| 1420 | api.knownDevcontainers[dc.WorkspaceFolder] = dc |
| 1421 | api.broadcastUpdatesLocked() |
| 1422 | |
| 1423 | go func() { |
| 1424 | _ = api.CreateDevcontainer(dc.WorkspaceFolder, dc.ConfigPath, WithRemoveExistingContainer()) |
| 1425 | }() |
| 1426 | |
| 1427 | api.mu.Unlock() |
| 1428 | |
| 1429 | httpapi.Write(ctx, w, http.StatusAccepted, codersdk.Response{ |
| 1430 | Message: "Devcontainer recreation initiated", |
| 1431 | Detail: fmt.Sprintf("Recreation process for devcontainer %q has started.", dc.Name), |
| 1432 | }) |
| 1433 | } |
| 1434 | |
| 1435 | // createDevcontainer should run in its own goroutine and is responsible for |
| 1436 | // recreating a devcontainer based on the provided devcontainer configuration. |
nothing calls this directly
no test coverage detected