Skip to content

Deploy headless-rust as a prebuilt .deb; remove legacy apps and scripts - #56

Merged
LeoLTM merged 12 commits into
feature/test-controlsfrom
chore/deploy-pipeline
Oct 28, 2026
Merged

LeoLTM merged 12 commits into
feature/test-controlsfrom
chore/deploy-pipeline

Conversation

@LeoLTM

@LeoLTM LeoLTM commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Summary

The Pi no longer builds anything. The daemon ships as an arm64 .deb, cross-compiled in a Debian Bookworm container (locally or in CI), and one command installs or updates it over SSH. Updating works over the offline field hotspot too, since the Pi only needs internet once, for the first install's dependencies.

cd headless-rust
bun run deploy pi@raspberrypi.local            # build the package from this checkout and install it
bun run deploy pi@192.168.4.1 --release        # latest GitHub release, via the Pi hotspot
bun run deploy pi@raspberrypi.local --release v0.4.0   # roll back
bun run pi status|logs|uninstall pi@raspberrypi.local

Stacked on feature/test-controls. Retarget to main once that branch is merged.

What changes

  • Packaging (headless-rust/packaging/): build-deb.sh builds the .deb with cargo-deb in a Bookworm cross-compilation container (podman or docker). The binary needs glibc ≥ 2.34 and libaravis ≥ 0.8.26, so it runs on Bookworm and Trixie.
  • Service: the daemon runs as a dedicated speedcamera user, with data in /var/lib/speedcamera and settings in /etc/default/speedcamera. A sudoers rule allows only the network script, nmcli, iw and shutdown -h now. This replaces the install-time polkit rule that gave every local user full NetworkManager control.
  • Migration: the first install over an old git-checkout setup stops the old unit and moves ~/.speedcamera (database and images) to /var/lib/speedcamera. If the install aborts, the old service is restored. apt remove keeps data; apt purge deletes it.
  • Deploy tooling: scripts/pi.sh (deploy / status / logs / uninstall) and an on-Pi packaging/install.sh replace six install/update/cleanup scripts and two unit files. Those had kept three diverging copies of the systemd unit.
  • Versioning: Cargo.toml (now 0.5.0) is the single version source. /api/health reports version and gitSha, and CI rejects a release tag that doesn't match Cargo.toml.
  • CI: the build job produces the .deb and uploads it as an artifact on every run. Releases attach speedcamera_arm64.deb and SHA256SUMS next to the firmware. The test job runs the integration suite, and the Rust cache now actually covers headless-rust/target.
  • Fixes:
    • build.rs hard-coded /usr/lib/aarch64-linux-gnu, which broke linking wherever arm64 libraries are installed alongside another architecture.
    • Shutdown now tries passwordless sudo before a typed password.
  • Removed:
    • electron/ and electronbun/.
    • headless-rust/diagnostics/ (the August Wi-Fi freeze investigation).
    • Electrobun updater and window stubs, and setup:esptool.
    • arduino/old/.
    • The ad-hoc TS test scripts, replaced by tests/server.test.ts.

Testing

  • cargo test: 14/14. bun run test:integration (new suite, against the mock daemon in a throwaway data dir): 10/10. bun tsc --noEmit is clean. Every commit that touches Rust compiles with -D warnings.
  • arm64 package on Bookworm arm64 (qemu): apt install resolved all dependencies from Debian's repos. The service user was created, the sudoers file validated, and the packaged binary served the UI and /api/health as speedcamera.
  • Package lifecycle under real systemd: run on amd64, with an amd64 build of the same package, because systemd crashes under qemu user emulation. Starting from a fake old git-checkout install, 27/27 checks passed:
    • Migration of the database and images.
    • Removal of the legacy unit and polkit rule.
    • Service runs as speedcamera.
    • sudo allows only the listed commands, and admin sudo still works.
    • Reinstall/upgrade, remove (keeps data), purge (deletes data), and a clean install.
  • scripts/pi.sh deploy, status and uninstall --purge --reset-network were run over SSH against that container.
  • Not tested on real hardware: a Pi 5 with the GigE camera, the serial sensor, the I2C display and NetworkManager hotspot switching.

