dont think bun.$ can do env vars

This commit is contained in:
Chris Wanstrath 2026-02-20 07:23:40 -08:00
parent 773e8d56a4
commit 5dd0ff2193

View File

@ -25,6 +25,17 @@ function requireContainer(): void {
} }
} }
/** Run a shell command, logging stderr on failure. */
async function run(cmd: ReturnType<typeof $>, step: string): Promise<void> {
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. */ /** Create and provision the container from scratch. Fails if it already exists. */
export async function create(log?: (msg: string) => void): Promise<void> { export async function create(log?: (msg: string) => void): Promise<void> {
requireContainer() requireContainer()
@ -36,21 +47,31 @@ export async function create(log?: (msg: string) => void): Promise<void> {
const home = homedir() const home = homedir()
log?.("Pulling image & creating container") 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) // Provision (as root)
log?.("Installing packages") 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 // 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) // Install Bun and Claude Code (as ubuntu user)
log?.("Installing Bun") 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") 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") log?.("Configuring environment")
const gitName = (await $`git config user.name`.quiet().text()).trim() const gitName = (await $`git config user.name`.quiet().text()).trim()