Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions .claude/skills/change-the-image/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ 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.
- README.md lists the tools with their versions, and the layout.

## 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
Expand All @@ -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
Expand All @@ -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
Expand Down
26 changes: 25 additions & 1 deletion .github/workflows/image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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")
Expand All @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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"
Expand Down
22 changes: 15 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand All @@ -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
Expand Down Expand Up @@ -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**: `<fctl version>` for every fctl release, `<major>.<minor>`
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'
Expand Down Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading