mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
devvm is one file: assets/ (base.yaml, layers/, features/, shared-tools/, guest/, oci/, smolvm/) is embedded as assets.FS, which cli passes to every constructor; backends, the builder, the shared tools, the proxy and Ubuntu's key check read it as an fs.FS. Scripts reach VMs on stdin (backend.Script carries their contents). What needs a path (limactl create's base.yaml, oci/ mounted into the conversion VM, the proxies' policy files) is written out to ~/.local/share/devvm/assets/<hash>, atomically, files 600 and folders 700; devvm gc deletes older copies no VM's proxy was started with (gc_assets, deleted_assets). Release archives hold the binary with README.md, CHANGELOG.md and LICENSE, and the formula installs the binary alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
200 lines
9.5 KiB
Plaintext
200 lines
9.5 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 DEVVM_MESSAGES=names
|
|
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 out in its data 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 and the conversion lock go once base has started.
|
|
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 '^gpgv --keyring '
|
|
stdout '^limactl create --tty=false --mount-none --name=devvm-oci-build --set \.images = \[\{"location":"file://.*/release-20260101/ubuntu-26\.04-server-cloudimg-(arm64|amd64)\.img","arch":"(aarch64|x86_64)","digest":"sha256:(1{64}|2{64})"\}\] --set \.mounts = \[\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm","writable":true\},\{"location":"/\S*/oci","writable":false\}\] --memory=[0-9.]+ /\S*/base\.yaml$'
|
|
stdout '^limactl start --tty=false devvm-oci-build$'
|
|
stdout '^limactl shell --workdir / devvm-oci-build sudo bash /\S*/data/devvm/assets/[0-9a-f]{16}/oci/build\.sh /\S*/data/devvm/assets/[0-9a-f]{16}/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"\}\}\] --memory=[0-9.]+ /\S*/base\.yaml$'
|
|
stdout '^limactl shell devvm-img-[0-9a-f]{12} bash -s$'
|
|
exec sh -c 'ls "$TMPDIR"'
|
|
! stdout .
|
|
! exists $LOCK
|
|
# Its record: what it came from, and musl from the image.
|
|
exec sh -c 'cat "$IMAGES"/*'
|
|
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.
|
|
exec sh -c 'cat "$XDG_DATA_HOME"/devvm/logs/runs/*.log'
|
|
stdout '^# \[1/10\] creating_from_ubuntu vm=devvm-oci-build$'
|
|
stdout '^# \[2/10\] configuring vm=devvm-oci-build$'
|
|
stdout '^# \[3/10\] starting vm=devvm-oci-build$'
|
|
stdout '^# \[4/10\] converting from=node:24@sha256:a{64}$'
|
|
stdout '^# \[5/10\] deleting vm=devvm-oci-build$'
|
|
stdout '^# \[6/10\] creating vm=devvm-img-'
|
|
stdout '^# \[10/10\] stopping vm=devvm-img-'
|
|
! stdout '\[11/10\]'
|
|
|
|
# Built: reused, without a lookup; a layer on it records where its base
|
|
# came from. Ubuntu's base is another image.
|
|
exec sh -c ': > "$STUB_LOG"; mkdir -p "$XDG_CONFIG_HOME/devvm/layers"; printf "#!/bin/bash\necho foo\n" > "$XDG_CONFIG_HOME/devvm/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 -l "^name=foo$" "$IMAGES"/* | 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.
|
|
mkdir $WORK/web
|
|
cd $WORK/web
|
|
exec devvm --from $PIN --no-network-policy base
|
|
stdout '^==> creating_from image=base vm=devvm-web-[0-9a-f]{14}$'
|
|
! stdout building_image
|
|
exec sh -c 'cat "$XDG_DATA_HOME"/devvm/vms/devvm-web-*'
|
|
stdout '^from=node:24@sha256:a{64}$'
|
|
exec sh -c ': > "$STUB_LOG"'
|
|
exec devvm --from debian:13
|
|
stderr '^devvm: from_ignored vm=devvm-web-[0-9a-f]{14}$'
|
|
! stdout building_image
|
|
stub_calls
|
|
! stdout 'limactl create|docker'
|
|
exec devvm --from $PIN
|
|
! stderr from_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 -.
|
|
exec sh -c ': > "$STUB_LOG"; 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}$' $IMAGES/from-digests
|
|
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 --workdir / devvm-oci-build sudo bash \S*/assets/[0-9a-f]{16}/oci/build\.sh \S*/assets/[0-9a-f]{16}/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/11\] exporting_docker from=myapp:dev$'
|
|
stdout '^# \[11/11\] stopping vm=devvm-img-'
|
|
! exists $LOCK
|
|
|
|
# Saved by name: an export that isn't the recorded image (the tag moved
|
|
# since) is refused, before the conversion.
|
|
exec sh -c ': > "$STUB_LOG"; 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 .
|
|
! exists $LOCK
|
|
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 $IMAGES/from-digests
|
|
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.
|
|
exec sh -c ': > "$STUB_LOG"'
|
|
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*/assets/[0-9a-f]{16}/oci/build\.sh \S*/assets/[0-9a-f]{16}/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, the temporary folder and
|
|
# the lock go.
|
|
exec sh -c ': > "$STUB_LOG"; : > "$STUB_DIR/build-fails"'
|
|
! exec devvm --from $PIN rebuild 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 .
|
|
! exists $LOCK
|
|
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.
|
|
exec sh -c ': > "$STUB_LOG"; printf "root=/dev/vda rw console=hvc0\"\ncopyToHost:\n- guest: /etc/hostname\n host: /tmp/x\n" > "$STUB_DIR/build-cmdline"'
|
|
! exec devvm --from $PIN rebuild 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 --from $PIN rebuild 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 --from $PIN rebuild 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 --from $PIN rebuild 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.
|
|
exec sh -c ': > "$STUB_LOG"; echo oci/build.sh > "$STUB_DIR/interrupt-on"; cp "$STUB_DIR/instances" "$WORK/before"'
|
|
! exec devvm --from $PIN rebuild base
|
|
! stderr convert_failed
|
|
stub_calls
|
|
stdout '^limactl delete -f devvm-oci-build$'
|
|
cmp $STUB_DIR/instances $WORK/before
|
|
exec sh -c 'ls "$TMPDIR"'
|
|
! stdout .
|
|
! exists $LOCK
|
|
|
|
-- digests --
|
|
myapp:third=sha256:dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
|
|
node:24=node@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|