mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 14:33:17 -10:00
The command line names the four network tiers. --network TIER (open,
internet, allowlist or none) chooses a new VM's tier, checked before
anything runs (arg_not_choice). devvm network open|internet|allowlist|none
gives the folder's VM a tier through Net.SetTier, and devvm network -g
takes the tiers and ask. config.toml's and settings.json's network is ask
or a tier (settings.NetworkChoices, checked against netpolicy.TierNames
by a test, since settings can't import netpolicy).
The question on creation is Proxy.Choose(vm): net_about says what each
tier reaches, net_ask asks for one (Answer, AnsweredBy("--network")),
Enter or a refusal gives allowlist, and an answer that isn't a tier is
warned of (net_tier_unknown) and asked again. devvm setup's picker
offers ask and the four tiers (network_default_open, _internet,
_allowlist, _none). On an existing VM, --network is ignored with the
devvm network TIER command that changes it.
devvm network --json: policy is the tier or unenforced, and each policy
file whose denies alone apply (internet and none) has denies_only: true,
as the text output's "(denies only)", so a script can tell a file's
denies from all of its rules without knowing the tier rules.
Messages reworded: net_tier_backend (--network open), net_open_policy
(devvm network allowlist), net_about, net_ask, network_default*,
net_default_failed, network_failed, setting_already's and
widen_parent_vm*'s descriptions. safety/network's "Choosing a tier"
replaces its on/off section; docs, the cli skill, testscripts and e2e
use the new forms, and e2e's internet and none checks go through devvm
network.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
295 lines
14 KiB
Plaintext
295 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.
|
|
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$'
|
|
! stdout oci_waiting
|
|
stub_calls
|
|
! stdout '^docker'
|
|
stdout '^limactl create --tty=false --mount-none --name=devvm-oci-build --set \.images = \[\{"location":"file://.*/release-[0-9]{8}/ubuntu-26\.04-server-cloudimg-(arm64|amd64)\.img","arch":"(aarch64|x86_64)","digest":"sha256:[0-9a-f]{64}"\}\] --set \.mounts = \[\{"location":"/\S*/tmp/devvm-oci\.[0-9]+/vm","writable":true\},\{"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 --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 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 vm=devvm-oci-build$'
|
|
stdout '^# \[3/14\] starting vm=devvm-oci-build$'
|
|
stdout '^# \[4/14\] converting from=node:24@sha256:a{64}$'
|
|
stdout '^# \[5/14\] deleting vm=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}$'
|
|
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 --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"
|
|
}
|
|
}
|