Files
garden-astro/deploy/auto-build.sh
T
wesandClaude Opus 5 de620bfaac Stage the ACannons browser build at /cannons
A third instance of the pattern notebooks-export/ and the reading payloads
already use: an artifact built somewhere with a toolchain this repo's
node:24-slim container does not have, dropped into a gitignored directory,
staged into public/ by a script, and picked up by auto-build.sh's signature on
the next tick. Nothing here needs a JDK, Go, or an opinion about the game --
cannons_reloaded's deploy/export-cannons.sh hands over a directory that is
already ready to serve.

Three things are load-bearing and easy to get wrong later:

The payload is at /cn/, not /cannons/. With build.format:'file' the page
builds to cannons.html, and try_files would then have a file and a directory
competing for the same URL. That is exactly why the notebook exports live at
/nb/ and not under /notebooks/.

nginx gets gzip_static for /cn/. nginx:alpine has `gzip on` commented out in
its base config, so without it the page ships 9MB instead of 3.3MB and nothing
anywhere reports that. It gets no-cache rather than an expiry, because
classes.js and cannons.wasm are stable filenames whose contents change on
every rebuild -- a long expiry would pair a stale client with a fresh server.

The page loads on click, not `loading="lazy"`. Lazy only defers until the
frame nears the viewport and this frame is above the fold, so a few MB would
download for anyone who opened the page to read the paragraph.

A missing export is a normal state throughout: copy-cannons.mjs stages
nothing, the page says so, and the sidebar link does not appear.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S4wdbGSVzvUDHBWRjSVxfr
2026-08-28 21:17:00 -04:00

54 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
# Timer target: rebuild the garden only when the vault or repo changed.
# Successor to the Quartz update_quartz_docker.sh change-detection loop.
# Usage: auto-build.sh [--force] (--force skips change detection — used
# by the manual rebuild hook)
set -eu
REPO=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
VAULT="${VAULT:-/home/nox/docker/obsidian/vaults/weeslahw_coppermind}"
STATE="$REPO/.build_state"
FORCE=0
[ "${1:-}" = "--force" ] && FORCE=1
cd "$REPO"
# serialize builds: the 5-min timer and the manual hook must never run
# docker/npm into the same checkout concurrently
exec 9>"$REPO/.build.lock"
flock 9
# a dirty tree can make pull fail; still rebuild whatever is checked out
git pull -q || echo "git pull failed (dirty tree?) — building local state"
# signature covers committed HEAD, any uncommitted repo edits, vault mtimes,
# and the notebook exports (gitignored, so git status/diff can't see them —
# they land here on their own timer via deploy/export-notebooks.py)
sig=$({
git rev-parse HEAD
git status --porcelain=v1
git diff
find "$VAULT" -name .obsidian -prune -o -type f -printf '%T@ %p\n' | sort
find "$REPO/notebooks-export" -type f -printf '%T@ %p\n' 2>/dev/null | sort
# the ACannons export: gitignored like the notebooks, written by a Gitea
# Action on cannons_reloaded rather than a timer here. Its own clause for
# the reason spelled out below -- with `-o` the -printf binds only to the
# LAST clause, so folding this into an OR-chain would silently print the
# other matches in a different format and stop the signature being stable.
find "$REPO/cannons-export" -type f -printf '%T@ %p\n' 2>/dev/null | sort
# same deal for every reading map payload: gitignored, written by library-rag-export.service
# on its own timer, so git status/diff above cannot see them change. One glob rather than a
# list — with `-o` the `-printf` binds only to the LAST clause, so an OR-chain silently
# prints the earlier matches in a different format and the signature stops being stable.
# It also means a future payload is watched without editing this line.
find "$REPO/public" -maxdepth 1 -name 'reading_*.json' -printf '%T@ %p\n' 2>/dev/null | sort
} | sha256sum | cut -d' ' -f1)
if [ "$FORCE" -eq 0 ] && [ -f "$STATE" ] && [ "$(cat "$STATE")" = "$sig" ]; then
exit 0
fi
sh "$REPO/deploy/build.sh"
printf %s "$sig" >"$STATE"
echo "garden rebuilt $(date -Is)"