build.sh 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. # Build the TensorFold 2x 1017 image (upstream sources at pins + their Dockerfile).
  3. #
  4. # Uses the classic docker builder (not buildx docker-container): the base
  5. # image dsv41-flash:local is local-only (never pushed to a registry), and
  6. # the container-driver builder cannot resolve local FROM references.
  7. #
  8. # Generic driver: forwards every KEY=VAL pin in versions.env as a
  9. # --build-arg to the Dockerfile (no hardcoded variable list). The sm121
  10. # launcher writes a merged versions.env here when a recipe carries
  11. # [build.versions] overrides (recipe wins over the image defaults).
  12. set -euo pipefail
  13. cd "$(dirname "$0")"
  14. TAG="${TAG:-dsv41-tf-1017:v1}"
  15. SRC="${SRC:-/tmp/dsv41-tf-1017-src}"
  16. # Sources are fetched OUTSIDE this directory (keeps the image-dir checksum stable).
  17. bash ./fetch-sources.sh "$SRC"
  18. cp Dockerfile "$SRC/Dockerfile"
  19. ARGS=()
  20. while IFS= read -r line; do
  21. # Skip blank lines and comments (# ...).
  22. case "$line" in
  23. ''|\#*) continue ;;
  24. esac
  25. key="${line%%=*}"
  26. val="${line#*=}"
  27. [ -n "$key" ] && ARGS+=(--build-arg "${key}=${val}")
  28. done < versions.env
  29. echo "=== Building ${TAG} ==="
  30. docker build "${ARGS[@]}" --progress=plain -t "${TAG}" -f "$SRC/Dockerfile" "$SRC" 2>&1
  31. echo "=== Done: ${TAG} ==="
  32. # Publish the host-side helper files next to the model cache so the launch
  33. # nodes can stage (chat template, Engram packer, CUDA prebuild) WITHOUT needing
  34. # the image first — serve runs before_serve hooks before it syncs the image.
  35. PUB="${SM121_TF1017_PUBDIR:-/mnt/nas/ai/sm121/dsv41-tf-1017}"
  36. if mkdir -p "$PUB" 2>/dev/null; then
  37. for f in pack_engram.py prebuild_ext.py prebuild-offline.py pfdense-table.json chat_template.jinja; do
  38. cp -f "$SRC/upstream/$(case $f in
  39. pack_engram.py) echo build/jayleaton/scripts/pack_engram.py ;;
  40. prebuild_ext.py) echo build/jayleaton/scripts/prebuild_ext.py ;;
  41. prebuild-offline.py) echo scripts/prebuild-offline.py ;;
  42. pfdense-table.json) echo build/jayleaton/config/pfdense-table.json ;;
  43. chat_template.jinja) echo build/mia-runtime/files/chat_template.jinja ;;
  44. esac)" "$PUB/$f"
  45. done
  46. echo "$TAG" > "$PUB/IMAGE_TAG"
  47. echo "=== helpers published to $PUB ==="
  48. fi