Add tooling cache and install neofetch, difftastic, and Neovim in containers
This commit is contained in:
parent
ed43aaff78
commit
4f913b6091
55
src/vm.ts
55
src/vm.ts
|
|
@ -47,9 +47,12 @@ async function createContainer(home: string): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Install base system packages (as root). */
|
/** Install base system packages (as root). */
|
||||||
async function installPackages(): Promise<void> {
|
async function installPackages(cached: boolean): Promise<void> {
|
||||||
|
const packages = cached
|
||||||
|
? "curl git fish"
|
||||||
|
: "curl git fish unzip"
|
||||||
await run(
|
await run(
|
||||||
$`container exec ${CONTAINER_NAME} bash -c ${"apt update && apt install -y curl git neofetch fish unzip"}`,
|
$`container exec ${CONTAINER_NAME} bash -c ${`apt update && apt install -y ${packages}`}`,
|
||||||
"Package installation")
|
"Package installation")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,8 +63,25 @@ async function createHostSymlinks(home: string): Promise<void> {
|
||||||
"Symlink creation")
|
"Symlink creation")
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Install Bun and Claude Code (as ubuntu user). */
|
const CACHE_DIR = join(homedir(), '.sandlot', '.cache')
|
||||||
async function installTooling(log?: (msg: string) => void): Promise<void> {
|
|
||||||
|
/** Check whether the package cache is populated. */
|
||||||
|
async function hasCachedTooling(): Promise<boolean> {
|
||||||
|
const files = ['bun', 'claude', 'neofetch', 'difft', 'nvim.tar.gz']
|
||||||
|
const checks = await Promise.all(files.map(f => Bun.file(join(CACHE_DIR, f)).exists()))
|
||||||
|
return checks.every(Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Install Bun, Claude Code, neofetch, and Neovim, using cached binaries when available. */
|
||||||
|
async function installTooling(cached: boolean, log?: (msg: string) => void): Promise<void> {
|
||||||
|
if (cached) {
|
||||||
|
log?.("Installing packages (cached)")
|
||||||
|
await run(
|
||||||
|
$`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"mkdir -p ~/.local/bin && cp /sandlot/.cache/bun /sandlot/.cache/claude /sandlot/.cache/neofetch /sandlot/.cache/difft ~/.local/bin/ && chmod +x ~/.local/bin/bun ~/.local/bin/claude ~/.local/bin/neofetch ~/.local/bin/difft && ln -sf bun ~/.local/bin/bunx && tar xzf /sandlot/.cache/nvim.tar.gz -C ~/.local --strip-components=1"}`,
|
||||||
|
"Install from cache")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
log?.("Installing Bun")
|
log?.("Installing Bun")
|
||||||
await run(
|
await run(
|
||||||
$`container exec --user ${USER} ${CONTAINER_NAME} env BUN_INSTALL=/home/${USER}/.local bash -c ${"curl -fsSL https://bun.sh/install | bash"}`,
|
$`container exec --user ${USER} ${CONTAINER_NAME} env BUN_INSTALL=/home/${USER}/.local bash -c ${"curl -fsSL https://bun.sh/install | bash"}`,
|
||||||
|
|
@ -71,6 +91,25 @@ async function installTooling(log?: (msg: string) => void): Promise<void> {
|
||||||
await run(
|
await run(
|
||||||
$`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://claude.ai/install.sh | bash"}`,
|
$`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://claude.ai/install.sh | bash"}`,
|
||||||
"Claude Code installation")
|
"Claude Code installation")
|
||||||
|
|
||||||
|
log?.("Installing neofetch")
|
||||||
|
await run(
|
||||||
|
$`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://raw.githubusercontent.com/dylanaraps/neofetch/master/neofetch -o ~/.local/bin/neofetch && chmod +x ~/.local/bin/neofetch"}`,
|
||||||
|
"neofetch installation")
|
||||||
|
|
||||||
|
log?.("Installing difftastic")
|
||||||
|
await $`mkdir -p ${CACHE_DIR}`.quiet()
|
||||||
|
await run(
|
||||||
|
$`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://github.com/Wilfred/difftastic/releases/latest/download/difft-aarch64-unknown-linux-gnu.tar.gz | tar xz -C ~/.local/bin"}`,
|
||||||
|
"difftastic installation")
|
||||||
|
|
||||||
|
log?.("Installing Neovim")
|
||||||
|
await run(
|
||||||
|
$`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"curl -fsSL https://github.com/neovim/neovim/releases/latest/download/nvim-linux-arm64.tar.gz -o /sandlot/.cache/nvim.tar.gz && tar xzf /sandlot/.cache/nvim.tar.gz -C ~/.local --strip-components=1"}`,
|
||||||
|
"Neovim installation")
|
||||||
|
|
||||||
|
// Cache binaries for next time
|
||||||
|
await $`container exec --user ${USER} ${CONTAINER_NAME} bash -c ${"cp ~/.local/bin/bun ~/.local/bin/claude ~/.local/bin/neofetch ~/.local/bin/difft /sandlot/.cache/"}`.nothrow().quiet()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Configure git identity, API key helper, activity hook, and Claude settings. */
|
/** Configure git identity, API key helper, activity hook, and Claude settings. */
|
||||||
|
|
@ -136,14 +175,16 @@ export async function create(log?: (msg: string) => void): Promise<void> {
|
||||||
|
|
||||||
const home = homedir()
|
const home = homedir()
|
||||||
|
|
||||||
|
const cached = await hasCachedTooling()
|
||||||
|
|
||||||
log?.("Pulling image & creating container")
|
log?.("Pulling image & creating container")
|
||||||
await createContainer(home)
|
await createContainer(home)
|
||||||
|
|
||||||
log?.("Installing packages")
|
log?.("Installing packages")
|
||||||
await installPackages()
|
await installPackages(cached)
|
||||||
await createHostSymlinks(home)
|
await createHostSymlinks(home)
|
||||||
|
|
||||||
await installTooling(log)
|
await installTooling(cached, log)
|
||||||
|
|
||||||
log?.("Configuring environment")
|
log?.("Configuring environment")
|
||||||
const apiKey = await getApiKey()
|
const apiKey = await getApiKey()
|
||||||
|
|
@ -235,7 +276,7 @@ export async function shell(workdir?: string): Promise<void> {
|
||||||
/** Run neofetch in the container. */
|
/** Run neofetch in the container. */
|
||||||
export async function info(): Promise<void> {
|
export async function info(): Promise<void> {
|
||||||
const proc = Bun.spawn(
|
const proc = Bun.spawn(
|
||||||
["container", "exec", "--user", USER, CONTAINER_NAME, "neofetch"],
|
["container", "exec", "--user", USER, CONTAINER_NAME, "env", `PATH=/home/${USER}/.local/bin:/usr/bin:/bin`, "neofetch"],
|
||||||
{ stdin: "inherit", stdout: "inherit", stderr: "inherit" },
|
{ stdin: "inherit", stdout: "inherit", stderr: "inherit" },
|
||||||
)
|
)
|
||||||
await proc.exited
|
await proc.exited
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user