#!/usr/bin/env bash # Build the tile-cache test fixture as a named Docker volume # (`tile-cache-fixture`), or emit it to a local directory in # ``--local `` mode (used by the AZ-407 unit tests). # # AC-1 (deterministic): two invocations against the same input emit # identical FAISS index hash, identical manifest rows, and identical # tile filesystem byte sizes. # # Env vars: # TILE_CACHE_INPUT_DIR Path to _docs/00_problem/input_data (required) # TILE_CACHE_VOLUME_NAME Docker volume name (default: tile-cache-fixture) # # Usage: # build.sh # builds the named Docker volume # build.sh --local /tmp/out # emits to /tmp/out (no Docker) set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)" VOLUME_NAME="${TILE_CACHE_VOLUME_NAME:-tile-cache-fixture}" INPUT_DIR="${TILE_CACHE_INPUT_DIR:-${REPO_ROOT}/_docs/00_problem/input_data}" LOCAL_OUT="" if [[ "${1:-}" == "--local" ]]; then if [[ -z "${2:-}" ]]; then echo "ERROR: --local requires an output directory" >&2 exit 2 fi LOCAL_OUT="$2" fi if [[ ! -d "${INPUT_DIR}" ]]; then echo "ERROR: input dir not found: ${INPUT_DIR}" >&2 exit 2 fi if [[ -n "${LOCAL_OUT}" ]]; then # Local mode: invoke builder.py directly. The caller's venv must # have Pillow, numpy, faiss-cpu installed; the unit test pulls # them via the dev extras. python3 "${SCRIPT_DIR}/builder.py" \ --input-dir "${INPUT_DIR}" \ --output-dir "${LOCAL_OUT}" exit 0 fi # Docker mode: build the builder image and populate the named volume. IMAGE_TAG="azaion-tile-cache-builder:local" docker build -t "${IMAGE_TAG}" "${SCRIPT_DIR}" # Recreate the named volume so output is bit-stable across runs (AC-1). docker volume rm "${VOLUME_NAME}" >/dev/null 2>&1 || true docker volume create "${VOLUME_NAME}" >/dev/null docker run --rm \ -v "${INPUT_DIR}:/input:ro" \ -v "${VOLUME_NAME}:/output" \ "${IMAGE_TAG}" echo "tile-cache-fixture volume '${VOLUME_NAME}' built from ${INPUT_DIR}"