#!/usr/bin/env bash
# build201.sh ARM CACHE CMD...: GPU-free Triton compile on box 201's build slot (build lock, capped), tree src_ARM,
# writing TRITON_CACHE_DIR=~/gdn-commit/CACHE.
set -euo pipefail
W=$HOME/gdn-commit; IMG=local/arbi-serve:main-43d0876; SP=/opt/venv/lib/python3.12/site-packages
ARM=$1; CACHE=$2; shift 2; t=$W/src_$ARM; mkdir -p $W/$CACHE
exec flock -w 7200 /run/lock/arbi-build.lock \
  docker run --rm --name gdn-commit-build --memory 4g --cpus 4 --user "$(id -u):$(id -g)" \
    -e PYTHONUNBUFFERED=1 -e HOME=/tmp -e PYTHONPYCACHEPREFIX=/tmp/pycache -e TRITON_CACHE_DIR=/tcache -e PYTHONPATH=/src \
    -v $t/arbi_serve:$SP/arbi_serve:ro -v $W/$CACHE:/tcache -v $W/aot_br:/aot -v $W/scripts:/scripts:ro -v $t:/src:ro -w /src \
    --entrypoint bash "$IMG" -c "$*"
