mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
devvm is about VMs, and Docker's containers aren't VMs: Lima is the default backend and smolvm stays experimental. The backend architecture (Backend, Caps, Require, the registry, backendtest.Fake) stays, so another backend is an addition. Removed: - internal/backend/docker, its registry entry and Names/Experimental's docker half; devvm _docker-connect and _docker-ports (internal/cli/dockerssh.go); assets/docker/unpack.sh. - Test-build overrides DEVVM_DOCKER_KIND, DEVVM_DOCKER_PROC_SYS, DEVVM_LINUX_BUILD_URL/_SHA256, the registry.linuxURL/linuxSHA256 ldflags vars and the CLI tests' Linux-build archive (linux_release). - Interfaces only Docker implemented, with their callers: backend.ProxySocket/ProxySocketOf (the proxy's -listen-unix), DiskUser (ls's and size's disk-over warning, size's disk_used and --json disk_used_gib), Reporter (doctor), LeftoverLister and Leftover (gc --orphans' volumes, networks, containers and images), DockerLayerVM and VMSpec.DockerLayer, SSHTarget.ProxyCommand and vmssh.SSH.Proxy, vmssh.SSH.SessionArgs, CacheEntry.Name. - The docker layer's runtime on a backend that makes VMs for it: vm/dockerlayer.go, KeyDockerLayer, chooseNet's refusal (chooseNet returns a bool now), the refusals at start and devvm network on, ls's "(sysbox)" and --json docker_layer, size_disk_default_unused. - The proxy's relay mode (relay.go, -relay, -relay-to, -listen-unix). - paths.Dirs.Docker and paths.VM.Lifeline. - assets/guest/tools.sh's linked-folder branch; services.sh's DEVVM_LOOP, DEVVM_DOCKERD and DEVVM_SSHD=inetd. - Messages: every docker_* the backend used, docker_layer_runtime, net_docker_layer, net_off_docker_layer, committing_image, pulling_image, unpacking_tools, disk_over, size_disk_default_unused, gc_orphan_volume/_network/_container/_image, docker_connect_failed; gc_orphan_elsewhere reworded. - Tests: docker.txtar, the docker stub's engine (its --from half stays), the ssh stub's login-shell branch; e2e's --backend docker, --engine, the docker host VM and Docker Desktop runs. - Release: one GoReleaser pass, no Linux-build pin in the macOS builds, no Linux devvm in the Homebrew formula's libexec. Linux builds stay. - Docs: backends/docker.md and internals/docker.md, design.md's Docker notes, the Docker column of the feature table, and every page's mentions of the Docker backend, Docker Desktop as one, and Sysbox. Kept: the docker layer in Lima VMs, devcontainer docker-in-docker, --from with images only a local Docker has, Docker Hub references. State written by a Docker VM before this reads as an unknown backend (backend_unknown_vm). Co-Authored-By: Claude Opus 5.5 <[email protected]>
200 lines
8.6 KiB
Plaintext
200 lines
8.6 KiB
Plaintext
# What assets/guest/sync.sh sets up in a VM, its pieces run here: the prompt,
|
|
# what the proxy blocked, the merge of Claude Code's settings, and VS
|
|
# Code's settings; and assets/guest/tools.sh, which mounts the shared tools.
|
|
exec bash snippets.sh $DEVVM_REPO/assets/guest/sync.sh
|
|
|
|
# devvm reads devvm-tools' report after a failed setup, so the setup's
|
|
# first command removes an older report (from boot): a failure before
|
|
# devvm-tools runs isn't taken for an unmounted tool.
|
|
exec bash first-cmd.sh $DEVVM_REPO/assets/guest/sync.sh
|
|
stdout '^sudo rm -f /run/devvm/tools-unmounted$'
|
|
|
|
# The prompt starts with (devvm), after a theme that rebuilds PS1 before
|
|
# each prompt; with no theme, once.
|
|
exec bash prompt-test.sh
|
|
cmp stdout prompt.want
|
|
|
|
# Before each prompt: what the proxy blocked since the last one, and how
|
|
# to allow it. A new shell asks with no count and prints nothing; then the
|
|
# new block; then nothing new; then the proxy can't be reached (curl
|
|
# fails): nothing, and the count stays.
|
|
exec bash blocked-test.sh
|
|
cmp stdout blocked.want
|
|
|
|
# The VM's MCP servers follow the host's: removed ones go, copies are
|
|
# replaced whole (no real header of an older copy survives), the VM's own
|
|
# stay; the host's settings win but the VM keeps its per-folder state.
|
|
exec bash merge-test.sh
|
|
cmp stdout merge.want
|
|
|
|
# VS Code's settings in the VM: no port forwarding to the host, no git
|
|
# sign-in relay; its other settings kept. A file that isn't plain JSON is
|
|
# left as it is, and said.
|
|
env HOME=$WORK/vmhome
|
|
exec bash vsc.sh
|
|
exec jq -c . $HOME/.vscode-server/data/Machine/settings.json
|
|
stdout '^\{"remote\.autoForwardPorts":false,"git\.terminalAuthentication":false,"github\.gitAuthentication":false\}$'
|
|
cp vsc-mine.json $HOME/.vscode-server/data/Machine/settings.json
|
|
exec bash vsc.sh
|
|
exec jq -c . $HOME/.vscode-server/data/Machine/settings.json
|
|
stdout '^\{"editor\.fontSize":14,"remote\.autoForwardPorts":false,"git\.terminalAuthentication":false,"github\.gitAuthentication":false\}$'
|
|
cp vsc-comments.json $HOME/.vscode-server/data/Machine/settings.json
|
|
exec bash vsc.sh
|
|
stderr 'isn''t plain JSON'
|
|
cmp $HOME/.vscode-server/data/Machine/settings.json vsc-comments.json
|
|
|
|
# devvm-tools (assets/guest/tools.sh) tries every image in the VM's list:
|
|
# it mounts the ones it can, and says why for each it can't (missing from
|
|
# the share, a loop device or mount that fails), leaving no empty mount
|
|
# point of theirs; then it lists them in
|
|
# its report, a line each, and fails. With all of them there, it succeeds
|
|
# and leaves no report.
|
|
exec bash tools-test.sh $DEVVM_REPO/assets/guest/tools.sh
|
|
cmp stdout tools.want
|
|
|
|
# The VM's links in /etc/hosts: a marked block after the file's own lines,
|
|
# replaced whole when they change, and gone without links. The file is
|
|
# written in place, never renamed over, and not at all when nothing
|
|
# changed.
|
|
exec bash hosts-test.sh
|
|
cmp stdout hosts.want
|
|
|
|
-- snippets.sh --
|
|
# Each piece of sync.sh ($1) into a file of its own.
|
|
awk '/^cat > ~\/.bashrc.d\/devvm-prompt.sh/ { on = 1; next } on && /^EOF$/ { exit } on' "$1" > prompt.sh
|
|
awk '/^_devvm_blocked\(\) \{/ { on = 1 } on && /^EOF$/ { exit } on' "$1" > blocked.sh
|
|
awk '/^merge_claude_json\(\) \{/ { on = 1 } on { print } on && /^\}$/ { exit }' "$1" > merge.sh
|
|
awk '/^vsc=~\/.vscode-server/ { on = 1 } on && /^# Codex has no env-var/ { exit } on' "$1" > vsc.sh
|
|
awk '/^link_hosts\(\) \{/ { on = 1 } on { print } on && /^\}$/ { exit }' "$1" > hosts.sh
|
|
for f in prompt.sh blocked.sh merge.sh vsc.sh hosts.sh; do [[ -s $f ]] || { echo "no $f in $1" >&2; exit 1; }; done
|
|
-- hosts-test.sh --
|
|
# sudo runs the command and says when it writes; hosts.link is the same
|
|
# file as hosts, which a write in place keeps.
|
|
exec 3>&1
|
|
sudo() { echo "(write)" >&3; "$@"; }
|
|
. hosts.sh
|
|
printf '127.0.0.1 localhost\n127.0.1.1 web\n' > hosts
|
|
ln hosts hosts.link
|
|
printf '127.77.0.2 db db.devvm.internal\n' > links
|
|
link_hosts hosts links; cat hosts.link
|
|
link_hosts hosts links; echo '-- again'
|
|
printf '127.77.0.2 db db.devvm.internal\n127.77.0.3 api api.devvm.internal\n' > links
|
|
link_hosts hosts links; cat hosts.link
|
|
: > links
|
|
link_hosts hosts links; cat hosts.link
|
|
-- hosts.want --
|
|
(write)
|
|
127.0.0.1 localhost
|
|
127.0.1.1 web
|
|
# devvm links begin
|
|
127.77.0.2 db db.devvm.internal
|
|
# devvm links end
|
|
-- again
|
|
(write)
|
|
127.0.0.1 localhost
|
|
127.0.1.1 web
|
|
# devvm links begin
|
|
127.77.0.2 db db.devvm.internal
|
|
127.77.0.3 api api.devvm.internal
|
|
# devvm links end
|
|
(write)
|
|
127.0.0.1 localhost
|
|
127.0.1.1 web
|
|
-- first-cmd.sh --
|
|
# The first command of a script ($1) after its set line, past comments.
|
|
awk 'on && !/^#/ { print; exit } /^set -euo pipefail$/ { on = 1 }' "$1"
|
|
-- prompt-test.sh --
|
|
# Two prompts, the way bash runs PROMPT_COMMAND (an array of commands on
|
|
# bash 5.1+, else a string).
|
|
prompts='for i in 1 2; do for c in "${PROMPT_COMMAND[@]}"; do eval "$c"; done; done; printf "[%s]\n" "$PS1"'
|
|
bash -c 'theme() { PS1="03:26:21 cj@vm \$ "; }; PROMPT_COMMAND=theme; . "$1"; '"$prompts" _ prompt.sh
|
|
bash -c 'PS1="\u@\h:\w\$ "; unset PROMPT_COMMAND; . "$1"; '"$prompts" _ prompt.sh
|
|
-- prompt.want --
|
|
[(devvm) 03:26:21 cj@vm $ ]
|
|
[(devvm) \u@\h:\w$ ]
|
|
-- blocked-test.sh --
|
|
# The proxy: each call answers with the next reply, and says which
|
|
# "after" it was asked for.
|
|
replies=("3" $'5\ndevvm: blocked registry.example.com:443 (not in the allowlist)\nTo allow, run this on the host:\ndevvm network allow registry.example.com' "5")
|
|
i=0
|
|
curl() { local url=${!#}; echo "after=${url##*after=}" >&2; [[ $i -lt ${#replies[@]} ]] || return 7; printf "%s\n" "${replies[i]}"; }
|
|
. blocked.sh
|
|
for c in 1 2 3 4; do _devvm_blocked 2>&1; i=$((i + 1)); done
|
|
-- blocked.want --
|
|
after=
|
|
after=3
|
|
devvm: blocked registry.example.com:443 (not in the allowlist)
|
|
To allow, run this on the host:
|
|
devvm network allow registry.example.com
|
|
after=5
|
|
after=5
|
|
-- merge-test.sh --
|
|
. merge.sh
|
|
v=vm.json h=host.json c=state/copied.json
|
|
# An earlier copy (network policy off then): a real header; plus a server
|
|
# added in the VM.
|
|
echo '{"theme":"light","projects":{"/p":{"trust":true}},"mcpServers":{
|
|
"gh":{"url":"https://x","headers":{"Authorization":"REAL","X-Old":"REAL2"}},
|
|
"gone":{"command":"old"},"mine":{"command":"vm-only"}}}' > "$v"
|
|
mkdir -p state; echo '["gh","gone"]' > "$c"
|
|
echo '{"theme":"dark","projects":{"/h":{}},"mcpServers":{"gh":{"url":"https://x","headers":{"Authorization":"PLACEHOLDER"}},"new":{"command":"n"}}}' > "$h"
|
|
merge_claude_json "$v" "$h" "$c"
|
|
jq -c '{theme, projects, mcpServers}' "$v"
|
|
jq -c . "$c"
|
|
# The first time: no list yet, no VM file.
|
|
rm -f "$v" "$c"
|
|
merge_claude_json "$v" "$h" "$c"
|
|
jq -c '.mcpServers | keys' "$v"
|
|
-- merge.want --
|
|
{"theme":"dark","projects":{"/p":{"trust":true}},"mcpServers":{"mine":{"command":"vm-only"},"gh":{"url":"https://x","headers":{"Authorization":"PLACEHOLDER"}},"new":{"command":"n"}}}
|
|
["gh","new"]
|
|
["gh","new"]
|
|
-- tools-test.sh --
|
|
# tools.sh ($1) with its folders under t/, and the commands it mounts with
|
|
# stubbed: losetup fails for bad-loop.erofs, and mount for bad-mount.erofs (at mnt/1).
|
|
export d=$PWD/t
|
|
mkdir -p "$d/share" "$d/etc"
|
|
touch "$d/share/node-1-k.erofs" "$d/share/py-1-k.erofs" "$d/share/bad-loop.erofs" "$d/share/bad-mount.erofs"
|
|
from='share=/mnt/devvm-tools root=/opt/devvm/tools list=/etc/devvm/tools report=/run/devvm/tools-unmounted'
|
|
grep -qx "$from" "$1" || { echo "no folders line in $1" >&2; exit 1; }
|
|
sed "s|^$from\$|share=$d/share root=$d/opt list=$d/etc/tools report=$d/run/tools-unmounted|" "$1" > tools.sh
|
|
mountpoint() { return 1; }
|
|
losetup() { case $* in *bad-loop*) return 1 ;; -d*) echo "losetup $*" ;; *) echo /dev/loop0 ;; esac; }
|
|
mount() { t=${*: -1}; [[ $t != */mnt/1 ]] || return 32; echo "mount ${t#"$d"/}"; }
|
|
findmnt() { :; }
|
|
export -f mountpoint losetup mount findmnt
|
|
printf '%s\n' "node-1-k.erofs node 1" "gone-1-k.erofs gone 1" "bad-loop.erofs loop 1" \
|
|
"bad-mount.erofs mnt 1" "py-1-k.erofs python 1" > "$d/etc/tools"
|
|
bash tools.sh 2>&1; echo "exit $?"
|
|
sed 's/^/report: /' "$d/run/tools-unmounted"
|
|
cd "$d/opt" && for m in */1; do [[ ! -e $m ]] || echo "there $m"; done
|
|
printf '%s\n' "node-1-k.erofs node 1" "py-1-k.erofs python 1" > "$d/etc/tools"
|
|
bash ../../tools.sh 2>&1; echo "exit $?"
|
|
[[ -e $d/run/tools-unmounted ]] || echo "no report"
|
|
-- tools.want --
|
|
mount opt/node/1
|
|
devvm-tools: gone-1-k.erofs is missing from the share
|
|
devvm-tools: can't mount bad-loop.erofs
|
|
devvm-tools: can't mount bad-mount.erofs
|
|
losetup -d /dev/loop0
|
|
mount opt/python/1
|
|
devvm-tools: unmounted gone-1-k.erofs
|
|
devvm-tools: unmounted bad-loop.erofs
|
|
devvm-tools: unmounted bad-mount.erofs
|
|
exit 1
|
|
report: gone-1-k.erofs
|
|
report: bad-loop.erofs
|
|
report: bad-mount.erofs
|
|
there node/1
|
|
there python/1
|
|
mount opt/node/1
|
|
mount opt/python/1
|
|
exit 0
|
|
no report
|
|
-- vsc-mine.json --
|
|
{"editor.fontSize": 14, "remote.autoForwardPorts": true}
|
|
-- vsc-comments.json --
|
|
{
|
|
// a comment
|
|
}
|