mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
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]>
103 lines
5.1 KiB
Plaintext
103 lines
5.1 KiB
Plaintext
# devvm 0.1.0's state (testdata/v0.1.0/GOOS, which 0.1.0 itself made:
|
|
# see fixture_v010.txtar) with today's store of Ubuntu's cloud images.
|
|
# 0.1.0 gave Lima the pinned image's address, so its image is in Lima's
|
|
# download cache alone, under the SHA-256 of that address, which its
|
|
# base's record keeps. Today's devvm looks there first, under that same
|
|
# name, and takes the image only once it checks out against the pin:
|
|
# the pin's digest is Ubuntu's real image's, which no test holds, so here
|
|
# it finds 0.1.0's entry, refuses its stand-in and leaves it as it was.
|
|
# With devvm's own copy of the pinned image, base builds from it, and
|
|
# devvm gc --caches keeps that copy, frees Lima's entry for it, which
|
|
# 0.1.0's record names, and devvm's own copies, a stopped download's and
|
|
# a killed import's, that nothing names. It keeps Lima's entries that no
|
|
# record names, which may be the user's own Lima's.
|
|
[!darwin] [!linux] skip 'a fixture for macOS and Linux only'
|
|
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
|
|
mkdir $HOME/src/db $HOME/src/app $HOME/src/web $HOME/src/scratch
|
|
cd $HOME/src/app
|
|
exec git init -q -b main
|
|
exec git commit -q --allow-empty -m one
|
|
cd $HOME/src/web
|
|
exec git init -q -b main
|
|
exec git commit -q --allow-empty -m one
|
|
cd $HOME/src/scratch
|
|
exec git init -q
|
|
cd $HOME
|
|
fixture v0.1.0
|
|
[darwin] env LIMACACHE=$HOME/Library/Caches/lima/download/by-url-sha256
|
|
[linux] env LIMACACHE=$HOME/.cache/lima/download/by-url-sha256
|
|
env OWN=$DATA/images/ubuntu
|
|
|
|
# The address 0.1.0 gave Lima and the digest it pinned, as its base's
|
|
# record keeps them, and Lima's entry for that address.
|
|
exec sh -c 'sed -n "s/^ \"digest\": \"\([^ ]*\) sha256:\([0-9a-f]*\)\",$/\1/p" "$DATA"/images/*/record.json'
|
|
stdout '^file://\S+/release-20261016/ubuntu-26\.04-server-cloudimg-(arm64|amd64)\.img\n$'
|
|
cp stdout $WORK/url
|
|
exec sh -c 'sed -n "s/^ \"digest\": \"[^ ]* sha256:\([0-9a-f]*\)\",$/\1/p" "$DATA"/images/*/record.json'
|
|
stdout '^[0-9a-f]{64}\n$'
|
|
cp stdout $WORK/sum
|
|
exec sh -c 'grep -q "\"digest\": \"sha256:$(cat "$WORK/sum")\"" "$DATA/images/ubuntu.json"'
|
|
exec sh $WORK/entry.sh $WORK/url
|
|
cp stdout $WORK/entry
|
|
|
|
# Without devvm's own copy: 0.1.0's entry is found and checked, never
|
|
# changed, and as it isn't the pin's image, base downloads it, which
|
|
# finds the release gone here (the sandbox's release has no image).
|
|
exec sh -c 'rm -f "$OWN"/*.img'
|
|
! exec devvm build base
|
|
stderr '^devvm: ubuntu_release_gone release=release-20261016 url=file://'
|
|
exec sh -c 'grep -h "not taking Ubuntu.s cloud image from Lima.s cache ($(cat "$WORK/entry")/data)" "$DATA"/logs/runs/*.log'
|
|
stdout 'its SHA-256 is [0-9a-f]{64}, not the pin.s'
|
|
exec sh -c 'cmp "$(cat "$WORK/entry")/data" "$WORK/standin"'
|
|
exec sh -c 'ls "$OWN"'
|
|
! stdout .
|
|
|
|
# With devvm's own copy, as its download leaves it: base builds from it,
|
|
# Lima given that file and the pin's digest.
|
|
exec sh -c 'cp "$WORK/standin" "$OWN/$(cat "$WORK/sum").img"'
|
|
stub_reset
|
|
exec devvm build base
|
|
stdout '^==> image_ready image=base$'
|
|
stub_calls
|
|
stdout '^limactl create .*"location":"\S*/data/devvm/images/ubuntu/[0-9a-f]{64}\.img","arch":"(aarch64|x86_64)","digest":"sha256:[0-9a-f]{64}"'
|
|
exec sh -c 'grep -c "\"location\":\"[^\"]*/images/ubuntu/$(cat "$WORK/sum")\.img\"" "$STUB_LOG"'
|
|
! stdout '^0$'
|
|
|
|
# devvm gc --caches: devvm's own copy of the pinned image stays; Lima's
|
|
# entry for it goes now devvm has its own, as Lima's own templates don't
|
|
# name it; an older release in Lima's cache that no record names stays;
|
|
# devvm's own copies no record or pin names go, a stopped download and a
|
|
# killed import, each unchanged for an hour.
|
|
mkdir $WORK/templates/_images
|
|
cp $WORK/template.yaml $WORK/templates/_images/ubuntu.yaml
|
|
env DEVVM_LIMA_TEMPLATES=$WORK/templates
|
|
exec sh -c 'u=$(cat "$WORK/url"); printf %s "${u%/release-*}/release-20250101/${u##*/}" >"$WORK/old-url"'
|
|
exec sh $WORK/entry.sh $WORK/old-url
|
|
cp stdout $WORK/old-entry
|
|
exec sh -c 'cd "$OWN" && for f in $(printf "a%.0s" $(seq 64)).img $(printf "b%.0s" $(seq 64)).img.part $(printf "c%.0s" $(seq 64)).img.import; do echo x >"$f"; done'
|
|
exec sh -c 'touch -t 202001010000 "$OWN"/aaaa*.img "$OWN"/bbbb*.img.part "$OWN"/cccc*.img.import "$(cat "$WORK/entry")" "$(cat "$WORK/old-entry")"'
|
|
exec devvm gc --caches --force
|
|
! stderr 'unreadable|corrupt|failed'
|
|
exec sh -c 'test "$(ls "$OWN")" = "$(cat "$WORK/sum").img"'
|
|
exec sh -c 'test ! -e "$(cat "$WORK/entry")" && test -e "$(cat "$WORK/old-entry")"'
|
|
|
|
-- template.yaml --
|
|
# One of Lima's own templates: an image of Ubuntu's devvm never pins here.
|
|
images:
|
|
- location: "https://cloud-images.ubuntu.com/releases/resolute/release-20200101/ubuntu-26.04-server-cloudimg-arm64.img"
|
|
arch: "aarch64"
|
|
|
|
-- entry.sh --
|
|
# entry.sh URLFILE: makes Lima's download cache's entry for the address
|
|
# in URLFILE, as Lima keeps one (by-url-sha256/<SHA-256 of the address>,
|
|
# with url and data), its data a stand-in, and prints its folder.
|
|
set -e
|
|
url=$(cat "$1")
|
|
name=$(printf %s "$url" | { sha256sum 2>/dev/null || shasum -a 256; } | cut -c1-64)
|
|
mkdir -p "$LIMACACHE/$name"
|
|
printf %s "$url" >"$LIMACACHE/$name/url"
|
|
cp "$WORK/standin" "$LIMACACHE/$name/data"
|
|
printf %s "$LIMACACHE/$name"
|
|
-- standin --
|
|
a stand-in for Ubuntu's cloud image
|