smoke-addon.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env bash
  2. # Smoke test for the sm121 add-on image (specs/tech-architecture/
  3. # ha-addon-recipe-repos.md, step 3): run the entrypoint with a `file://`
  4. # recipe repo (mounted) + a token, and assert the dashboard answers on
  5. # 3100 (curl /api/state).
  6. #
  7. # scripts/smoke-addon.sh [image] (default sm121-addon:latest)
  8. set -euo pipefail
  9. cd "$(dirname "$0")/.."
  10. IMG="${1:-sm121-addon:latest}"
  11. TOKEN=smoke-test
  12. # A minimal `file://` recipe repo, mounted read-only at /repos. It lives
  13. # under target/ (gitignored) so it sits on a volume the docker VM shares
  14. # — colima only mounts /Volumes here; a $HOME tmpdir would mount empty.
  15. REPO="$(pwd)/target/smoke-addon-repo"
  16. rm -rf "$REPO"; mkdir -p "$REPO"
  17. git init -q "$REPO"
  18. mkdir -p "$REPO/recipes/demo"
  19. echo 'engine = "vllm"' > "$REPO/recipes/demo/recipe.toml"
  20. git -C "$REPO" add -A
  21. git -C "$REPO" -c user.email=t@sm121.test -c user.name=sm121-test commit -qm init
  22. CID="$(docker run -d \
  23. -p 3100:3100 \
  24. -v "$REPO":/repos:ro \
  25. -e SM121_RECIPE_REPOS='[{"url":"file:///repos"}]' \
  26. -e SM121_SSH_USER=u \
  27. -e SM121_WEB_TOKEN="$TOKEN" \
  28. "$IMG")"
  29. trap 'docker rm -f "$CID" >/dev/null 2>&1 || true; rm -rf "$REPO"' EXIT
  30. # Wait for the dashboard (up to 30 s — the first sync is a clone).
  31. ok=""
  32. for _ in $(seq 1 30); do
  33. if curl -sf -H "Authorization: Bearer $TOKEN" \
  34. http://127.0.0.1:3100/api/state >/dev/null 2>&1; then
  35. ok=1
  36. break
  37. fi
  38. sleep 1
  39. done
  40. echo "--- container log (tail) ---"
  41. docker logs "$CID" 2>&1 | tail -5
  42. if [ -n "$ok" ]; then
  43. echo "--- /api/state (first 200 chars) ---"
  44. curl -sf -H "Authorization: Bearer $TOKEN" http://127.0.0.1:3100/api/state | head -c 200
  45. echo
  46. echo "smoke OK: the add-on dashboard answered on 3100"
  47. else
  48. echo "smoke FAILED: no answer on 3100" >&2
  49. exit 1
  50. fi