Files
shaneandshinyobjectz 1a8a7df53d Opening a video, probing it and making its contact sheet no longer read the whole file (#293)
On a cloud Sprite one `raea media probe` of a 1.1 GB 4K interview took 112 s, and its 16-frame sheet 32 s where
ffmpeg alone takes 7 (12-01, measured). Three causes:

- The ffmpeg backend asked ffprobe for every packet's time on each open, and for MP4 and QuickTime ffprobe reads every
  packet to answer: 1 GB read per open, and a sheet opened its file once a frame. The times now come from the file's
  own sample tables (io/ffmpeg mov.rs; the same times as ffprobe's on 45 of 45 real client clips, up to one shift),
  and ffprobe is asked only for the stream's facts. Fragments, other containers and edit lists that do more than set
  a start are asked of ffprobe as before.
- `media probe` decoded the whole sound track to learn its rate, channels and length: read from the track's tables.
- A sheet's frames are read four at a time.

The Sprite's service sets its disks' read-ahead to 16 MB at each start: at the disk's own 256 KB, with each read
answered in about 26 ms, a pass over footage ran at 10 MB/s.

Co-authored-by: shinyobjectz <[email protected]>
2026-12-01 11:22:11 -08:00

126 lines
7.1 KiB
Bash

#!/bin/bash
# One raea cloud box, set up on the Fly Sprite it runs on. Two callers run this same file: deploy/sprites/box.sh up
# from a Mac, and raea cloud's POST /v1/bots (B1: apps/site/cloud harness/sprite.ts, through the Sprites API, at the
# commit it pins), so a box made by hand and a box a bot makes can't differ (docs/cloud-render.feature CR11).
# It only adds what's missing, so running it again is safe.
#
# bash -s -- NAME RAEA_VERSION "AGENTS" [REF] < setup.sh
#
# Before it runs, the caller writes the farm's env (RAEA_CLOUD_GPU_URL, RAEA_CLOUD_GPU_TOKEN) to /tmp/farm.env, and
# from a working tree, sdk/cloud's files to /tmp/raea-cloud.tgz. With no tarball there, it takes them from raea's
# public repo at REF. What goes on: raea's Linux release, Node, the ACP agents named in AGENTS with raea's skills for
# each, and sdk/cloud's server as the Sprite's HTTP service on 8080, `raea render` there sent to the farm.
set -euo pipefail
NAME=${1:?name} VERSION=${2:?raea version} AGENTS=${3:?agents} REF=${4:-}
NODE=24.22.0
say() { echo "box $NAME: $*"; }
export DEBIAN_FRONTEND=noninteractive
say packages
# raea's runtime libraries, and Mesa's lavapipe: the box draws previews on its CPU, its renders go to the farm
sudo -E apt-get update -qq
sudo -E apt-get install -y -qq --no-install-recommends ca-certificates curl git git-lfs zstd xz-utils procps ripgrep \
libasound2t64 libfontconfig1 libvulkan1 mesa-vulkan-drivers vulkan-tools > /dev/null
# faces an ad is set in (12-01: a box had Liberation and DejaVu alone, so every cut fell back to Liberation Sans): the
# open families brands are closest to, each taken when this Ubuntu has it
for f in fonts-inter fonts-roboto fonts-open-sans fonts-lato fonts-montserrat fonts-noto-core fonts-ibm-plex fonts-bebas-neue fonts-urw-base35 fonts-liberation2; do
dpkg -s "$f" > /dev/null 2>&1 || sudo -E apt-get install -y -qq --no-install-recommends "$f" > /dev/null 2>&1 || say "no $f here"
done
node -v 2> /dev/null | grep -q '^v24' || {
say "node $NODE"
curl -fsSL "https://nodejs.org/dist/v$NODE/node-v$NODE-linux-x64.tar.xz" | sudo tar -xJ -C /opt
sudo ln -sf /opt/node-v$NODE-linux-x64/bin/{node,npm,npx} /usr/local/bin/
}
if [ "$(/opt/raea/bin/raea --version 2> /dev/null)" != "$VERSION" ]; then
say "raea $VERSION"
f=raea-$VERSION-linux-x86_64.tar.gz u=https://github.com/shinyobjectz/raea/releases/download/v$VERSION
(cd /tmp && curl -fsSL -o "$f" "$u/$f" && curl -fsSL -o "$f.sha256" "$u/$f.sha256" && sha256sum -c --quiet "$f.sha256")
sudo rm -rf /opt/raea && sudo mkdir -p /opt/raea && sudo tar -xzf "/tmp/$f" -C /opt/raea --strip-components=1
rm -f "/tmp/$f" "/tmp/$f.sha256"
fi
# the Google sign-in's own browser (server/google-screen.ts): Chrome on a virtual display, shown over VNC
sudo -E apt-get install -y -qq --no-install-recommends xvfb x11vnc xdotool fonts-noto-color-emoji > /dev/null
command -v google-chrome > /dev/null || {
say "google chrome"
curl -fsSLo /tmp/chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo -E apt-get install -y -qq /tmp/chrome.deb > /dev/null
rm -f /tmp/chrome.deb
}
# sdk/cloud's server, client and wrapper, as the image has them (image/Dockerfile)
if [ ! -s /tmp/raea-cloud.tgz ]; then
[ -n "$REF" ] || { echo "box: no /tmp/raea-cloud.tgz and no REF to take sdk/cloud from"; exit 2; }
say "sdk/cloud at $REF"
g=$(mktemp -d)
git -C "$g" init -q && git -C "$g" sparse-checkout set sdk/cloud
git -C "$g" fetch -q --depth 1 --filter=blob:none https://github.com/shinyobjectz/raea "$REF" && git -C "$g" checkout -q FETCH_HEAD
tar -czf /tmp/raea-cloud.tgz -C "$g/sdk/cloud" server src image deploy/git package.json package-lock.json
rm -rf "${g:?}"
fi
say server
sudo mkdir -p /opt/raea-cloud && sudo chown "$(id -u):$(id -g)" /opt/raea-cloud
tar -xzf /tmp/raea-cloud.tgz -C /opt/raea-cloud && rm /tmp/raea-cloud.tgz
cd /opt/raea-cloud
npm ci --omit=dev --no-fund --no-audit --loglevel=error
node server/agents.ts install $AGENTS
chmod +x image/*.sh deploy/git/*
sudo ln -sf /opt/raea-cloud/image/raea.sh /usr/local/bin/raea
sudo ln -sf /opt/raea-cloud/deploy/git/repo.sh /usr/local/bin/raea-repo
git lfs install --skip-repo > /dev/null
# the box's commits say which box made them
git config --global user.name "raea cloud $NAME"
git config --global user.email "$NAME@box.raea.io"
git config --global init.defaultBranch main
# the box's own token, made once and kept on its disk; the farm's, from the caller
umask 077
[ -s ~/.raea-cloud.env ] || echo "RAEA_CLOUD_TOKEN=$(openssl rand -hex 32)" > ~/.raea-cloud.env
if [ -s /tmp/farm.env ]; then
{ grep -v '^RAEA_CLOUD_GPU_' ~/.raea-cloud.env; cat /tmp/farm.env; } > ~/.raea-cloud.env.new
mv ~/.raea-cloud.env.new ~/.raea-cloud.env && rm /tmp/farm.env
fi
grep -q '^RAEA_CLOUD_GPU_URL=' ~/.raea-cloud.env || { echo "box: no farm (write RAEA_CLOUD_GPU_URL and RAEA_CLOUD_GPU_TOKEN to /tmp/farm.env)"; exit 2; }
umask 022
# raea's skills by raea's own agent names (the registry's ids aren't them: 11-25, every box had gone without), into the
# box's home; each client's socket links them into its own config folders (server/main.ts linkSkills)
for a in $AGENTS; do
case "$a" in claude-acp) s=claude ;; antigravity-acp | gemini) s=gemini ;; kimi-code | kimi) s=kimi ;; codex-acp) s=codex ;; *) continue ;; esac
/opt/raea/bin/raea skills install --agent "$s" > /dev/null 2>&1 || say "raea skills for $a ($s) not installed"
done
# the build, as the caller stamped it (box.sh: /tmp/raea-cloud-build.json), with what this script put on: shown on
# GET /v1/health and raea cloud's /v1/admin/boxes, so which code a box runs is never a guess
python3 - "$NAME" "$VERSION" "$REF" << 'PY' > /opt/raea-cloud/BUILD.json
import json, os, sys, datetime
b = {}
try: b = json.load(open("/tmp/raea-cloud-build.json"))
except Exception: pass
if sys.argv[3]: b.setdefault("commit", sys.argv[3]); b.setdefault("build", sys.argv[3][:12]); b.setdefault("dirty", False)
b.update(box=sys.argv[1], raea=sys.argv[2], built_at=datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="seconds"))
print(json.dumps(b))
PY
rm -f /tmp/raea-cloud-build.json
# the server, as the Sprite's HTTP service on 8080: raea on lavapipe (docs/cloud.feature CL13), renders to the farm
cat > /opt/raea-cloud/image/sprite-start.sh << 'EOF'
#!/bin/bash
set -a
. ~/.raea-cloud.env
set +a
# footage is read 16 MB ahead: a Sprite's disk answers each read in about 26 ms, and at its own 256 KB a pass over
# a 1 GB interview took two minutes that takes 14 s so (12-01, measured). Set at each start: a Sprite woken keeps none.
for b in /sys/class/bdi/*/read_ahead_kb /sys/block/*/queue/read_ahead_kb; do sudo sh -c "echo 16384 > $b" 2> /dev/null || true; done
export PORT=8080 RAEA_CLOUD_DEVICE=cpu WGPU_BACKEND=vulkan __EGL_VENDOR_LIBRARY_DIRS=/nonexistent
export VK_DRIVER_FILES=$(ls /usr/share/vulkan/icd.d/lvp_icd*.json | head -1)
mkdir -p ~/work
exec node /opt/raea-cloud/server/main.ts
EOF
chmod +x /opt/raea-cloud/image/sprite-start.sh
if sprite-env services list | grep -q '"raea-cloud"'; then
sprite-env services restart raea-cloud > /dev/null
else
sprite-env services create raea-cloud --cmd /opt/raea-cloud/image/sprite-start.sh --http-port 8080 > /dev/null
fi
say ready