# tidalDB cluster server image — PACKAGING ONLY (no in-container compile).
#
# Committed promotion of tmp/img-build/Dockerfile. The `tidal-server` binary in
# the build context is a HOST cross-compile (mac-arm64 -> x86_64-unknown-linux-gnu)
# produced by scripts/build-release.sh. It NEEDs libmvec.so.1 (glibc 2.41
# vectorized math), so the runtime base MUST be trixie (glibc 2.41) — bookworm
# (2.36) lacks libmvec and aborts at startup. Verified NEEDED: libstdc++.so.6,
# libgcc_s.so.1, libmvec.so.1 + glibc.
#
# Built by scripts/build-release.sh via the amd64 buildx builder. Do not build by
# hand — the script pins the toolchain + digests the result.
FROM debian:trixie-slim

ARG DEBIAN_FRONTEND=noninteractive

# usearch's HNSW C++ core needs the C++ runtime; ca-certificates/curl for TLS +
# operator healthchecks. glibc (incl. libmvec.so.1) ships in the base image.
RUN apt-get update && \
    apt-get install -y --no-install-recommends libstdc++6 libgcc-s1 ca-certificates curl && \
    rm -rf /var/lib/apt/lists/*

# Non-root, uid 10001 to match the StatefulSet securityContext (runAsUser 10001,
# fsGroup 10001) and the init-datadir chown.
RUN useradd --system -u 10001 --home /srv tidal

COPY --chown=tidal:tidal tidal-server /usr/local/bin/tidal-server
COPY --chown=tidal:tidal config /etc/tidal-server

USER tidal
WORKDIR /srv
EXPOSE 9500 9601 9091

# Self-contained config path (overridden at runtime by the StatefulSet's explicit
# --schema/--topology flags pointing at mounted ConfigMaps).
ENV TIDAL_CONFIG=/etc/tidal-server
ENV TIDAL_SERVER_LOG=info
# Cluster mode is gated experimental; the StatefulSet also sets this.
ENV TIDAL_ALLOW_EXPERIMENTAL_CLUSTER=1

# Bare binary ENTRYPOINT so `docker run img verify ...`/subcommand overrides work;
# the StatefulSet supplies the full `cluster ...` argv.
ENTRYPOINT ["tidal-server"]
CMD ["cluster", "--listen", "0.0.0.0:9500", \
     "--schema", "/etc/tidal-server/default-schema.yaml", \
     "--topology", "/etc/tidal-server/default-cluster.yaml"]
