dev: tools/dev.sh builds and serves through the Crafter.Build Flatpak
All checks were successful
Deploy / build-deploy (push) Successful in 6m54s

The script stopped at "crafter-build: command not found": crafter-build
is a shell alias for the Flatpak, and a /bin/sh script does not inherit
aliases. It now calls the Flatpak itself unless a crafter-build command
is on PATH.

The server it builds links the SDK's libc++ and libunwind, so on the
host it does not start (libunwind.so.1 not found). It now runs inside
the Flatpak, like CI's crafter-run, with the temp dir granted so it can
write the order ledger; without the grant every checkout answers 500.

bin/ held builds from the old and the current toolchain, and the
exactly-one rule refused to pick. Every Crafter.Build update adds a
variant directory, so the script now takes the newest and says which,
rather than failing after each update. CI keeps its strict rule.

Stopping it also stops its tail of the server log, which was left
running whenever the script ended without a Ctrl-C. The help text names
/shop/donation and no longer mentions the RF form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jorijn van der Graaf 2026-11-25 15:33:50 +01:00
commit 1fb4b1c302
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB

View file

@ -47,45 +47,70 @@ done
cleanup() { cleanup() {
[ -n "${SRV_PID:-}" ] && kill "$SRV_PID" 2>/dev/null || true [ -n "${SRV_PID:-}" ] && kill "$SRV_PID" 2>/dev/null || true
[ -n "${CADDY_PID:-}" ] && kill "$CADDY_PID" 2>/dev/null || true [ -n "${CADDY_PID:-}" ] && kill "$CADDY_PID" 2>/dev/null || true
[ -n "${TAIL_PID:-}" ] && kill "$TAIL_PID" 2>/dev/null || true
rm -rf "$WORK" rm -rf "$WORK"
} }
trap cleanup EXIT INT TERM trap cleanup EXIT INT TERM
# Exactly one match or fail loudly. A variant directory name embeds a config # crafter-build is the Crafter.Build Flatpak. An interactive shell reaches it
# hash, so two matches means the tree holds artifacts from two different # through an alias, which a script does not inherit, so call the Flatpak
# configurations and picking either would be a coin flip — this has caused real # itself unless a crafter-build command is on PATH (CI installs a wrapper).
# confusion (testing a stale binary and believing the result). CRAFTER_REF="${CRAFTER_REF:-net.catcrafts.CrafterBuild}"
onedir() { crafter_build() {
_m=$(find bin -maxdepth 1 -type d -name "$1" 2>/dev/null | sort) if command -v crafter-build >/dev/null 2>&1; then
_n=$(printf '%s\n' "$_m" | grep -c . || true) crafter-build "$@"
if [ "$_n" -ne 1 ]; then else
echo "dev: expected exactly one $1 directory under bin/, found $_n" >&2 flatpak run --die-with-parent "$CRAFTER_REF" "$@"
[ "$_n" -gt 1 ] && printf '%s\n' "$_m" >&2 fi
echo "dev: run 'rm -rf bin' and try again" >&2 }
# What it builds links the SDK's libc++ and libunwind (RUNPATH /app/lib), so the
# server runs inside the Flatpak as well, the way CI's crafter-run does: on the
# host it does not even start (libunwind.so.1 not found). $WORK is under /tmp,
# which the sandbox does not share, hence the grant. Without it the server
# cannot write the order ledger and every checkout answers 500.
in_sdk() {
_cmd=$1; shift
flatpak run --die-with-parent --filesystem="$WORK" --command="$_cmd" \
"$CRAFTER_REF" "$@"
}
# A product's build directory. Its name embeds a config hash, and every
# Crafter.Build update brings a new one, so locally bin/ gains a variant per
# toolchain release while nothing removes the old ones. CI starts from a clean
# bin/ and keeps its exactly-one rule; here, take the variant whose artifact was
# written last, which right after a build is the build just made. When there is
# a choice, say which one won, so a stale pick cannot go unnoticed.
variant() {
_pick=$(ls -t bin/$1/$2 2>/dev/null | head -n 1)
if [ -z "$_pick" ]; then
echo "dev: no bin/$1/$2 found; run without --no-build first" >&2
exit 1 exit 1
fi fi
printf '%s' "$_m" _n=$(ls -d bin/$1 | wc -l)
[ "$_n" -gt 1 ] && echo "dev: using ${_pick%/*} (newest of $_n builds)" >&2
printf '%s' "${_pick%/*}"
} }
if [ "$BUILD" = 1 ]; then if [ "$BUILD" = 1 ]; then
echo "dev: building the server product..." echo "dev: building the server product..."
crafter-build --product=server >"$WORK/build-server.log" 2>&1 \ crafter_build --product=server >"$WORK/build-server.log" 2>&1 \
|| { echo "dev: server build failed:" >&2; tail -20 "$WORK/build-server.log" >&2; exit 1; } || { echo "dev: server build failed:" >&2; tail -20 "$WORK/build-server.log" >&2; exit 1; }
SRV=$(onedir 'Catcrafts.Server-*') SRV=$(variant 'Catcrafts.Server-*' catcrafts-server)
# sitemap.xml and feed.xml are generated from the same route table and Post # sitemap.xml and feed.xml are generated from the same route table and Post
# model the pages use, and the wasm build copies them into the bundle — so # model the pages use, and the wasm build copies them into the bundle — so
# they have to exist before it runs. # they have to exist before it runs.
"$SRV/catcrafts-server" --sitemap > sitemap.xml in_sdk "$PWD/$SRV/catcrafts-server" --sitemap > sitemap.xml
"$SRV/catcrafts-server" --feed > feed.xml in_sdk "$PWD/$SRV/catcrafts-server" --feed > feed.xml
echo "dev: building the wasm bundle..." echo "dev: building the wasm bundle..."
crafter-build >"$WORK/build-web.log" 2>&1 \ crafter_build >"$WORK/build-web.log" 2>&1 \
|| { echo "dev: wasm build failed:" >&2; tail -20 "$WORK/build-web.log" >&2; exit 1; } || { echo "dev: wasm build failed:" >&2; tail -20 "$WORK/build-web.log" >&2; exit 1; }
fi fi
SRV=$(onedir 'Catcrafts.Server-*') [ -n "${SRV:-}" ] || SRV=$(variant 'Catcrafts.Server-*' catcrafts-server)
WEB=$(onedir 'Catcrafts.Net-*') WEB=$(variant 'Catcrafts.Net-*' catcrafts.wasm)
# Makes the static shell survive being served at a deep URL. Run unconditionally, # Makes the static shell survive being served at a deep URL. Run unconditionally,
# not just after a build: --no-build may be pointing at a bundle someone produced # not just after a build: --no-build may be pointing at a bundle someone produced
@ -216,7 +241,7 @@ JSON
echo "dev: seeded SAMPLE financials (DEV_FINANCIALS=1) — figures are invented" echo "dev: seeded SAMPLE financials (DEV_FINANCIALS=1) — figures are invented"
fi fi
"$SRV/catcrafts-server" --serve "$BACKEND_PORT" \ in_sdk "$PWD/$SRV/catcrafts-server" --serve "$BACKEND_PORT" \
--orders="$WORK/orders.jsonl" --rail="$RAIL" \ --orders="$WORK/orders.jsonl" --rail="$RAIL" \
--redirect-base="http://localhost:$PORT" >"$WORK/server.log" 2>&1 & --redirect-base="http://localhost:$PORT" >"$WORK/server.log" 2>&1 &
SRV_PID=$! SRV_PID=$!
@ -242,7 +267,7 @@ cat <<EOF
/ home / home
/shop product list /shop product list
/shop/<slug> donation (fake payment rail) /shop/donation donate any amount to reach the payment page
/projects the Crafter suite /projects the Crafter suite
/posts fediverse posts /posts fediverse posts
/demos demo list; /demos/raytracer loads the wasm /demos demo list; /demos/raytracer loads the wasm
@ -267,12 +292,13 @@ cat <<EOF
tools/dev-credit.sh $WORK/orders.jsonl CC-XXXXXX 57043 tools/dev-credit.sh $WORK/orders.jsonl CC-XXXXXX 57043
The reconciler picks it up within a minute and the order flips to paid. The reconciler picks it up within a minute and the order flips to paid.
Reference matching is deliberately forgiving, so try lower case, spaces, or Reference matching is deliberately forgiving, so try lower case or spaces to
the RF… form to see that they all still settle the same order.") see that they still settle the same order.")
Ctrl-C to stop. Ctrl-C to stop.
EOF EOF
# Surface backend output as it happens — this is where a render error shows up. # Surface backend output as it happens — this is where a render error shows up.
tail -f "$WORK/server.log" & tail -f "$WORK/server.log" &
TAIL_PID=$!
wait "$SRV_PID" wait "$SRV_PID"