# syntax=docker/dockerfile:1.7
# SparkRing shared stack (FujitsuPolycom/sparkring) as a sm121-managed image.
#
# The public image is published digest-only (no tags), so a raw pull leaves an
# untagged image that (a) sm121's image-presence probe cannot match by tag and
# (b) `docker image prune` reaps as dangling. Wrapping it in a thin FROM with
# a local tag puts it under the normal sm121 build/sync flow: built once on a
# build node, `docker save | ssh docker load` to the rest, checksum-label
# stamped, and safe from prune.
#
# No stages, no layers: the entire runtime lives upstream of the FROM.
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
LABEL sm121.source="ghcr.io/fujitsupolycom/sparkring" sm121.digest="sha256:f25cdb6bf7df85754ea5c62445b139dac3143bc6e910a0442d681b6e63c31c4b"

# The b12x loader JIT-compiles _storage.c with `-L/opt/cuda-13.3/lib64 -lcudart`,
# but this CUDA 13 image ships libcudart only as pip nvidia/cu13/lib/libcudart.so.13
# (no lib64 dir, no dev symlink) — the first serve attempt dies with
# "ld: cannot find -lcudart". Bridge it, then pre-build the extension so the
# runtime cache is baked into the image and serves never hit the JIT.
RUN set -eux; \
    mkdir -p /opt/cuda-13.3/lib64; \
    ln -s /usr/local/lib/python3.12/dist-packages/nvidia/cu13/lib/libcudart.so.13 /opt/cuda-13.3/lib64/libcudart.so; \
    python3 -c "import b12x.loader._native as n; n.load(); print('b12x loader native pre-built')"
