Files
recap/docker_entrypoint.sh
T
Keysat b5a066750a Live-reload Gemini API key config + fix vendor module resolution
Two related changes that ship together because the second was uncovered
while testing the first.

1. Live config reload (the ostensible feature):

   The "Set Gemini API Key" StartOS action writes to /data/config/
   startos-config.json. The server used to read that file once at
   startup (and via a separate Python read in docker_entrypoint.sh
   before that), which meant a key change required a service restart
   to take effect. Now the server polls the file every 3 s
   (RECAP_CONFIG_POLL_MS, env-overridable) and updates serverApiKey
   in place. fs.watch was tried first and dropped — it's flaky on
   macOS (FSEvents single-file quirks) and behaves inconsistently with
   atomic-rename writes the SDK file model uses. Polling is dead
   simple and a stat call every 3 s is free.

   Also dropped the Python config read from docker_entrypoint.sh; the
   server now handles it natively. Entrypoint still loads /data/.env
   for arbitrary env vars (RECAP_*, etc.).

2. Vendor module resolution (the silently-broken thing):

   The earlier vendor change (move @keysat/licensing-client from a
   git+https dep to a file: dep at vendor/) created a symlink in
   server/node_modules. That symlink to the vendor dir was getting
   resolved by Node, so the keysat client tried to import @noble/
   ed25519 from /app/vendor/keysat-licensing-client/dist/, walked up
   to /app/vendor/, then /app/, neither of which had node_modules.

   Result: v0.2.0 and v0.2.1 would crash at startup with
   ERR_MODULE_NOT_FOUND on @noble/ed25519. The Docker BUILD succeeded
   because npm install with file: deps doesn't pull transitive deps
   into the parent node_modules — but the runtime would have failed
   the moment server/license.js ran.

   Fix:
     • Dockerfile builder now `npm install`s inside vendor/keysat-
       licensing-client/ so @noble/* lands in its own node_modules,
       where Node's resolver finds it.
     • Dockerfile runner now COPYs vendor/ to the runner image
       (previously not copied — the symlink in server/node_modules
       would have pointed at nothing).
     • vendor/keysat-licensing-client/package-lock.json is committed
       so the in-Docker install is reproducible.
2026-05-08 16:38:33 -05:00

45 lines
1.3 KiB
Bash

#!/bin/sh
set -eu
DATA_DIR="/data"
HISTORY_DIR="$DATA_DIR/history"
CONFIG_DIR="$DATA_DIR/config"
BIN_DIR="$DATA_DIR/bin"
CACHE_DIR="$DATA_DIR/ytdlp-cache"
# Create directory structure on persistent volume
mkdir -p "$HISTORY_DIR" "$CONFIG_DIR" "$BIN_DIR" "$CACHE_DIR"
# Ensure the non-root user owns the data volume
# (on first boot the volume is root-owned; we need appuser to write)
chown -R 1001:1001 "$DATA_DIR"
# Use persistent yt-dlp binary if available (runtime updates go here)
if [ -x "$BIN_DIR/yt-dlp" ]; then
export PATH="$BIN_DIR:$PATH"
fi
# Point yt-dlp cache to persistent storage (stores OAuth tokens)
export XDG_CACHE_HOME="$CACHE_DIR"
# Load arbitrary env vars from .env if it exists (e.g. RECAP_*).
# We do NOT read startos-config.json here — the Node server reads that
# natively at startup AND watches it for live updates, so config changes
# made via the StartOS action are picked up without a service restart.
if [ -f "$DATA_DIR/.env" ]; then
set -a
. "$DATA_DIR/.env"
set +a
fi
export DATA_DIR="$DATA_DIR"
export PORT="${PORT:-3001}"
export HOSTNAME="0.0.0.0"
echo "Starting Recap..."
echo " yt-dlp: $(yt-dlp --version 2>/dev/null || echo 'not found')"
echo " ffmpeg: $(ffmpeg -version 2>/dev/null | head -1 || echo 'not found')"
echo " Data: $DATA_DIR"
exec node /app/server/index.js