#!/usr/bin/env bash # Smoke test for the sm121 add-on image (specs/tech-architecture/ # ha-addon-recipe-repos.md): run the entrypoint with a `file://` recipe # repo (mounted) + a token, and assert the dashboard answers on 3100 # (curl /api/state). # # The thin image compiles sm121 from the launcher repo on first boot — # hermetically, from THIS checkout via file:// (SM121_LAUNCHER_URL), with # the cargo target dir persisted in a volume (re-runs are incremental). # # scripts/smoke-addon.sh [image] (default sm121-addon:latest) set -euo pipefail cd "$(dirname "$0")/.." IMG="${1:-sm121-addon:latest}" TOKEN=smoke-test # The image source lives in the sibling add-on repo (the HA add-on store). # Build it locally if it isn't there yet (CI builds the registry one). if ! docker image inspect "$IMG" >/dev/null 2>&1; then echo "building $IMG from ../sm121-ha-integration/sm121/" docker build -q -t "$IMG" -f ../sm121-ha-integration/sm121/Dockerfile ../sm121-ha-integration/sm121/ fi # A minimal `file://` recipe repo, mounted read-only at /repos. It lives # under target/ (gitignored) so it sits on a volume the docker VM shares # — colima only mounts /Volumes here; a $HOME tmpdir would mount empty. REPO="$(pwd)/target/smoke-addon-repo" rm -rf "$REPO"; mkdir -p "$REPO" git init -q "$REPO" mkdir -p "$REPO/recipes/demo" echo 'engine = "vllm"' > "$REPO/recipes/demo/recipe.toml" git -C "$REPO" add -A git -C "$REPO" -c user.email=t@sm121.test -c user.name=sm121-test commit -qm init # Persistent HOME (the add-on data folder in HA; here: the sm121 binary + # the cargo target cache, so re-runs don't rebuild the world). HOMEV="$(pwd)/target/smoke-addon-home" mkdir -p "$HOMEV" CID="$(docker run -d \ -p 3100:3100 \ -v "$REPO":/repos:ro \ -v "$HOMEV":/root \ -v "$(pwd)":/src-launcher:ro \ -e SM121_RECIPE_REPOS='[{"url":"file:///repos"}]' \ -e SM121_LAUNCHER_URL="file:///src-launcher" \ -e SM121_LAUNCHER_REV=HEAD \ -e SM121_SSH_USER=u \ -e SM121_WEB_TOKEN="$TOKEN" \ "$IMG")" trap 'docker rm -f "$CID" >/dev/null 2>&1 || true; rm -rf "$REPO"' EXIT # Wait for the dashboard (up to 8 min — the first run compiles sm121 from # source; a warm cache is seconds). ok="" for _ in $(seq 1 480); do if curl -sf -H "Authorization: Bearer $TOKEN" \ http://127.0.0.1:3100/api/state >/dev/null 2>&1; then ok=1 break fi sleep 1 done echo "--- container log (tail) ---" docker logs "$CID" 2>&1 | tail -5 if [ -n "$ok" ]; then echo "--- /api/state (first 200 chars) ---" curl -sf -H "Authorization: Bearer $TOKEN" http://127.0.0.1:3100/api/state | head -c 200 echo echo "smoke OK: the add-on dashboard answered on 3100" else echo "smoke FAILED: no answer on 3100" >&2 exit 1 fi