Before merging / rolling out

  • Tag v0.5.0 after merging. The current latest release (v0.4.0) has no .deb, so --release and install.sh won't work until then.
  • Do the first migration on one Pi, with a backup of ~/.speedcamera.
  • Do first installs over Wi-Fi. A Pi with no Wi-Fi connection at boot still starts the hotspot and moves eth0 to the camera LAN. That behaviour is unchanged, but it drops an Ethernet-only SSH session.

Follow-ups (not in this PR)

  • One-time cargo fmt and clippy cleanup (240 formatting diffs, ~50 clippy warnings), then add both as CI checks.
  • Move the sysctl and Wi-Fi power-save config that setup-network.sh writes on every mode switch into the package.
  • Updating from inside the web UI: show the running version, check for a newer release, and accept an uploaded .deb while offline.
  • cancelFlash is still a no-op.

🤖 Generated with Claude Code

LeoLTM added 12 commits October 28, 2026 02:17
Both desktop apps were superseded by headless-rust and are no longer
built in CI. They remain available in the git history.
- diagnostics/ was written for the August Wi-Fi freeze investigation.
  Its fixes now live in setup-network.sh, and `diag:fix` wrote a second,
  conflicting sysctl file.
- The updater slice, the window/updater RPC stubs and `setup:esptool`
  (an amd64 binary nothing used) came from the Electrobun app.
- arduino/old/old.cpp is the 2023 prototype.
Cargo.toml becomes the single version source. It said 0.1.0 while
package.json said 0.5.0 and rpc.rs hard-coded "0.5.0-rust", so there was
no way to tell what a Pi was running. /api/health, getLocalVersion and
the startup banner now report the version plus the commit passed in
SPEEDCAMERA_GIT_SHA (set by package builds; local builds show "dev").
Both callers kept their own list of relative and /home/pi/... guesses.
Look in /usr/lib/speedcamera, where the package installs the script,
and fall back to the checkout copy for `cargo run`.
The packaged daemon runs as a system user without a password. Checking
a typed password first would make shutdown fail whenever one was entered.
The fixed -L /usr/lib/aarch64-linux-gnu made the linker pick arm64
libraries whenever they are installed next to another architecture, as
in the cross-compilation image. pkg-config already supplies the paths,
and the fallback relies on the linker's defaults.
packaging/build-deb.sh cross-compiles in a Debian Bookworm container
(podman or docker), so the Pi no longer needs Rust, Bun or internet to
update. Building on Bookworm keeps the binary compatible with Trixie.

The package runs the daemon as a dedicated `speedcamera` user, keeps
data in /var/lib/speedcamera and ships a sudoers rule limited to the
commands the daemon runs. Installed over a git-checkout setup, preinst
and postinst stop the old unit and move ~/.speedcamera over; an aborted
install restores the old service.
`scripts/pi.sh deploy|status|logs|uninstall` installs a locally built,
released or given .deb over SSH. It also works over the offline hotspot,
because the Pi only needs internet once, for the first install's
dependencies. packaging/install.sh installs a release directly on a Pi.

Removes the six old scripts and two unit files, which kept three
diverging copies of the systemd unit and required building on the Pi.
The two spawn-and-check scripts duplicated their boilerplate and wrote
test violations into the developer's real ~/.speedcamera; verify-ws.ts
wasn't wired to anything. tests/server.test.ts covers the same HTTP, RPC
and live-event checks against a throwaway data dir.
- The build job produces the arm64 package (uploaded as an artifact on
  every run) instead of an x86 binary nobody used.
- Releases attach speedcamera_arm64.deb and SHA256SUMS next to the
  firmware, and a tag must match the Cargo.toml version.
- The test job runs the integration suite, and the Rust cache now
  covers headless-rust/target (rust-cache was looking at ./target).
CI runs the build container as the runner's uid, which has no passwd
entry in the image, and visudo refuses to run for such users. Validate
the sudoers file in a separate root container (it only reads the file)
and keep the build itself running as the calling user.
@LeoLTM
LeoLTM merged commit f1447f6 into feature/test-controls Oct 28, 2026
4 checks passed
@LeoLTM
LeoLTM deleted the chore/deploy-pipeline branch October 28, 2026 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant