feat(supabase): owner trial served on the LAN address, sandbox kept on loopback

This commit is contained in:
bchanot committed 2026-11-04 22:36:50 +01:00
1 parent a69eba569b
commit d74c54ed05
6 files changed
+260 -21

No files matched your search

+28 -4
View File
@@ -23,7 +23,8 @@
# pnpm db:sandbox sheet-assets-e2e (= pnpm e2e:sheet-assets) the sheet-asset upload tool against the sandbox:
# a gateway on 127.0.0.1:$PORT_GATEWAY, then scripts/sheet-assets-e2e.sh
# pnpm db:sandbox trial the owner's trial (docs/development/V1-2-6_OWNER_TRIAL.md): a gateway on
# 127.0.0.1:$PORT_TRIAL_GATEWAY and the app on http://127.0.0.1:$PORT_TRIAL_APP,
# 127.0.0.1:$PORT_TRIAL_GATEWAY and the app on http://$FAUNOSTEO_TRIAL_HOST:$PORT_TRIAL_APP
# (default: this machine's LAN address; 127.0.0.1 = host-only),
# foreground, Ctrl+C stops both
# pnpm db:sandbox trial-account <email> a confirmed account, password at a hidden prompt (12 characters min.)
# pnpm db:sandbox trial-grant <email> <catalog_reader|sheet_editor|sheet_reviewer|sheet_publisher>
@@ -385,6 +386,27 @@ cmd_sheet_assets_e2e() {
# ---- Owner trial (docs/development/V1-2-6_OWNER_TRIAL.md) -------------------
port_taken() { (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null; }
# The one place the trial host is decided: FAUNOSTEO_TRIAL_HOST, default the DEV host (the LAN
# address); 127.0.0.1 = host-only. Loopback or a private IPv4 of an interface of this machine,
# nothing else (no 0.0.0.0, no name, no public address).
trial_host() {
local host="${FAUNOSTEO_TRIAL_HOST:-$FAUNOSTEO_DEV_HOST}" a b c d
[[ "$host" =~ ^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$ ]] \
|| die "FAUNOSTEO_TRIAL_HOST must be an IPv4 address (not a name, not 0.0.0.0): $host"
a=$((10#${BASH_REMATCH[1]})) b=$((10#${BASH_REMATCH[2]}))
c=$((10#${BASH_REMATCH[3]})) d=$((10#${BASH_REMATCH[4]}))
[ "$a" -le 255 ] && [ "$b" -le 255 ] && [ "$c" -le 255 ] && [ "$d" -le 255 ] \
|| die "FAUNOSTEO_TRIAL_HOST is not an IPv4 address: $host"
[ "$host" = "$a.$b.$c.$d" ] || die "FAUNOSTEO_TRIAL_HOST: write the address without leading zeros"
if [ "$a" -eq 127 ]; then host=127.0.0.1
elif [ "$a" -eq 10 ] || { [ "$a" -eq 172 ] && [ "$b" -ge 16 ] && [ "$b" -le 31 ]; } \
|| { [ "$a" -eq 192 ] && [ "$b" -eq 168 ]; }; then :
else die "FAUNOSTEO_TRIAL_HOST must be loopback or a private address (10/8, 172.16/12, 192.168/16): $host"
fi
ip -4 -o addr | grep -qF "inet $host/" || die "FAUNOSTEO_TRIAL_HOST $host is not an address of this machine"
TRIAL_HOST="$host"
}
trial_email() { # email: one fixed shape, nothing else reaches curl or psql
[[ "${1:-}" =~ ^[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]{1,120}\.[A-Za-z]{2,24}$ ]] \
|| die "an e-mail address is expected"
@@ -411,6 +433,7 @@ trial_stop() {
# through its environment, never argv.
cmd_trial() {
load_secrets
trial_host
[ -z "$(docker ps -a -q -f "name=^${TRIAL_GATEWAY}\$")" ] \
|| die "$TRIAL_GATEWAY exists (stop the running trial, or pnpm db:sandbox down)"
for port in $PORT_TRIAL_GATEWAY $PORT_TRIAL_APP; do
@@ -419,10 +442,11 @@ cmd_trial() {
trap trial_stop EXIT
trap 'exit 130' INT TERM
start_trial_gateway
echo "== trial: http://127.0.0.1:$PORT_TRIAL_APP (Ctrl+C stops the app and its gateway)"
echo "== trial: http://$TRIAL_HOST:$PORT_TRIAL_APP (Ctrl+C stops the app and its gateway)"
( cd apps/app && FAUNOSTEO_TRIAL_GATEWAY="http://127.0.0.1:$PORT_TRIAL_GATEWAY" \
VITE_SUPABASE_URL="http://127.0.0.1:$PORT_TRIAL_APP" VITE_SUPABASE_ANON_KEY="$SB_ANON_KEY" \
exec node_modules/.bin/vite --config vite/trial.config.ts --host 127.0.0.1 \
FAUNOSTEO_TRIAL_HOST="$TRIAL_HOST" \
VITE_SUPABASE_URL="http://$TRIAL_HOST:$PORT_TRIAL_APP" VITE_SUPABASE_ANON_KEY="$SB_ANON_KEY" \
exec node_modules/.bin/vite --config vite/trial.config.ts --host "$TRIAL_HOST" \
--port $PORT_TRIAL_APP --strictPort ) &
trial_pid=$!
wait "$trial_pid"