Proxmox nodes: install in an LXC container instead of Docker on the node

Run on a Proxmox VE node (pct and /etc/pve present), the installers now
default to INSTALL_MODE=lxc: create or reuse (by tag netmon-hub /
netmon-probe) an unprivileged Debian LXC on vmbr0 with nesting and onboot,
push the installer into it (rebuilt from its own functions) and run it there
in native mode. LXC_* variables override ID, storage, template storage,
bridge, IP and size. Docker on a node now needs an explicit
INSTALL_MODE=docker and prints a warning; an earlier Docker install is
pointed out with removal steps.

Ping setup inside an unprivileged container stays within the mapped group
range, which the kernel requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-04 18:28:21 -08:00
parent edeb77f833
commit a17f2b502c
7 changed files with 382 additions and 38 deletions

View file

@ -58,3 +58,55 @@ def test_choose_mode(tmp_path):
r = run('id() { echo 1000; }; INSTALL_MODE=native; choose_mode')
assert r.returncode != 0 and "run as root" in r.stderr
assert run('INSTALL_MODE=bogus; choose_mode').returncode != 0
def test_proxmox_node_creates_container_and_installs_inside(tmp_path):
"""On a Proxmox node (pct present) the installer makes an LXC and runs itself inside it."""
fake = tmp_path / "bin"
fake.mkdir()
log = tmp_path / "calls.log"
pushed = tmp_path / "pushed.sh"
def stub(name, body):
(fake / name).write_text(f'#!/bin/bash\necho "{name} $*" >> {log}\n{body}')
(fake / name).chmod(0o755)
stub("pct", f'''case $1 in
list) printf 'VMID Status Lock Name\\n100 running other\\n'; [ -f {pushed}.created ] && echo "105 running netmon-hub" ; true ;;
create) touch {pushed}.created ;;
config) [ "$2" = 100 ] && echo "tags: web" ; [ "$2" = 105 ] && printf 'hostname: netmon-hub\\ntags: netmon-hub\\n' ; true ;;
status) echo "status: stopped" ;;
push) cp "$3" {pushed} ;;
exec) shift 3; [ "$1" = hostname ] && echo "192.168.68.50 " ; true ;;
esac''')
stub("pvesh", 'echo 105')
stub("pveam", '[ "$1" = available ] && printf "system debian-12-standard_12.7-1_amd64.tar.zst\\nsystem debian-12-standard_12.12-1_amd64.tar.zst\\n"; true')
stub("pvesm", 'printf "Name Type Status Total\\nlocal dir active 1\\nlocal-lvm lvmthin active 2\\n"')
stub("sleep", "true")
pve = tmp_path / "pve"
pve.mkdir()
env = {"PATH": f"{fake}:{os.environ['PATH']}", "NETMON_PVE_DIR": str(pve), "INSTALL_DIR": str(tmp_path / "opt"), "HOST_PORT": "8000"}
r = subprocess.run(["bash", "install.sh"], cwd=ROOT, capture_output=True, text=True, env={**os.environ, **env}, timeout=60,
input="")
if os.geteuid() != 0:
assert r.returncode != 0 and "run the installer as root" in r.stderr
return
assert r.returncode == 0, r.stdout + r.stderr
calls = log.read_text()
assert "pveam download local debian-12-standard_12.12-1_amd64.tar.zst" in calls
create = next(line for line in calls.splitlines() if line.startswith("pct create"))
for part in ("pct create 105 local:vztmpl/debian-12-standard_12.12-1_amd64.tar.zst", "--hostname netmon-hub",
"--rootfs local-lvm:4", "bridge=vmbr0,ip=dhcp", "--unprivileged 1", "--features nesting=1",
"--onboot 1", "--tags netmon-hub"):
assert part in create, part
assert "pct start 105" in calls
inner = next(line for line in calls.splitlines() if "netmon-install.sh" in line and "exec 105 -- env" in line)
assert "INSTALL_MODE=native" in inner and "HOST_PORT=8000" in inner
assert "http://192.168.68.50:8000" in r.stdout
# The pushed script is a complete installer for the same role.
text = pushed.read_text()
assert "NETMON_ROLE=hub" in text and text.rstrip().endswith('main "$@"')
assert subprocess.run(["bash", "-n", str(pushed)]).returncode == 0
# A second run finds the tagged container instead of creating another.
log.write_text("")
r = subprocess.run(["bash", "install.sh"], cwd=ROOT, capture_output=True, text=True, env={**os.environ, **env}, timeout=60)
assert r.returncode == 0 and "reusing container 105" in r.stdout and "pct create" not in log.read_text()