Files
w3cjandClaude Opus 5.5 a8f0517579 feat(lima): devvm downloads Ubuntu's cloud image itself
Lima's download of the cloud image neither retries nor times out: one cut
in its 900 MB fails base's build, and a stall hangs it. devvm now
downloads the pinned image itself through fetch.Resumable
(ubuntu.Download), into images/ubuntu/<sha256>.img (Dirs.UbuntuImage),
resuming across cuts, stalls and runs, and gives Lima that file. Lima
2.3 checks a local file against the digest before it copies it.

- Before downloading, it takes the image from Lima's own download cache
  when that holds it with the pin's SHA-256: copied into a new file of
  devvm's own, mode 600, hashed as it's written, capped, stopped by the
  context, and kept only once it checks out. Lima's cache is never
  changed, and a base whose dated release Ubuntu may have removed still
  builds again.
- One devvm downloads at a time (images/locks/ubuntu-image), another
  waiting under ubuntu_image_waiting and looking again under the lock
  (TestUbuntuImageAfterWait, which fails without that second look).
- The download goes through the company proxy and trusts the user's CAs
  (Lima.Roots, from trust.Pool, which internal/cli passes through the
  registry), as do the Finder's lookups (TestNewTrustsRoots, and the
  registry's TestOverrides). An untrusted certificate is
  ubuntu_untrusted, naming the CAs' folder, one from a trusted CA
  that's for another host, out of date or not valid yet
  ubuntu_bad_certificate (check the clock and what answers for the
  host), and any other that fails to verify (a SHA-1 signature, a CA's
  name constraints, a key for clients alone) ubuntu_certificate_invalid,
  naming Go's reason, for the lookups (the listing, the checksums, their
  signature: TestLookupCertificates) and the download alike
  (TestLocalImageFailsFor), and a release Ubuntu removed (404, 410)
  ubuntu_release_gone, which names devvm rebuild base; none is retried.
  ubuntu_download_failed no longer starts with devvm.
