smoke-addon.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env bash
  2. # Smoke test for the sm121 add-on image (specs/tech-architecture/
  3. # ha-addon-recipe-repos.md): build the image from the sibling add-on repo
  4. # (rust:alpine compiles sm121 from THIS checkout → static musl binary →
  5. # alpine final), run the entrypoint with a `file://` recipe repo
  6. # (mounted), and assert the dashboard answers on 3100 (curl /api/state).
  7. #
  8. # scripts/smoke-addon.sh [image] (default sm121-addon:latest)
  9. set -euo pipefail
  10. cd "$(dirname "$0")/.."
  11. IMG="${1:-sm121-addon:latest}"
  12. TOKEN=smoke-test
  13. # The image source lives in the sibling add-on repo (the HA add-on store).
  14. # Build it locally if it isn't there yet (CI builds the registry one).
  15. # The Dockerfile's rust:alpine stage compiles the launcher from
  16. # launcher-src/ in the build context — rsync this checkout there.
  17. HA_REPO="../sm121-ha-integration"
  18. if ! docker image inspect "$IMG" >/dev/null 2>&1; then
  19. echo "building $IMG (launcher source → $HA_REPO/launcher-src/)"
  20. rm -rf "$HA_REPO/launcher-src"
  21. rsync -a --exclude .git --exclude target ./ "$HA_REPO/launcher-src/"
  22. docker build -q -t "$IMG" -f "$HA_REPO/sm121/Dockerfile" "$HA_REPO/"
  23. fi
  24. # A minimal `file://` recipe repo, mounted read-only at /repos. It lives
  25. # under target/ (gitignored) so it sits on a volume the docker VM shares
  26. # — colima only mounts /Volumes here; a $HOME tmpdir would mount empty.
  27. REPO="$(pwd)/target/smoke-addon-repo"
  28. rm -rf "$REPO"; mkdir -p "$REPO"
  29. git init -q "$REPO"
  30. mkdir -p "$REPO/recipes/demo"
  31. echo 'engine = "vllm"' > "$REPO/recipes/demo/recipe.toml"
  32. git -C "$REPO" add -A
  33. git -C "$REPO" -c user.email=t@sm121.test -c user.name=sm121-test commit -qm init
  34. # Persistent HOME (the add-on data folder in HA; here: the sm121 cache
  35. # dir — ~/.cache/sm121 — so re-runs reuse the recipe-repo cache).
  36. HOMEV="$(pwd)/target/smoke-addon-home"
  37. mkdir -p "$HOMEV"
  38. CID="$(docker run -d \
  39. -p 3100:3100 \
  40. -v "$REPO":/repos:ro \
  41. -v "$HOMEV":/root \
  42. -e SM121_RECIPE_REPOS='[{"url":"file:///repos"}]' \
  43. -e SM121_SSH_USER=u \
  44. -e SM121_WEB_TOKEN="$TOKEN" \
  45. "$IMG")"
  46. trap 'docker rm -f "$CID" >/dev/null 2>&1 || true; rm -rf "$REPO"' EXIT
  47. # First boot is fast now (the binary ships in the image — just the
  48. # recipe-repo sync); give it 60 s to be safe.
  49. ok=""
  50. for _ in $(seq 1 60); do
  51. if curl -sf -H "Authorization: Bearer $TOKEN" \
  52. http://127.0.0.1:3100/api/state >/dev/null 2>&1; then
  53. ok=1
  54. break
  55. fi
  56. sleep 1
  57. done
  58. echo "--- container log (tail) ---"
  59. docker logs "$CID" 2>&1 | tail -5
  60. if [ -n "$ok" ]; then
  61. echo "--- /api/state (first 200 chars) ---"
  62. curl -sf -H "Authorization: Bearer $TOKEN" http://127.0.0.1:3100/api/state | head -c 200
  63. echo
  64. echo "smoke OK: the add-on dashboard answered on 3100"
  65. else
  66. echo "smoke FAILED: no answer on 3100" >&2
  67. exit 1
  68. fi