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

189 lines
7.9 KiB
Plaintext

# devvm build: base from Ubuntu's cloud image, a layer as a clone of its
# parent's image, each built once and recorded; what a failed or
# interrupted build leaves behind (a stopped VM to inspect, or nothing).
env IMAGES=$XDG_DATA_HOME/devvm/images
mkdir $XDG_CONFIG_HOME/devvm/layers
cp foo.sh $XDG_CONFIG_HOME/devvm/layers/foo.sh
cp bar.sh $XDG_CONFIG_HOME/devvm/layers/bar.sh
# base: Ubuntu's newest dated release, its signed checksums checked, pinned
# on this machine first; without host mounts, confined; its record says
# which image it came from. base.yaml goes on limactl create's input, from
# the binary: devvm writes none of its own files out.
! exists $IMAGES/ubuntu.json
exec devvm build base
stdout '^==> origin_pinned origin=release-20261016$'
stdout '^==> building_image image=base key=[0-9a-f]{12}$'
stdout '^base_build_time$'
stdout '^==> image_ready image=base$'
catg $IMAGES/ubuntu.json
stdout '^ "release": "release-20261016",$'
stdout '^ "digest": "sha256:[0-9a-f]{64}",$'
stub_calls
# Lima gets devvm's own copy of the image, named for the pin's digest.
stdout '^limactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} --set \.images = \[\{"location":"/\S*/data/devvm/images/ubuntu/[0-9a-f]{64}\.img","arch":"(aarch64|x86_64)","digest":"sha256:[0-9a-f]{64}"\}\] --cpus=4 --memory=8 --disk=100 -$'
cmp $STUB_DIR/create-template $DEVVM_REPO/assets/base.yaml
! exists $XDG_DATA_HOME/devvm/assets
stdout '^limactl edit --tty=false devvm-img-[0-9a-f]{12} .*--set \.portForwards = \[\{"guestIP":"127\.0\.0\.1"'
stdout '^limactl start --tty=false devvm-img-[0-9a-f]{12}$'
stdout '^limactl shell --start=false devvm-img-[0-9a-f]{12} bash -s$'
stdout '^limactl shell --start=false --workdir / devvm-img-[0-9a-f]{12} sync$'
stdout '^limactl stop devvm-img-[0-9a-f]{12}$'
# Its ssh port is devvm's, on every host, given up once it has started.
stdout '^limactl edit --tty=false devvm-img-[0-9a-f]{12} --set \.ssh\.localPort=[1-9][0-9]+ '
exists $RUN/build-ports
! exec sh -c 'ls -A "$RUN/build-ports" | grep .'
grep 'Essentials, and mise' $STUB_DIR/scripts
catg $IMAGES/????????????/record.json
stdout '^ "name": "base",$'
stdout '^ "chain": "base=[0-9a-f]{12}",$'
stdout '^ "digest": "file://.*/release-[0-9]{8}/ubuntu-26\.04-server-cloudimg-(arm64|amd64)\.img sha256:[0-9a-f]{64}",$'
stdout '^ "libc": "gnu",$'
stdout '^ "built": "\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ",$'
stdout '^ "made_by": "\S+"$'
# Each step is numbered in the run log, and the count is what ran.
catg $DATA/logs/runs/*.log
stdout '^# \[1/7\] creating_from_ubuntu vm=devvm-img-'
stdout '^# \[2/7\] configuring what=devvm-img-'
stdout '^# \[3/7\] starting what=devvm-img-'
stdout '^# \[4/7\] running_script script=apt\.sh what=devvm-img-'
stdout '^# \[5/7\] running_script script=base\.sh what=devvm-img-'
stdout '^# \[6/7\] running_script script=apt\.sh what=devvm-img-'
stdout '^# \[7/7\] stopping vm=devvm-img-'
! stdout '\[8/7\]'
# Its packages: a recording, sent no mirror (config.toml sets none), which
# gave back none, recorded under base's key.
exec tar -tf $STUB_DIR/packages-in.tar
cmp stdout want-recording
exists $DATA/packages/sets
exec sh -c 'ls "$XDG_DATA_HOME"/devvm/packages/sets'
stdout '^[0-9a-f]{12}\.json$'
# Built and recorded: reused, from the image pinned.
stub_reset
exec devvm build base
! stdout building_image
! stdout origin_pinned
stub_calls
! stdout 'create|clone|start'
# An image without a record is a failed build: deleted and built again.
# With -v, the run log's lines are streamed to stderr as well, numbered
# steps and commands, and the log still gets them.
exec sh -c 'rm "$IMAGES"/????????????/record.json'
exec devvm -v build base
stdout '^==> image_leftover image=base key=[0-9a-f]{12}$'
stderr '^# \[1/7\] creating_from_ubuntu vm=devvm-img-'
stderr '^\+ limactl create '
# Built again under the same key, it replays the set recorded.
exec tar -tf $STUB_DIR/packages-in.tar
cmp stdout want-replay
! stdout '^\+ limactl'
exec sh -c 'ls -t "$XDG_DATA_HOME"/devvm/logs/runs/*.log | head -1 | xargs cat'
stdout '^\+ limactl create '
stub_calls
stdout '^limactl delete -f devvm-img-[0-9a-f]{12}$'
catg $IMAGES/????????????/record.json
stdout '^ "name": "base",$'
# A layer is a clone of its parent's image, without host mounts, running
# the user's script; its record has its whole chain.
exec sh -c ': > "$STUB_LOG" && : > "$STUB_DIR/scripts"'
exec devvm build base+foo
stdout '^==> building_image image=foo key=[0-9a-f]{12}$'
! stdout 'image=base'
stub_calls
stdout '^limactl clone --tty=false --mount-none devvm-img-[0-9a-f]{12} devvm-img-[0-9a-f]{12}$'
! stdout 'limactl create'
grep '^echo foo$' $STUB_DIR/scripts
exec sh -c 'cat "$IMAGES"/????????????/record.json'
stdout '^ "chain": "base=[0-9a-f]{12} foo=[0-9a-f]{12}",$'
stdout -count=2 '^ "libc": "gnu",$'
# Names that aren't base or a layer are refused, before anything runs.
stub_reset
! exec devvm build foo+stray
stderr '^devvm: unknown_layer layer=stray layers=base bar desktop docker foo nix$'
! exec devvm build stray+node
stderr '^devvm: unknown_layer layer=stray layers=base bar desktop docker foo nix$'
! exec devvm build ''
stderr '^devvm: arg_blank command=devvm build$'
! exec devvm rebuild ../../x
stderr '^devvm: unknown_layer layer=\.\./\.\./x layers=base bar desktop docker foo nix$'
! exec devvm build
stderr '^devvm: arg_missing args=IMAGE command=devvm build$'
# An image holds base and layers alone: a shared tool's name is refused,
# naming it.
! exec devvm build node
stderr '^devvm: tool_not_layer tool=node$'
! exec devvm build foo+claude
stderr '^devvm: tool_not_layer tool=claude$'
! exec devvm rebuild node
stderr '^devvm: tool_not_layer tool=node$'
! stub_calls
# A failed script: the end of the run log, and the image's VM kept,
# stopped and without a record, for inspection in devvm's Lima home.
exec sh -c ': > "$STUB_DIR/shell-fails"'
! exec devvm build foo+bar
stderr '^--- log_end file=.*\.log$'
stderr '^\+ limactl shell --start=false --workdir / devvm-img-[0-9a-f]{12} sudo bash -s -- lists$'
stderr '^devvm: script_failed script=apt\.sh vm=devvm-img-[0-9a-f]{12}$'
! stdout unfinished_image
stub_calls
stdout '^limactl stop devvm-img-[0-9a-f]{12}$'
! stdout 'limactl delete'
exec sh -c 'stub vms | grep -c .; stub vms | grep -c " Stopped$"; ls "$IMAGES"/????????????/record.json | grep -c .'
stdout '^3\n3\n2\n$'
rm $STUB_DIR/shell-fails
# The next build deletes it first. While it builds, devvm images lists it
# as building, gc leaves it and images rm refuses it. Ctrl+C during a
# build deletes the unfinished image, never a finished one.
exec sh -c ': > "$STUB_LOG" && : > "$STUB_DIR/shell-hangs"'
! exec devvm build foo+bar &b&
wait_file $STUB_DIR/hanging
exec devvm images
stdout '^- +- +- +[0-9a-f]{12} +building +'
exec sh -c 'devvm images | awk "\$5 == \"building\" { print \$4 }" > building.key'
exec devvm gc --force
! stdout 'gc_unfinished|deleted_unfinished_build'
exec sh -c '! devvm images rm --force "$(cat building.key)"'
stderr '^devvm: image_building key=[0-9a-f]{12}$'
exec sh -c 'grep "^limactl delete" "$STUB_LOG" | grep -c "$(cat building.key)"'
stdout '^1$'
kill -INT b
wait b
stdout '^==> image_leftover image=foo\+bar key=[0-9a-f]{12}$'
stdout '^==> interrupted_image vm=devvm-img-[0-9a-f]{12}$'
! stderr script_failed
stub_calls
stdout -count=2 '^limactl delete -f devvm-img-[0-9a-f]{12}$'
exec sh -c 'stub vms | grep -c .; ls "$IMAGES"/????????????/record.json | grep -c .'
stdout '^2\n2\n$'
rm $STUB_DIR/shell-hangs
# A failed clone: nothing to inspect, so the partial instance is deleted.
exec sh -c ': > "$STUB_LOG" && : > "$STUB_DIR/clone-fails"'
! exec devvm build foo+bar
stderr '^devvm: vm_create_failed vm=devvm-img-[0-9a-f]{12}$'
stdout '^==> unfinished_image vm=devvm-img-[0-9a-f]{12}$'
stub_calls
stdout -count=1 '^limactl delete -f devvm-img-[0-9a-f]{12}$'
exec sh -c 'stub vms | grep -c .; ls "$IMAGES"/????????????/record.json | grep -c .'
stdout '^2\n2\n$'
rm $STUB_DIR/clone-fails
-- want-recording --
in/mirrors
-- want-replay --
in/Packages
-- foo.sh --
#!/bin/bash
echo foo
-- bar.sh --
#!/bin/bash
echo bar