- fetch.Untrusted, fetch.BadCertificate (an x509.HostnameError, or a
  CertificateInvalidError that's Expired) and fetch.Unverified (any
  failure to verify, with its reason, so every error the other two
  name), beside fetch.Gone, are the one
  place that tells a certificate's failures apart: Transient asks
  Unverified, the lookups and the download ask all three, host mise
  asks Untrusted, and a forbidigo rule keeps x509's and tls's
  verification errors in internal/fetch (TestCertificateClasses,
  TestTransient, testdata/lint, the owners doc's row).
- An https address, or a test build's file:// DEVVM_UBUNTU_URL, read
  from disk the same way; anything else is refused. The CLI tests'
  sandbox has a stand-in of this host's image in the store.
- Base's record keeps the image's address, and the key is as it was: it
  hashes the pin (release, file, digest), not the location.
- devvm gc --caches frees devvm's copies that no record names and that
  aren't pinned now, unchanged for an hour, a stopped .part and a killed
  import's .import included, and those of a kept image once its .img is
  there. A pin it can't read fails it.
- Of Lima's cache, it frees only an entry that devvm's own state shows a
  build of devvm's left: a base record names its address, devvm has its
  own copy of the image, and the installed Lima's own templates
  (share/lima/templates beside limactl, Lima.Templates) don't name it.
  An entry no record names may be the user's own Lima's, so it stays,
  and none is freed when the templates can't be read, with a line in
  the run log naming the folder and why. A test build's
  DEVVM_LIMA_TEMPLATES stands in for the templates folder.
- ubuntu.ParseImage reads a record's image as Image.String writes it,
  and ubuntu.IsSHA256 is the one check of a cloud image's SHA-256, in
  place of Lima's own regex.
- devvm space shows the copies as a cloud images row, freed by gc
  --caches, kept as state, as a release Ubuntu removed can't be
  downloaded again.

0.1.0's frozen state runs the new commands (fixture_v010_cloud_image):
devvm looks in Lima's cache under the SHA-256 of the address 0.1.0's
base record keeps and never changes the entry, base builds from devvm's
own copy, and gc --caches keeps that copy, frees Lima's entry the
record names and devvm's own stale copies, and keeps an older entry no
record names.

Docs: images.md (the download, its failures, the import, gc's rules),
space.md, backends/lima.md, settings.md (the lookups and the download
trust your CAs), troubleshooting.md, overview.md, testing.md,
tests.md, structure.md's internal/fetch row; the CHANGELOG's two Fixed
lines, which later commits make highlights, What to do 5 and 6, and the
release page's Ubuntu's cloud image in devvm's folder.

New messages: downloading_ubuntu, importing_ubuntu, ubuntu_image_waiting,
ubuntu_download_failed, ubuntu_release_gone, ubuntu_bad_certificate,
ubuntu_certificate_invalid, ubuntu_image_checksum, ubuntu_untrusted.
Lima.LocalImage is the seam, Lima.ImageClient the client.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-29 22:53:34 -07:00

302 lines
14 KiB
Plaintext

# --from: base from a container image, converted into a disk in a
# throwaway VM from Ubuntu's image, keyed by the image's digest: from its
# registry, else Docker's ID for an image only Docker has. Registries are
# never reached here: a pinned digest needs no lookup, and HTTPS_PROXY
# points at nothing, so every lookup is offline.
env IMAGES=$XDG_DATA_HOME/devvm/images
env LOCK=$XDG_DATA_HOME/devvm/oci-build.lock
env TMPDIR=$WORK/tmp
mkdir $TMPDIR
env PIN=node:24@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
env HTTPS_PROXY=http://127.0.0.1:9
env https_proxy=http://127.0.0.1:9
# Not an image reference: refused before anything runs, from the flag or
# from DEVVM_FROM.
! exec devvm --from 'node;x' build base
stderr '^devvm: bad_from from=node;x$'
env DEVVM_FROM='a b'
! exec devvm build base
stderr '^devvm: bad_from from=a b$'
env DEVVM_FROM=
! stub_calls
# A pinned digest: no lookup, no Docker. A build VM from Ubuntu's image,
# with only a folder of devvm's temporary one mounted writable and
# devvm's oci/ (written into that temporary folder) read-only, converts exactly
# that digest; it's deleted before base is
# created from what it wrote (outside the folder it wrote in), and the
# temporary folder goes once base has started. The conversion lock's file,
# left as a devvm that crashed leaves it, holds nothing, so the build goes
# on (TestLockOCI checks that a free lock shows no wait).
exec sh -c ': > "$LOCK"'
exec sh -c 'echo musl > "$STUB_DIR/build-libc"'
exec devvm --from $PIN build base
stdout '^==> building_image_from from=node:24@sha256:a{64} image=base key=[0-9a-f]{12}$'
! stdout base_build_time
stdout '^==> converting_in_vm from=node:24@sha256:a{64} vm=devvm-oci-build$'
stdout '^==> image_ready image=base$'
stub_calls
! stdout '^docker'
stdout '^limactl create --tty=false --mount-none --name=devvm-oci-build --set \.images = \[\{"location":"/\S*/data/devvm/images/ubuntu/[0-9a-f]{64}\.img","arch":"(aarch64|x86_64)","digest":"sha256:[0-9a-f]{64}"\}\] --set \.mounts = \[\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm","writable":true,"9p":\{"cache":"none"\}\},\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/oci","writable":false\}\] --cpus=4 --memory=8 --disk=100 -$'
stdout '^limactl start --tty=false devvm-oci-build$'
# With HTTPS_PROXY set, the build goes through a proxy of devvm's, which
# alone has the host's proxy settings: the script reads that proxy's
# address on its input first, then runs with its arguments.
stdout '^limactl shell --start=false --workdir / devvm-oci-build sudo bash -s -- /\S*/tmp/devvm-oci\.[0-9]+/oci/build\.sh /\S*/tmp/devvm-oci\.[0-9]+/oci /\S*/tmp/devvm-oci\.[0-9]+/vm node:24@sha256:a{64} node:24@sha256:a{64} \S+ [0-9]+ /home/\S+\.guest 20G$'
stdout '^limactl delete -f devvm-oci-build\nlimactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} --set \.images = \[\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm/disk\.raw","arch":"(aarch64|x86_64)","kernel":\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm/kernel","cmdline":"root=/dev/vda rw console=hvc0"\},"initrd":\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm/initrd"\}\}\] --cpus=4 --memory=8 --disk=100 -$'
cmp $STUB_DIR/create-template $DEVVM_REPO/assets/base.yaml
stdout '^limactl shell --start=false devvm-img-[0-9a-f]{12} bash -s$'
exec sh -c 'ls "$TMPDIR"'
! stdout .
# The builds' proxies are gone, with their files.
! exists $XDG_DATA_HOME/devvm/run/builds/devvm-oci-build
exec find $XDG_DATA_HOME/devvm/run/builds -name '*proxy*'
! stdout .
# Its record: what it came from, and musl from the image.
catg $IMAGES/????????????/record.json
stdout '^ "name": "base",$'
stdout '^ "from": "node:24@sha256:a{64}",$'
stdout '^ "digest": "node:24@sha256:a{64}",$'
stdout '^ "libc": "musl",$'
# Each step numbered: the conversion's five, then base's, with sudo told
# to keep the build proxy's settings and told no more.
exec sh -c 'cat "$XDG_DATA_HOME"/devvm/logs/runs/*.log'
stdout '^# \[1/14\] creating_from_ubuntu vm=devvm-oci-build$'
stdout '^# \[2/14\] configuring what=devvm-oci-build$'
stdout '^# \[3/14\] starting what=devvm-oci-build$'
stdout '^# \[4/14\] converting from=node:24@sha256:a{64}$'
stdout '^# \[5/14\] deleting what=devvm-oci-build$'
stdout '^# \[6/14\] creating vm=devvm-img-'
stdout '^# \[14/14\] stopping vm=devvm-img-'
! stdout '\[15/14\]'
# A --from base's packages are its image's own: nothing sent or taken.
! exists $STUB_DIR/packages-in.tar
! exists $DATA/packages/sets
# Built: reused, without a lookup; a layer on it records where its base
# came from. Ubuntu's base is another image.
stub_reset
exec sh -c 'mkdir -p "$CFG/layers"; printf "#!/bin/bash\necho foo\n" > "$CFG/layers/foo.sh"'
exec devvm --from $PIN build foo
! stdout 'building_image_from .*image=base '
stdout '^==> building_image_from from=node:24@sha256:a{64} image=foo key=[0-9a-f]{12}$'
exec sh -c 'grep -lxF " \"name\": \"foo\"," "$IMAGES"/????????????/record.json | xargs cat'
stdout '^ "from": "node:24@sha256:a{64}",$'
stdout '^ "digest": "node:24@sha256:a{64}",$'
stdout '^ "libc": "musl",$'
exec devvm build base
stdout '^==> building_image image=base key=[0-9a-f]{12}$'
exec sh -c 'rm "$STUB_DIR/build-libc"'
# A new VM from it records --from; once it exists, another --from is
# ignored with a warning, and nothing is built for it.
project web
exec devvm --from $PIN --network open
stdout '^==> creating_from image=base vm=devvm-web-[0-9a-f]{14}$'
! stdout building_image
vm_name WEB web
vm_state $WEB_dir/vm.json
stdout '^from=node:24@sha256:a{64}$'
# Its base has musl, and pi's releases are for glibc alone: tools add
# refuses pi before it builds anything.
stub_reset
! exec devvm tools add pi
stderr '^devvm: tool_glibc_only tool=pi$'
stub_calls
! stdout 'limactl (create|clone)'
stub_reset
exec devvm --from debian:13
stderr '^devvm: new_vm_flags_ignored flags=--from vm=devvm-web-[0-9a-f]{14}$'
! stdout building_image
stub_calls
! stdout 'limactl create|docker image'
exec devvm --from $PIN
! stderr new_vm_flags_ignored
cd $WORK
# An image only Docker has, offline: Docker's ID, recorded; docker save
# hands it to the build VM, whose build.sh reads it for -.
stub_reset
exec sh -c 'echo sha256:dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd > "$STUB_DIR/docker-image"'
exec devvm --from myapp:dev build base
! stderr from_cached
stdout '^==> exporting_docker from=myapp:dev$'
grep '^ "myapp:dev": "sha256:d{64}"' $DATA/cache/from-digests.json
stub_calls
stdout '^docker image inspect --format \{\{\.Id\}\} myapp:dev$'
stdout '^docker info$'
stdout '^docker save -o /\S*/tmp/devvm-oci\.[0-9]+/vm/image\.tar myapp:dev$'
stdout '^limactl shell --start=false --workdir / devvm-oci-build sudo bash -s -- /\S*/tmp/devvm-oci\.[0-9]+/oci/build\.sh /\S*/tmp/devvm-oci\.[0-9]+/oci /\S*/tmp/devvm-oci\.[0-9]+/vm - myapp:dev '
exec sh -c 'ls -t "$XDG_DATA_HOME"/devvm/logs/runs/*.log | head -1 | xargs cat'
stdout '^# \[1/15\] exporting_docker from=myapp:dev$'
stdout '^# \[15/15\] stopping vm=devvm-img-'
# The cache may go at any time: the base keeps its key, from the digest
# its record names, so it stays current, and a build offline keeps it.
rm $DATA/cache
exec devvm images
stdout '^base +myapp:dev +\S+ +[0-9a-f]{12} +current '
! stdout ' stale '
stub_reset
exec devvm --from myapp:dev build base
stderr '^devvm: from_cached_unreachable from=myapp:dev host=registry-1\.docker\.io$'
! stdout building_image
# Saved by name: an export that isn't the recorded image (the tag moved
# since) is refused, before the conversion.
stub_reset
exec sh -c 'echo sha256:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee > "$STUB_DIR/docker-saved"'
! exec devvm --from myapp:other build base
stderr '^devvm: docker_image_changed from=myapp:other$'
stub_calls
! stdout 'oci/build\.sh'
exec sh -c 'ls "$TMPDIR"'
! stdout .
exec sh -c 'rm "$STUB_DIR/docker-saved"'
# Docker not running for an image only it has: the recorded ID is kept,
# with a warning, then refused.
cp digests.json $DATA/cache/from-digests.json
exec sh -c ': > "$STUB_DIR/docker-down"'
! exec devvm --from myapp:third build base
stderr '^devvm: from_cached_unreachable from=myapp:third host=registry-1\.docker\.io$'
stderr '^devvm: docker_only from=myapp:third$'
exec sh -c 'rm "$STUB_DIR/docker-down"'
# Offline: a digest the registry gave before is kept, with a warning;
# with none, and Docker without the image, the lookup fails.
stub_reset
exec devvm --from node:24 build base
stderr '^devvm: from_cached_unreachable from=node:24 host=registry-1\.docker\.io$'
stub_calls
stdout ' sudo bash -s -- /\S*/tmp/devvm-oci\.[0-9]+/oci/build\.sh /\S*/tmp/devvm-oci\.[0-9]+/oci /\S*/vm node@sha256:a{64} node:24 '
! stdout 'docker save'
rm $STUB_DIR/docker-image
! exec devvm --from debian:13 build base
stderr '^devvm: from_unreachable from=debian:13 host=registry-1\.docker\.io$'
# A failed conversion says so, and the build VM and the temporary folder
# go.
stub_reset
exec sh -c ': > "$STUB_DIR/build-fails"'
! exec devvm rebuild --force --from $PIN base
stderr '^devvm: convert_failed from=node:24@sha256:a{64}$'
stub_calls
stdout '^limactl delete -f devvm-oci-build$'
! stdout '--name=devvm-img-'
exec sh -c 'ls "$TMPDIR"'
! stdout .
exec sh -c 'rm "$STUB_DIR/build-fails"'
# What the image's own code wrote is untrusted: a command line that could
# change Lima's config, a symlink to a host file, an unknown libc, or a
# disk that isn't raw ext4 (qcow2 can name a host file as its backing
# file) are refused, and base is never created from them.
stub_reset
exec sh -c 'printf "root=/dev/vda rw console=hvc0\"\ncopyToHost:\n- guest: /etc/hostname\n host: /tmp/x\n" > "$STUB_DIR/build-cmdline"'
! exec devvm rebuild --force --from $PIN base
stderr '^devvm: convert_bad_output file=cmdline from=node:24@sha256:a{64}$'
exec sh -c 'rm "$STUB_DIR/build-cmdline"; echo hostile > "$HOME/secret"; echo "disk.raw $HOME/secret" > "$STUB_DIR/build-symlinks"'
! exec devvm rebuild --force --from $PIN base
stderr '^devvm: convert_bad_output file=disk.raw from=node:24@sha256:a{64}$'
exec sh -c 'rm "$STUB_DIR/build-symlinks"; printf "gnu\nx\n" > "$STUB_DIR/build-libc"'
! exec devvm rebuild --force --from $PIN base
stderr '^devvm: convert_bad_output file=libc from=node:24@sha256:a{64}$'
exec sh -c 'rm "$STUB_DIR/build-libc"; : > "$STUB_DIR/build-qcow2"'
! exec devvm rebuild --force --from $PIN base
stderr '^devvm: convert_bad_output file=disk.raw from=node:24@sha256:a{64}$'
exec sh -c 'rm "$STUB_DIR/build-qcow2"'
stub_calls
! stdout '--name=devvm-img-'
exec cat $HOME/secret
stdout '^hostile$'
exec sh -c 'ls "$TMPDIR"'
! stdout .
# Ctrl+C during the conversion deletes the build VM and the temporary
# folder; nothing is left in Lima.
stub_reset
exec sh -c 'echo oci/build.sh > "$STUB_DIR/interrupt-on"; stub vms > "$WORK/before"'
! exec devvm rebuild --force --from $PIN base
! stderr convert_failed
stub_calls
stdout '^limactl delete -f devvm-oci-build$'
exec stub vms
cmp stdout $WORK/before
exec sh -c 'ls "$TMPDIR"'
! stdout .
# A gnu base records its glibc version, as the conversion read it. A
# shared tool whose image needs a newer glibc is refused, naming the tool
# and both versions, and no VM is made; a tool it runs on is given to the
# VM, which records the base's glibc.
stub_reset
rm $STUB_DIR/interrupt-on
env OLD=debian:9@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
exec sh -c 'echo 2.24 > "$STUB_DIR/build-glibc"; echo 2.28 > "$STUB_DIR/tools-glibc-node"; echo 2.17 > "$STUB_DIR/tools-glibc-go"'
project old
! exec devvm --from $OLD --network open --no-git-protect --tools node
stderr '^devvm: tool_needs_glibc has=2\.24 needs=2\.28 tool=node version=[0-9.]+$'
exec stub vms
! stdout devvm-old-
exec sh -c 'grep -lxF " \"from\": \"$OLD\"," "$IMAGES"/????????????/record.json | xargs cat'
stdout '^ "libc": "gnu",$'
stdout '^ "glibc": "2\.24",$'
exec sh -c 'cat "$XDG_DATA_HOME"/devvm/tools/node-*.erofs.json'
stdout '^ "glibc": "2\.28",$'
stub_reset
exec devvm --from $OLD --network open --no-git-protect --tools go
# Its tools build in a clone of devvm's own Ubuntu base, built above,
# never in the --from image's, as any VM may mount them; the base being
# built already, nothing says it's built first.
! stdout tools_need_own_base
exec sh -c 'for r in "$IMAGES"/????????????/record.json; do grep -qxF " \"from\": \"\"," "$r" && grep -qxF " \"name\": \"base\"," "$r" && basename "$(dirname "$r")"; done; true'
stdout '^[0-9a-f]{12}$'
cp stdout $WORK/ownbase
stub_calls
cp stdout $WORK/calls
exec sh -c 'grep -c "^limactl clone .* devvm-img-$(cat "$WORK/ownbase") devvm-tools-build$" "$WORK/calls"'
stdout '^1$'
vm_name OLD old
vm_state $OLD_dir/vm.json
stdout '^tools.made.glibc=2\.24$'
stdout '^tools.made.libc=gnu$'
stdout '^tools.names=go$'
# Adding the tool to the VM later is refused the same way.
! exec devvm tools add node
stderr '^devvm: tool_needs_glibc has=2\.24 needs=2\.28 tool=node version=[0-9.]+$'
vm_state $OLD_dir/vm.json
stdout '^tools.names=go$'
# Only devvm's own base builds gnu tools: one whose record says it came
# from a container image is refused, and no VM is made.
exec sh -c 'cp "$IMAGES/$(cat "$WORK/ownbase")/record.json" "$WORK/own-record.json"'
json_set $WORK/own-record.json from=evil/debian:12
exec sh -c 'cp "$WORK/own-record.json" "$IMAGES/$(cat "$WORK/ownbase")/record.json"'
env DEB9=debian:9@sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
project old2
! exec devvm --from $DEB9 --network open --no-git-protect --tools python
stderr '^devvm: tools_wrong_base key=[0-9a-f]{12}$'
exec stub vms
! stdout devvm-old2-
# With devvm's own base not built, the first gnu tools of a --from VM
# say so, then build it first. uv needs a newer glibc than the image
# has, so devvm stops after the build, before any VM, rather than
# replace itself with the VM's shell (which would lose this run's
# coverage).
exec sh -c 'rm "$IMAGES/$(cat "$WORK/ownbase")/record.json"; echo 2.28 > "$STUB_DIR/tools-glibc-uv"'
! exec devvm --from $DEB9 --network open --no-git-protect --tools python
stdout '^==> tools_need_own_base$'
stdout '^==> building_image image=base key=[0-9a-f]{12}$'
stderr '^devvm: tool_needs_glibc has=2\.24 needs=2\.28 tool=uv version=[0-9.]+$'
cd $WORK
-- digests.json --
{
"digests": {
"myapp:third": "sha256:dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd",
"node:24": "node@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
}