mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
Linux build VMs' ssh ports were Lima's own pick, outside the claims lock, so another VM's forwarder could take one before Lima bound it. Lima's start now gets every build VM's port from ports.Allocator.Build on macOS and Linux alike, and sets it with its one edit. - start.go: the l.OS == "darwin" condition goes. - build.go, tools.go: cloneEdits goes; a build VM's start always edits its new ssh port, so the configure step is always counted. - ports.Allocator.Build holds a file lock on run/build-ports/<name> (platform.LockFile) until release, so the kernel lets go of it when devvm ends, killed or not. free, under the claims lock, first deletes (clearStale) the records no process holds that are over 15 minutes old (staleAfter: longer than Lima's 10 minutes of waiting for ssh, which a killed devvm's limactl start may still spend binding it). Tests: TestBuild (a stale record kept while young, then cleared; a held one kept however old), TestStartBuildSSHPort on darwin and linux, TestStartConfined's Linux builds, TestBuildImageLayer, TestBuildTools; TestCloneEdits goes. build.txtar checks the build's port edit and that its record is gone; tools.txtar's steps are one count on both systems; layout.txtar lists run/build-ports on Linux. The limactl stub needed no change: it applies .ssh.localPort on every host, and the contract's scenario already starts builds with a port. Docs: internals/design (reserved ports; the build VM's ssh port lead is now confirmed, fixed), internals/overview, using/space. Co-Authored-By: Claude Opus 5.5 <[email protected]>
188 lines
7.8 KiB
Plaintext
188 lines
7.8 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
|
|
stdout '^limactl create --tty=false --mount-none --name=devvm-img-[0-9a-f]{12} --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}"\}\] --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 devvm-img-[0-9a-f]{12} bash -s$'
|
|
stdout '^limactl shell --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 vm=devvm-img-'
|
|
stdout '^# \[3/7\] starting vm=devvm-img-'
|
|
stdout '^# \[4/7\] running_script script=apt\.sh vm=devvm-img-'
|
|
stdout '^# \[5/7\] running_script script=base\.sh vm=devvm-img-'
|
|
stdout '^# \[6/7\] running_script script=apt\.sh vm=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 --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
|