# Local dev backend: smartbotic-database + smartbotic-vectorapi from the release
# .debs. Native builds are impossible on the Void dev host (protobuf 35 removed
# a header the generated protos need), so the Debian 13 image is the only way to
# run the real stack locally. The web UI is served by Vite in dev, not from here.
#
# The versions are ARGs and are ASSERTED rather than assumed: fetch-debs.sh
# stages exactly the ones named, and the RUN below fails the build if any is
# missing. Installing whatever happens to be in debs/ is how a "prod-faithful"
# image quietly stops being faithful.
FROM debian:13

ARG DB_VERSION
ARG DB_CLIENT_VERSION
ARG VAPI_VERSION

# adduser is needed by both postinst scripts; systemctl is not present in a
# container, so a no-op shim lets the packages configure cleanly. The services
# are started by the entrypoint instead. libidn2-0 is a real NEEDED library of
# the runner's vendored curl; jq and procps are for measuring from inside.
RUN apt-get update && apt-get install -y --no-install-recommends \
      ca-certificates curl adduser libidn2-0 jq procps \
    && rm -rf /var/lib/apt/lists/* \
    && printf '#!/bin/sh\nexit 0\n' > /usr/bin/systemctl && chmod +x /usr/bin/systemctl

COPY debs/ /tmp/debs/
RUN set -e; \
    if [ -n "$DB_VERSION" ]; then \
      for f in smartbotic-database_${DB_VERSION}_amd64.deb \
               libsmartbotic-db-client_${DB_CLIENT_VERSION}_amd64.deb \
               smartbotic-vectorapi_${VAPI_VERSION}_amd64.deb; do \
        [ -f "/tmp/debs/$f" ] || { echo "expected deb missing from build context: $f" >&2; exit 1; }; \
      done; \
    fi; \
    apt-get update && apt-get install -y --no-install-recommends /tmp/debs/*.deb \
    && rm -rf /var/lib/apt/lists/* /tmp/debs

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
EXPOSE 8080
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
