A template overlay (templates/postgres) adds DEPENDS="postgresql", DB_* settings with a random password, an install that creates the user and database on the Core's PostgreSQL (safe to re-run), an uninstall that drops them, and a Python example that counts visits. Tested with a throwaway app: deploy, redeploy and a reboot of the Core keep the data, remove drops the database and user. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8.9 KiB
Testing
Manual checks for coreapp-dev. The scripts call sudo, pacman/yay,
systemctl and virsh, so they change the real system even when HOME is
a temporary folder. Run these on a machine or VM you don't mind changing.
Static checks
cd ~/Projects/coreapp-dev
for f in install.sh update.sh uninstall.sh bin/coreapp-vm bin/coreapp libvirt/network-hook.sh; do bash -n "$f"; done
shellcheck -x install.sh update.sh uninstall.sh bin/coreapp-vm bin/coreapp libvirt/network-hook.sh
install.sh
- If the system was last upgraded more than a day ago,
bash install.shsays so and runsupdatefirst (pacman's lists would otherwise name versions the mirrors have deleted: 404s). Underupdateitself (COREDESKTOP_ALLOW_PACMAN=1) it doesn't. bash install.sh. It should:- install whichever of
libvirt qemu-base virt-install dnsmasq edk2-ovmf dmidecodeare missing - enable and start
libvirtd.service - add you to the
libvirtgroup - define the
defaultnetwork if it's missing, set it to start at boot, and start it - print "coreapp-dev installed.", and the log-out note if your group membership is new
- install whichever of
- Log out and back in, then check:
id -nG | grep -w libvirt systemctl is-active libvirtd virsh -c qemu:///system net-info default # Active: yes, Autostart: yes ls ~/.local/share/coreapp-dev/images - Run
bash install.shagain. It must succeed, print "already enabled" and change nothing. - Error paths:
- With CoreDesktop missing:
HOME=$(mktemp -d) bash install.shshould say it needs CoreDesktop and exit 1.
- With CoreDesktop missing:
update.sh
bash update.shwith everything already installed: no package installs, no prompts apart from sudo, exits 0.- Stop the network (
virsh -c qemu:///system net-destroy default) and runbash update.sh: it should start the network again.
Through CoreDesktop's sibling command
Once the repo is in git:
export HOME="$(mktemp -d)"
mkdir -p "$HOME/.local/share"
ln -s ~/.local/share/coredesktop "$HOME/.local/share/coredesktop"
bash "$HOME/.local/share/coredesktop/sibling" add ~/Projects/coreapp-dev
bash "$HOME/.local/share/coredesktop/sibling" update
bash "$HOME/.local/share/coredesktop/sibling" add ~/Projects/coreapp-dev # re-run is safe
The coreapp network
After bash update.sh:
virsh -c qemu:///system net-info coreapp # Active: yes, Autostart: yes
sudo ls -l /etc/libvirt/hooks/network.d/coreapp-dev
sudo nft list table ip coreapp-dev # masquerade for 10.123.0.0/24
sudo iptables -S | grep coreapp-dev # 3 INPUT and 2 FORWARD accepts
grep virbr-coreapp /etc/ufw/user.rules # DHCP, DNS, route rules
-
Run
bash update.shagain: no changes, and no ufw rules added twice. (This also checks that thegreppatterns match how ufw writes its rules; if one doesn't,updateasks for sudo every time.) -
virsh -c qemu:///system net-destroy coreapp: the nft table and iptables rules are gone.net-start coreapp: they're back. -
The hook on its own, in a throwaway namespace (no host changes):
docker run --rm --cap-add NET_ADMIN -v "$PWD/libvirt/network-hook.sh:/hook:ro" \ --entrypoint bash corerelay:local -c \ '/hook coreapp started; /hook coreapp started; iptables -S | grep -c coreapp-dev; /hook coreapp stopped; iptables -S | grep -c coreapp-dev'prints 5, then 0 (the
sysctlerror is expected inside a container). -
Moving from the old network (192.168.123.0/24): with a VM running,
bash update.shredefinescoreappbut doesn't restart it, and says how. With no VM running, it restarts it:net-dumpxml coreappshows10.123.0.1and thedhcp-host=52:54:00:c0:4e:10,...option, andsudo iptables -S | grep -c 192.168.123prints 0. -
The reservation works:
virsh -c qemu:///system net-dhcp-leases coreapplistscoreserverat10.123.0.10. (dnsmasq still logs "cannot read .../coreapp.hostsfile": that file is libvirt's, root-only and now empty.) -
From the workstation, the Core's own services answer directly (its containers are on 192.168.0.0/16, so this fails if the VM network is in 192.168.x.x):
curl -sk -o /dev/null -w '%{http_code}\n' --resolve nextcloud.<domain>:443:10.123.0.10 https://nextcloud.<domain>/prints 302.
CoreServer VM
- Put Federated's dashboard key in
~/.config/coreapp-dev/authorized_keys. coreapp-vm create. Without the image, it downloads it first (1.3 GB; interrupt it and run again: it resumes) and checks its SHA-256. It says how many root keys it's installing (2: coreapp-dev's and the dashboard's) and printsIP: 10.123.0.10within about two minutes.coreapp-vm list:coreserveris running at 10.123.0.10.coreapp-vm sshlogs in (after cloud-init, a minute later). Inside the VM:cat /root/.ssh/authorized_keyshas both keysdf -h /federatedshows about 50 GB (the disk is 60 GB;/stays 10 GB)ping -c3 1.1.1.1andgetent hosts federated.computer(internet and DNS)systemctl is-enabled systemd-resolvedsaysmasked
coreapp-vm ssh hostnameprintscoreserver;coreapp-vm ip nopesays there's no such VM.coreapp-vm createagain refuses with "already exists".- To see the screen:
virt-viewer -c qemu:///system coreserver. - Once the Core is installed:
virsh -c qemu:///system reboot coreserver. Within a few minutes all its containers are up again, includingpdns(dig +short A <domain> @10.123.0.10answers). coreapp-vm stop, thencoreapp-vm start.coreapp-vm delete: asks for the name; anything else keeps the VM. With the name, the VM and/var/lib/libvirt/images/coreserver.qcow2are gone, the image in~/.local/share/coreapp-dev/images/stays.
Uninstall
On a machine you can rebuild (it removes the network every VM uses):
bash uninstall.shwith a VM on thecoreappnetwork, answering no: it stops, and nothing is removed.- Again, answering yes: the VMs and their disks are gone,
virsh -c qemu:///system net-list --allhas nocoreapp,/etc/libvirt/hooks/network.d/coreapp-devis gone,sudo iptables -S | grep -c coreapp-devprints 0,grep -c virbr-coreapp /etc/ufw/user.rulesprints 0 (virbr0's rules stay), andcoreapp-vmisn't onPATH. - Answering no to the data questions keeps
~/.local/share/coreapp-devand~/.config/coreapp-dev. bash install.shputs everything back.
Apps (coreapp)
Against a Core in the VM (coreapp-vm list shows it running). These install
a test app on that Core. It must not be registered with Federated's
monitoring: /federated/services/hello/service on the Core has no
MONITOR line, and ~/.local/share/coreapp-dev/logs/hello-install.log has
no blackboxregistrar request.
cd $(mktemp -d) && coreapp new hello:./hellohasservice,docker-compose.yml.in,env.in,install,uninstall,icon.png,Dockerfile,www/,README.md, with no{{...}}left (grep -r '{{' helloprints nothing).coreapp new helloagain refuses.~/.local/share/coreapp-dev/app-addresseshashello 192.168.200.x.cd hello && coreapp deploy: builds, copies the image, installs, printsDeployed: https://hello.<domain>/. On the Core,/federated/apps/hello/.envis root's, mode 600, withIMAGE_VERSIONequal toVERSIONand a randomAPP_SECRET.coreapp check:OK: HTTP 200, valid certificate.(the first certificate can take a minute).- Change
www/index.html,coreapp deploy: says "Updating it...", the container is recreated, the page shows the change,APP_SECRETis unchanged.coreapp deployagain: "The Core already has this image." coreapp status,coreapp logs,coreapp shell(exit withexit).coreapp remove, answering y: on the Core,/federated/apps/hello,/federated/services/hello, the container and thecoreapp/helloimage are gone. Nothing fromuninstallapp's trace is printed; it's in~/.local/share/coreapp-dev/logs/hello-remove.log(mode 600).- Collisions: an app named like one of Federated's (
coreapp new nextcloud, deploy) is refused; so is anINTERNAL_IPanother container uses.
With a database
coreapp new --postgres guest-book: hasapp.py, nowww/;servicehasDEPENDS="postgresql";env.inhasDB_NAME=guest_bookand a randomDB_PASSWORD; the README has a Database section.coreapp deploy,coreapp check. Loading the page several times (curl -s https://guest-book.<domain>/ | grep visits) counts up. On the Core,docker exec postgresql psql -U postgres -llistsguest_book, owned byguest_book.- Change
app.py,coreapp deploy: the change shows, the count continues. virsh -c qemu:///system reboot coreserver: once the Core is up, the app answers and the count continues (its log may show "Waiting for the database" first).coreapp remove: theguest_bookdatabase and user are gone too.