MCPcopy
hub / github.com/coder/mux / postCreateSetup

Method postCreateSetup

src/node/runtime/DockerRuntime.ts:463–516  ·  view source on GitHub ↗

* Post-create setup: provision container OR detect fork and setup credentials. * Runs after mux persists workspace metadata so build logs stream to UI in real-time. * * Handles ALL environment setup: * - Fresh workspace: provisions container (create, sync, checkout, credentials) * - F

(params: WorkspaceInitParams)

Source from the content-addressed store, hash-verified

461 * After this completes, the container is ready for initWorkspace() to run the hook.
462 */
463 async postCreateSetup(params: WorkspaceInitParams): Promise<void> {
464 const {
465 projectPath,
466 branchName,
467 trunkBranch,
468 workspacePath,
469 initLogger,
470 abortSignal,
471 env,
472 skipInitHook,
473 } = params;
474
475 if (!this.containerName) {
476 throw new Error("Container not initialized. Call createWorkspace first.");
477 }
478 const containerName = this.containerName;
479
480 // Check if container already exists (e.g., from successful fork or aborted previous attempt)
481 const containerCheck = await this.checkExistingContainer(
482 containerName,
483 workspacePath,
484 branchName
485 );
486 switch (containerCheck.action) {
487 case "skip":
488 // Fork path: container already valid, just log and setup credentials
489 initLogger.logStep(
490 skipInitHook
491 ? "Container already running (from fork), skipping init hook..."
492 : "Container already running (from fork), running init hook..."
493 );
494 await this.setupCredentials(containerName, env);
495 return;
496 case "cleanup":
497 initLogger.logStep(containerCheck.reason);
498 await runDockerCommand(`docker rm -f ${containerName}`, 10000);
499 break;
500 case "create":
501 break;
502 }
503
504 // Provision container (throws on error - caller handles)
505 await this.provisionContainer({
506 containerName,
507 projectPath,
508 workspacePath,
509 branchName,
510 trunkBranch,
511 initLogger,
512 abortSignal,
513 env,
514 trusted: params.trusted,
515 });
516 }
517
518 /**
519 * Initialize workspace by running .mux/init hook.

Callers

nothing calls this directly

Calls 5

setupCredentialsMethod · 0.95
provisionContainerMethod · 0.95
runDockerCommandFunction · 0.85
logStepMethod · 0.80

Tested by

no test coverage detected