From 575d2f9744028f662b16f7138242dbdb1b80e0cd Mon Sep 17 00:00:00 2001 From: Roland Date: Sat, 18 Jul 2026 13:37:00 -0600 Subject: [PATCH] image builds: reset repo to HEAD before stamping the app build The pi-gen and Debian Live chroot hooks run `npm install`, which rewrites the tracked app/package-lock.json, then build_app.sh stamps build/.build-stamp from that dirty working tree. On first boot repair.sh runs `git reset --hard` (reverting the lock) *before* it recomputes the stamp, so the baked stamp can never match -- and the device rebuilds the React app every time, the exact OOM-prone step baking the build in (#536) was meant to avoid. Verified against WROLPi-v0.27.2: the shipped image had `M app/package-lock.json`, baked stamp a9c6ef61..., post-reset stamp 2b908c6c... (guaranteed mismatch). Mirror repair.sh in both image hooks: `git reset --hard HEAD` right after npm install and before build_app.sh, so the baked stamp represents committed source and matches what the device recomputes. Only the lock is reverted; build/, node_modules, and the venvs are untracked and survive. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../config/hooks/normal/9999-wrolpi.hook.chroot | 10 ++++++++++ pi-gen/stage2/04-wrolpi/03-run-chroot.sh | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/debian-live-config/config/hooks/normal/9999-wrolpi.hook.chroot b/debian-live-config/config/hooks/normal/9999-wrolpi.hook.chroot index 858de050..2920f0a7 100644 --- a/debian-live-config/config/hooks/normal/9999-wrolpi.hook.chroot +++ b/debian-live-config/config/hooks/normal/9999-wrolpi.hook.chroot @@ -56,6 +56,16 @@ npm --version node --version npm install +# `npm install` rewrites the tracked app/package-lock.json. build_app.sh (below) +# stamps build/.build-stamp from that working tree, but on-device repair.sh runs +# `git reset --hard` before it stamps -- reverting the lock -- so a stamp baked +# against the dirty lock can never match on first boot and the box rebuilds the app. +# Reset to HEAD here, exactly as repair.sh does, so the baked stamp represents +# committed source. Only the lock is reverted; build/, node_modules, and the venvs +# are untracked and survive. The repo is cloned and reset as root (same owner), +# so no safe.directory config is needed here. +git -C /opt/wrolpi reset --hard HEAD + # Build the React production bundle. Without this, /opt/wrolpi/app/build/ # does not exist and wrolpi-app.service (`serve build -l 3000 ...`) returns # 404 for every request. Baking the build into the squashfs means the diff --git a/pi-gen/stage2/04-wrolpi/03-run-chroot.sh b/pi-gen/stage2/04-wrolpi/03-run-chroot.sh index ed2547c9..9affc7f8 100755 --- a/pi-gen/stage2/04-wrolpi/03-run-chroot.sh +++ b/pi-gen/stage2/04-wrolpi/03-run-chroot.sh @@ -63,6 +63,15 @@ echo "Controller pre-installed" # Install webapp. (cd /opt/wrolpi/app && npm install) +# `npm install` rewrites the tracked app/package-lock.json. build_app.sh (below) +# stamps build/.build-stamp from that working tree, but on-device repair.sh runs +# `git reset --hard` before it stamps -- reverting the lock -- so a stamp baked +# against the dirty lock can never match on first boot and the Pi rebuilds the app +# (the exact OOM-prone step this bake-in avoids). Reset to HEAD here, exactly as +# repair.sh does, so the baked stamp represents committed source. Only the lock is +# reverted; build/, node_modules, and the venvs are untracked and survive. +git -C /opt/wrolpi reset --hard HEAD + # Build the React production bundle now, so it is baked into the image. Without # this the Pi would build on first boot -- a multi-minute, memory-hungry step # that can OOM on a 2GB Pi. build_app.sh stamps the output so the on-device