From 5dd0ff21930148ef182627aa4fb771f31f2b9038 Mon Sep 17 00:00:00 2001 From: Chris Wanstrath Date: Fri, 20 Feb 2026 07:23:40 -0800 Subject: [PATCH] dont think bun.$ can do env vars --- src/vm.ts | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/vm.ts b/src/vm.ts index 714b7ab..48899d5 100644 --- a/src/vm.ts +++ b/src/vm.ts @@ -25,6 +25,17 @@ function requireContainer(): void { } } +/** Run a shell command, logging stderr on failure. */ +async function run(cmd: ReturnType, step: string): Promise { + const result = await cmd.nothrow().quiet() + if (result.exitCode !== 0) { + const stderr = result.stderr.toString().trim() + const stdout = result.stdout.toString().trim() + const detail = stderr || stdout || "(no output)" + throw new Error(`${step} failed (exit ${result.exitCode}):\n${detail}`) + } +} + /** Create and provision the container from scratch. Fails if it already exists. */ export async function create(log?: (msg: string) => void): Promise { requireContainer() @@ -36,21 +47,31 @@ export async function create(log?: (msg: string) => void): Promise { const home = homedir() log?.("Pulling image & creating container") - await $`container run -d --name ${CONTAINER_NAME} -m 4G --mount type=bind,source=${home}/dev,target=/host,readonly -v ${home}/.sandlot:/sandlot ubuntu:24.04 sleep infinity`.quiet() + await run( + $`container run -d --name ${CONTAINER_NAME} -m 4G --mount type=bind,source=${home}/dev,target=/host,readonly -v ${home}/.sandlot:/sandlot ubuntu:24.04 sleep infinity`, + "Container creation") // Provision (as root) log?.("Installing packages") - await $`container exec ${CONTAINER_NAME} bash -c ${"apt update && apt install -y curl git neofetch fish"}`.quiet() + await run( + $`container exec ${CONTAINER_NAME} bash -c ${"apt update && apt install -y curl git neofetch fish"}`, + "Package installation") // Create symlinks so git worktree absolute paths from the host resolve inside the container - await $`container exec ${CONTAINER_NAME} bash -c ${`mkdir -p '${home}' && ln -s /host '${home}/dev' && ln -s /sandlot '${home}/.sandlot'`}`.quiet() + await run( + $`container exec ${CONTAINER_NAME} bash -c ${`mkdir -p '${home}' && ln -s /host '${home}/dev' && ln -s /sandlot '${home}/.sandlot'`}`, + "Symlink creation") // Install Bun and Claude Code (as ubuntu user) log?.("Installing Bun") - await $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://bun.sh/install | BUN_INSTALL=$HOME/.local bash"}`.quiet() + await run( + $`container exec --user ${USER} ${CONTAINER_NAME} env BUN_INSTALL=/home/${USER}/.local bash -c ${"curl -fsSL https://bun.sh/install | bash"}`, + "Bun installation") log?.("Installing Claude Code") - await $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://claude.ai/install.sh | bash"}`.quiet() + await run( + $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://claude.ai/install.sh | bash"}`, + "Claude Code installation") log?.("Configuring environment") const gitName = (await $`git config user.name`.quiet().text()).trim()