#!/usr/bin/env bash
# Build the Phase 0 CLI image for linux/amd64 (Unraid target).
# Works from an arm64 Mac via buildx + QEMU emulation (slow first time).
set -euo pipefail
cd "$(dirname "$0")"

IMAGE="${IMAGE:-step-parser}"
TAG="${TAG:-dev}"
PLATFORM="${PLATFORM:-linux/amd64}"
REGISTRY="${REGISTRY:-registry.alwisp.com/jason}"

echo "Building ${IMAGE}:${TAG} for ${PLATFORM} ..."
docker buildx build --platform "${PLATFORM}" -t "${IMAGE}:${TAG}" --load .

cat <<EOF

Built ${IMAGE}:${TAG}.

Next:
  ./smoke-test.sh                      # validate the kernel + render + diagram
  docker run --rm --entrypoint pip ${IMAGE}:${TAG} freeze > requirements.lock.txt

Push to the Unraid registry once green:
  docker tag ${IMAGE}:${TAG} ${REGISTRY}/${IMAGE}:latest
  docker push ${REGISTRY}/${IMAGE}:latest
EOF
