diff --git a/.claude/skills/change-the-image/SKILL.md b/.claude/skills/change-the-image/SKILL.md index 625d00c..d6d00c5 100644 --- a/.claude/skills/change-the-image/SKILL.md +++ b/.claude/skills/change-the-image/SKILL.md @@ -5,8 +5,11 @@ description: Add, upgrade or remove a tool in the sandbox image, or change its l # Changing the image -- `provision.sh` installs everything, as root; the Dockerfile only runs it - and sets the user and the PATH. The versions are at the top, as +- `provision.sh` installs everything, as root, in steps: a `step_` + function each, run in the order `STEPS` lists them, or only those named + as its arguments. The Dockerfile runs each step in a `RUN` of its own, so + that each makes a layer, and sets the user and the PATH; the Lima driver + runs the script without arguments. The versions are at the top, as `NAME="${NAME:-default}"`, so a build can override one. - `check.sh` is the layout fctl and images built `FROM` this one rely on, checked in every build. @@ -14,13 +17,14 @@ description: Add, upgrade or remove a tool in the sandbox image, or change its l ## Adding or upgrading a tool -1. **Install it in `provision.sh`.** Prefer Debian's package: add it to the - `apt-get install` list. Otherwise use the project's own installer or - release archive, with the version pinned at the top of the script, and - check the download against the checksum the project publishes, when it - publishes one. A toolchain agents extend (more versions, targets, global - tools) goes in the agent's home through `as_agent`, like rustup and Bun; - anything else system-wide. +1. **Install it in `provision.sh`,** in the step it belongs with. Prefer + Debian's package: add it to that step's `apt_install` list (`tools`, + `build-tools` or `media-tools`). Otherwise use the project's own + installer or release archive, with the version pinned at the top of the + script, and check the download against the checksum the project + publishes, when it publishes one. A toolchain agents extend (more + versions, targets, global tools) goes in the agent's home through + `as_agent`, like rustup and Bun; anything else system-wide. 2. **Make it work from the PATH alone.** fctl-agent passes Claude the PATH, HOME and the locale, nothing else from the image. A tool that needs an environment variable gets a wrapper or a config file instead. A new PATH @@ -30,7 +34,12 @@ description: Add, upgrade or remove a tool in the sandbox image, or change its l its toolchain). 4. **List it** in README.md's "What's inside", with its version. 5. **Say what it costs.** The Image workflow's summary lists each - architecture's size; put the difference in the pull request. + architecture's size, what hosts download and its largest layer; put the + difference in the pull request. Keep each layer under 200 MB + compressed: ghcr.io's download links expire within 5 to 10 minutes, and + Apple's `container` keeps nothing of a pull that broke off. A tool that + would take a layer past that gets a step of its own: a `step_` + function, its name in `STEPS` and a `RUN` in the Dockerfile. An upgrade changes the version at the top of `provision.sh` and in README.md. Rust follows fctl's `rust-toolchain.toml`; Claude Code and fctl aren't pinned @@ -54,8 +63,13 @@ Removing a tool breaks images and sessions that use it: a breaking change - **Login shells.** Setup scripts and the Lima driver run `bash -l`, which reads `/etc/profile.d/fctl.sh`. Keep its PATH and the Dockerfile's `ENV PATH` the same. -- **apt's lists** are removed after the first installs; a later - `apt-get install` needs its own `apt-get update` and cleanup. +- **apt's lists.** Install packages with `apt_install`, which fetches the + lists once per run of the script; the script removes them as it ends, so + that no layer keeps them. A step that adds a source to apt updates the + lists itself, as `node` does. +- **A layer keeps every file its step changes,** whole: a step that + rewrites what an earlier one installed (a `chown -R`, a reinstall, a + cache it refreshes) stores those files twice. - **Python is externally managed.** No `pip install` into the system: use `uv tool install` (as the agent) or a Debian package. - **Playwright's version is its browsers' and their libraries'.** Bumping diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 22df701..eadf311 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -212,11 +212,14 @@ jobs: ARCH: ${{ matrix.arch }} run: | docker buildx create --name sandbox --driver docker-container --use >/dev/null + layout=() if [ "$PUSH" = yes ]; then echo "$GH_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin >/dev/null output="type=image,name=$IMAGE,push-by-digest=true,name-canonical=true,push=true,oci-mediatypes=true" else output="type=docker,name=sandbox:check" + # And as an OCI layout, for its layers' compressed sizes. + layout=(--output "type=oci,dest=$RUNNER_TEMP/layout,tar=false") fi docker buildx build . \ --platform "linux/$ARCH" --pull --provenance=false \ @@ -232,7 +235,7 @@ jobs: --label "org.opencontainers.image.created=$CREATED" \ --label "sh.fctl.version=$VERSION" \ --label "sh.fctl.claude-code.version=$CLAUDE" \ - --output "$output" \ + --output "$output" "${layout[@]}" \ --metadata-file "$RUNNER_TEMP/build.json" if [ "$PUSH" = yes ]; then digest=$(jq -r '."containerimage.digest"' "$RUNNER_TEMP/build.json") @@ -254,6 +257,27 @@ jobs: docker volume rm "$cache" docker image inspect --format '{{.Size}}' "$CHECK" | awk -v arch="$ARCH" '{ printf "%s: %.2f GB\n", arch, $1 / 1e9 }' >> "$GITHUB_STEP_SUMMARY" + - name: Its layers + if: needs.plan.outputs.push != 'yes' + env: + ARCH: ${{ matrix.arch }} + run: | + # What hosts download. ghcr.io's download links expire within 5 to + # 10 minutes, so a large layer may never arrive (the Dockerfile). + layout="$RUNNER_TEMP/layout" + manifest=$(jq -r '.manifests[0].digest' "$layout/index.json") + sizes=$(jq -r '.layers[].size' "$layout/blobs/sha256/${manifest#sha256:}") + awk '{ printf "Layer %d: %.1f MB\n", NR, $1 / 1e6 }' <<<"$sizes" + awk -v arch="$ARCH" '{ total += $1; n++; if ($1 > max) max = $1 } + END { printf "%s: %.2f GB to download, in %d layers of at most %.0f MB\n", arch, total / 1e9, n, max / 1e6 }' \ + <<<"$sizes" | tee -a "$GITHUB_STEP_SUMMARY" + n=0 + while read -r size; do + n=$((n + 1)) + if [ "$size" -gt 200000000 ]; then + echo "::warning::The $ARCH image's layer $n is $((size / 1000000)) MB compressed, over 200 MB: split the step that makes it" + fi + done <<<"$sizes" - name: Note its digest if: needs.plan.outputs.push == 'yes' env: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index cbf6e29..673dc0a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,5 @@ -# ShellCheck for the scripts, actionlint (with ShellCheck) for the workflows. +# ShellCheck for the scripts, actionlint (with ShellCheck) for the workflows, +# and that the Dockerfile runs every step of provision.sh. name: Lint on: @@ -25,6 +26,18 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: ShellCheck run: shellcheck --version && shellcheck provision.sh check.sh check-fctl.sh examples/check.sh kernel/build.sh kernel/check.sh + - name: The Dockerfile runs every step + run: | + # Each in a RUN of its own, in the order of provision.sh's STEPS: a + # step left out would be missing from the image, though fctl's + # Lima driver, which runs them all, would have it. + steps=$(sed -n '/^STEPS=(/,/^)/{/^STEPS=(/d;/^)/d;p}' provision.sh | xargs) + runs=$(sed -n 's|^RUN bash /tmp/provision.sh \([a-z-]*\).*|\1|p' Dockerfile | xargs) + if [ -z "$steps" ] || [ "$steps" != "$runs" ]; then + echo "::error file=Dockerfile::The Dockerfile runs the steps '$runs', but provision.sh's STEPS are '$steps'" + exit 1 + fi + echo "The Dockerfile runs every step: $steps" - name: actionlint run: | archive="actionlint_${ACTIONLINT_VERSION}_linux_amd64.tar.gz" diff --git a/AGENTS.md b/AGENTS.md index 670ed46..cfd0f58 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,8 +12,8 @@ to its code in hyperstructure/fctl. | File | What it is | |---|---| -| `Dockerfile` | The image: runs `provision.sh`, then sets the user and the PATH. | -| `provision.sh` | Installs everything, as root. The versions are at the top. | +| `Dockerfile` | The image: runs each of `provision.sh`'s steps in a layer of its own, then sets the user and the PATH. | +| `provision.sh` | Installs everything, as root, in steps. The versions are at the top. | | `check.sh` | Checks a built image for the layout fctl and derived images rely on. | | `check-fctl.sh` | Develops fctl in a built image, as sessions working on hyperstructure/fctl do. | | `examples/` | Images that don't start from this one, which fctl's docs show (`ubuntu/Dockerfile`), and `check.sh`, which checks any image for what fctl needs of it. | @@ -22,7 +22,7 @@ to its code in hyperstructure/fctl. | `.github/workflows/examples.yml` | Builds the examples for both architectures and checks them with `examples/check.sh`, when they change. | | `kernel/` | The kernel of fctl's Firecracker sandboxes: `build.sh` builds the Linux release in `VERSION` with Firecracker's guest configuration, `check.sh` boots it in Firecracker. | | `.github/workflows/kernel.yml` | Builds the kernel for both architectures, boots it where there is KVM, and publishes it as `ghcr.io/hyperstructure/sandbox-kernel`. | -| `.github/workflows/lint.yml`, `commits.yml`, `skills.yml` | ShellCheck and actionlint; pull request titles; the skills, against the Agent Skills specification. | +| `.github/workflows/lint.yml`, `commits.yml`, `skills.yml` | ShellCheck, actionlint, and that the `Dockerfile` runs every step of `provision.sh`; pull request titles; the skills, against the Agent Skills specification. | | `.claude/skills/` | How to change the image, publish it, and commit. | ## Commands @@ -62,9 +62,10 @@ pull request. context, passing `FCTL_VERSION` and `FCTL_DOWNLOAD` as build arguments. With Lima, it copies `provision.sh` into a Debian 13 VM (Debian 12 with Lima before 2.0, and on hosts of fctl 0.14 and earlier) and runs it as - root with `AGENT_USER` set to the VM's user and the same variables. Keep - both files at the root, under these names, self-contained, and working on - Debian 13 and 12 with a user other than `agent`. + root, without arguments (every step), with `AGENT_USER` set to the VM's + user and the same variables. Keep both files at the root, under these + names, self-contained, and working on Debian 13 and 12 with a user other + than `agent`. - **The tags**: `` for every fctl release, `.` and `latest`. Hosts pull their own version's tag, again every 6 hours for newer builds, and fall back to `latest`. They remove other versions' @@ -119,7 +120,14 @@ hyperstructure/fctl) and, when hosts must adapt, an fctl release first. in the same step. - Mind the size: hosts download the image for every fctl release. Say in the pull request what a change adds; the Image workflow's summary lists - each architecture's size. + each architecture's size and, on pull requests, what hosts download and + its largest layer. +- Keep each layer under 200 MB compressed (the Image workflow warns about + larger ones): ghcr.io's download links expire within 5 to 10 minutes, + and Apple's `container` keeps nothing of a pull that broke off. A tool + goes in the step it belongs with; one that would take a layer past that + gets a step of its own (a `step_` function in `provision.sh`, its name + in `STEPS` and a `RUN` in the `Dockerfile`). - `provision.sh` and `check-fctl.sh` are bash with `set -euo pipefail`; `check.sh` is POSIX sh. All three pass ShellCheck. - Workflows pin actions to a commit SHA with the version in a comment, and diff --git a/Dockerfile b/Dockerfile index db30120..435afff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,25 @@ ARG FCTL_DOWNLOAD= ARG CLAUDE_VERSION= ENV LANG=C.UTF-8 LC_ALL=C.UTF-8 TZ=UTC COPY provision.sh /tmp/provision.sh -RUN bash /tmp/provision.sh && rm /tmp/provision.sh +# Each of provision.sh's steps makes a layer of its own, none over about +# 200 MB compressed: ghcr.io sends each layer's download to a link that +# expires within 5 to 10 minutes, and closes the connection then, and Apple's +# container keeps nothing of a pull that broke off. One layer of 1.3 GB never +# arrived at 2.4 MB/s. +RUN bash /tmp/provision.sh tools +RUN bash /tmp/provision.sh build-tools +RUN bash /tmp/provision.sh media-tools +RUN bash /tmp/provision.sh node +RUN bash /tmp/provision.sh browser-libraries +RUN bash /tmp/provision.sh python +RUN bash /tmp/provision.sh user +RUN bash /tmp/provision.sh claude +RUN bash /tmp/provision.sh rust +RUN bash /tmp/provision.sh rust-std +RUN bash /tmp/provision.sh bun +RUN bash /tmp/provision.sh chromium +RUN bash /tmp/provision.sh webkit +RUN bash /tmp/provision.sh versions && rm /tmp/provision.sh USER agent WORKDIR /home/agent diff --git a/provision.sh b/provision.sh index cdf592c..ed3a3ec 100755 --- a/provision.sh +++ b/provision.sh @@ -11,6 +11,13 @@ # empty means the latest, from https://fctl.sh/releases. CLAUDE_VERSION # picks Claude Code's (empty: the latest); the image workflow passes the one # it labels the image with, so that every architecture gets the same. +# +# It runs its steps (STEPS, below) in order, or only those named as its +# arguments: the Dockerfile runs each in a RUN of its own, so that no layer +# takes long to download (the Dockerfile says why). +# +# bash provision.sh # everything +# bash provision.sh tools node # two steps set -euo pipefail AGENT_USER="${AGENT_USER:-agent}" @@ -32,106 +39,154 @@ FCTL_DOWNLOAD="${FCTL_DOWNLOAD:-}" CLAUDE_VERSION="${CLAUDE_VERSION:-}" export DEBIAN_FRONTEND=noninteractive -apt-get update -apt-get install -y --no-install-recommends \ - ca-certificates curl wget git gnupg less openssh-client procps psmisc lsof sudo \ - rsync unzip xz-utils zip zstd \ - build-essential cmake pkg-config libssl-dev \ - jq ripgrep fd-find tree file shellcheck sqlite3 \ - ffmpeg imagemagick pngquant -# Debian calls fd `fdfind`. -ln -sf /usr/bin/fdfind /usr/local/bin/fd - -# GitHub CLI -curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o /usr/share/keyrings/githubcli-archive-keyring.gpg -echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \ - > /etc/apt/sources.list.d/github-cli.list - -# Node.js, corepack, TypeScript and Playwright. Node.js stopped shipping -# corepack in 25, so it comes from npm, which also puts its yarn and pnpm -# shims on the PATH. npm leaves out its funding and audit notices and its -# update check, which only lengthen agents' output. -curl -fsSL "https://deb.nodesource.com/setup_${NODE_MAJOR}.x" | bash - -apt-get install -y --no-install-recommends gh nodejs -npm config set --location=global fund=false audit=false update-notifier=false -npm install -g "corepack@$COREPACK_VERSION" "typescript@$TYPESCRIPT_VERSION" \ - "playwright@$PLAYWRIGHT_VERSION" -npm cache clean --force +# Installs Debian packages. apt's lists are fetched once per run of the +# script, which removes them as it ends, so that no layer keeps them. +apt_listed= +apt_install() { + [ -n "$apt_listed" ] || apt-get update + apt_listed=yes + apt-get install -y --no-install-recommends "$@" +} + +# Runs a script as the agent user in a login shell; it gets the arguments +# after the script as $1…. +as_agent() { + local script="$1" + shift + sudo -u "$AGENT_USER" -H bash -lc "set -euo pipefail; $script" bash "$@" +} + +# The command-line tools. +step_tools() { + apt_install \ + ca-certificates curl wget git gnupg less openssh-client procps psmisc lsof sudo \ + rsync unzip xz-utils zip zstd \ + jq ripgrep fd-find tree file shellcheck sqlite3 + # Debian calls fd `fdfind`. + ln -sf /usr/bin/fdfind /usr/local/bin/fd +} + +# What builds C and C++. +step_build_tools() { + apt_install build-essential cmake pkg-config libssl-dev +} + +# Recordings and images. +step_media_tools() { + apt_install ffmpeg imagemagick pngquant +} + +# GitHub CLI, Node.js, corepack, TypeScript and Playwright. Node.js stopped +# shipping corepack in 25, so it comes from npm, which also puts its yarn and +# pnpm shims on the PATH. npm leaves out its funding and audit notices and +# its update check, which only lengthen agents' output. +step_node() { + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg -o /usr/share/keyrings/githubcli-archive-keyring.gpg + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \ + > /etc/apt/sources.list.d/github-cli.list + # It updates apt's lists, the GitHub CLI's included. + curl -fsSL "https://deb.nodesource.com/setup_${NODE_MAJOR}.x" | bash - + apt_listed=yes + apt_install gh nodejs + npm config set --location=global fund=false audit=false update-notifier=false + npm install -g "corepack@$COREPACK_VERSION" "typescript@$TYPESCRIPT_VERSION" \ + "playwright@$PLAYWRIGHT_VERSION" + npm cache clean --force +} + # The system libraries and fonts that Playwright's Chromium, Firefox and # WebKit need, from its own list for this Debian release, and Xvfb for -# headed browsers. The agent's browsers come below. -playwright install-deps chromium firefox webkit +# headed browsers. It updates apt's lists itself. The agent's browsers come +# later. +step_browser_libraries() { + playwright install-deps chromium firefox webkit +} # uv, and Python for everyone: uv's build of CPython in /opt/uv/python, as # python3 and python in /usr/local/bin. -curl -LsSf "https://astral.sh/uv/$UV_VERSION/install.sh" | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh -env UV_PYTHON_INSTALL_DIR=/opt/uv/python UV_PYTHON_BIN_DIR=/usr/local/bin UV_NO_CACHE=1 \ - uv python install --default --preview-features python-install-default "$PYTHON_VERSION" - -rm -rf /var/lib/apt/lists/* - -# The agent user. The sandbox is the security boundary, so sudo needs no password. -if ! id "$AGENT_USER" >/dev/null 2>&1; then - useradd -m -s /bin/bash -u 1000 "$AGENT_USER" -fi -echo "$AGENT_USER ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/90-fctl-$AGENT_USER" -chmod 0440 "/etc/sudoers.d/90-fctl-$AGENT_USER" -# Root's: fctl runs its supervisor, fctl-agent, as root from there, so the -# agent user must not put another in its place. -mkdir -p /opt/fctl/bin -chown -R root:root /opt/fctl -chmod 755 /opt/fctl /opt/fctl/bin -# The agent user's: fctl mounts a project's package caches here, and Docker -# gives a new volume the owner of the directory it is mounted on, so a host -# that runs nothing as root in its sandboxes needn't chown it. -install -d -o "$AGENT_USER" -g "$(id -g "$AGENT_USER")" /var/cache/fctl +step_python() { + curl -LsSf "https://astral.sh/uv/$UV_VERSION/install.sh" | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh + env UV_PYTHON_INSTALL_DIR=/opt/uv/python UV_PYTHON_BIN_DIR=/usr/local/bin UV_NO_CACHE=1 \ + uv python install --default --preview-features python-install-default "$PYTHON_VERSION" +} # fctl, for everyone on the machine: agents name and describe their session # with `fctl edit`. A version that is not published (a development build of -# the host) gets the latest release instead. The host copies its own -# fctl-agent in at session start, so the one in the archive goes. +# the host) gets the latest release instead. install_fctl() { curl -fsSL https://fctl.sh/install | env FCTL_VERSION="$1" FCTL_DOWNLOAD="$FCTL_DOWNLOAD" FCTL_INSTALL_DIR=/usr/local/bin \ FCTL_NO_COMPLETIONS=1 sh } -if ! install_fctl "$FCTL_VERSION"; then - [ -n "$FCTL_VERSION" ] || exit 1 - echo "fctl $FCTL_VERSION is not published; installing the latest release" >&2 - install_fctl "" -fi -rm -f /usr/local/bin/fctl-agent-*-linux -# Claude Code, installed for the agent user (native build, ~/.local/bin/claude). -AGENT_HOME="$(getent passwd "$AGENT_USER" | cut -d: -f6)" -sudo -u "$AGENT_USER" -H env CLAUDE_VERSION="$CLAUDE_VERSION" \ - bash -c 'curl -fsSL https://claude.ai/install.sh | bash -s -- ${CLAUDE_VERSION:+"$CLAUDE_VERSION"}' -sudo -u "$AGENT_USER" -H mkdir -p "$AGENT_HOME/workspace" - -# The agent's PATH: Claude Code and uv's tools in ~/.local/bin, Rust's and -# Bun's tools, then fctl's supervisor. The Dockerfile sets the same; login -# shells (setup scripts, the Lima driver's) get it from here. -cat > /etc/profile.d/fctl.sh <<'EOF' +# The agent user, fctl's directories, fctl, and the agent's PATH. +step_user() { + # The sandbox is the security boundary, so sudo needs no password. + if ! id "$AGENT_USER" >/dev/null 2>&1; then + useradd -m -s /bin/bash -u 1000 "$AGENT_USER" + fi + local home + home="$(getent passwd "$AGENT_USER" | cut -d: -f6)" + echo "$AGENT_USER ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/90-fctl-$AGENT_USER" + chmod 0440 "/etc/sudoers.d/90-fctl-$AGENT_USER" + sudo -u "$AGENT_USER" -H mkdir -p "$home/workspace" + # Root's: fctl runs its supervisor, fctl-agent, as root from there, so the + # agent user must not put another in its place. + mkdir -p /opt/fctl/bin + chown -R root:root /opt/fctl + chmod 755 /opt/fctl /opt/fctl/bin + # The agent user's: fctl mounts a project's package caches here, and Docker + # gives a new volume the owner of the directory it is mounted on, so a host + # that runs nothing as root in its sandboxes needn't chown it. + install -d -o "$AGENT_USER" -g "$(id -g "$AGENT_USER")" /var/cache/fctl + + if ! install_fctl "$FCTL_VERSION"; then + [ -n "$FCTL_VERSION" ] || exit 1 + echo "fctl $FCTL_VERSION is not published; installing the latest release" >&2 + install_fctl "" + fi + # The host copies its own fctl-agent in at session start, so the one in + # the archive goes. + rm -f /usr/local/bin/fctl-agent-*-linux + + # The agent's PATH: Claude Code and uv's tools in ~/.local/bin, Rust's and + # Bun's tools, then fctl's supervisor. The Dockerfile sets the same; login + # shells (setup scripts, the Lima driver's, as_agent's) get it from here. + cat > /etc/profile.d/fctl.sh <<'PROFILE' PATH="$HOME/.local/bin:$HOME/.cargo/bin:$HOME/.bun/bin:/opt/fctl/bin:$PATH" -EOF +PROFILE +} -# Runs a script as the agent user in a login shell; it gets the arguments -# after the script as $1…. -as_agent() { - local script="$1" - shift - sudo -u "$AGENT_USER" -H bash -lc "set -euo pipefail; $script" bash "$@" +# Claude Code, installed for the agent user (native build, ~/.local/bin/claude). +step_claude() { + sudo -u "$AGENT_USER" -H env CLAUDE_VERSION="$CLAUDE_VERSION" \ + bash -c 'curl -fsSL https://claude.ai/install.sh | bash -s -- ${CLAUDE_VERSION:+"$CLAUDE_VERSION"}' } # Rust, with the components and targets that rust-toolchain.toml lists, and # Bun, in the agent's home: they find their files through HOME alone # (fctl-agent passes Claude no RUSTUP_HOME or the like), and agents add # toolchains, targets and global tools without sudo. -as_agent 'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | - sh -s -- -y --no-modify-path --profile minimal --default-toolchain "$1" \ - --component rustfmt,clippy --target wasm32-unknown-unknown' "$RUST_VERSION" -as_agent 'curl -fsSL https://bun.sh/install | bash -s "bun-v$1"' "$BUN_VERSION" -as_agent 'ln -sf bun "$HOME/.bun/bin/bunx"' +# +# The compiler, cargo, rustfmt and Clippy first. The standard library for +# this machine goes, to come back in the next step with wasm32's: in one +# layer they are over 200 MB on amd64. +step_rust() { + as_agent 'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | + sh -s -- -y --no-modify-path --profile minimal --default-toolchain "$1" \ + --component rustfmt,clippy + rustup target remove --toolchain "$1" "$(rustc -vV | sed -n "s/^host: //p")"' "$RUST_VERSION" +} + +step_rust_std() { + as_agent 'rustup target add --toolchain "$1" \ + "$(rustc -vV | sed -n "s/^host: //p")" wasm32-unknown-unknown' "$RUST_VERSION" +} + +step_bun() { + as_agent 'curl -fsSL https://bun.sh/install | bash -s "bun-v$1"' "$BUN_VERSION" + as_agent 'ln -sf bun "$HOME/.bun/bin/bunx"' +} # Playwright's headless Chromium and its WebKit, in ~/.cache/ms-playwright, # where Playwright looks for them with HOME alone (fctl leaves @@ -139,9 +194,36 @@ as_agent 'ln -sf bun "$HOME/.bun/bin/bunx"' # add the other browsers and other versions' builds without sudo. They stay # when other versions install theirs, for as long as the global Playwright # that installed them is there. -as_agent 'playwright install --only-shell --no-progress chromium webkit' +step_chromium() { + as_agent 'playwright install --only-shell --no-progress chromium' +} + +step_webkit() { + as_agent 'playwright install --no-progress webkit' +} # What sessions find on the PATH. -as_agent 'claude --version; fctl --version; python3 --version; uv --version - rustc --version; cargo --version; node --version; corepack --version; tsc --version - bun --version; playwright --version' +step_versions() { + as_agent 'claude --version; fctl --version; python3 --version; uv --version + rustc --version; cargo --version; node --version; corepack --version; tsc --version + bun --version; playwright --version' +} + +STEPS=( + tools build-tools media-tools node browser-libraries python + user claude rust rust-std bun chromium webkit versions +) +[ "$#" -gt 0 ] || set -- "${STEPS[@]}" +for step in "$@"; do + case " ${STEPS[*]} " in + *" $step "*) ;; + *) + echo "provision.sh: there is no step $step; the steps are ${STEPS[*]}" >&2 + exit 2 + ;; + esac + "step_${step//-/_}" +done +# No layer keeps apt's lists (apt_install), nor Node.js's compile cache, +# which npm turns on. +rm -rf /var/lib/apt/lists/* /tmp/node-compile-cache