# The database exactly as it runs on the host today.
#
# Not built from the .deb in the package repo: that one is a later build linked
# against Abseil 20240722, while the host's binary - the one whose data this is
# and whose behaviour is known - links 20260107. Installing the .deb produced a
# container that could not start at all. The host's own files are copied in
# instead, onto the same Ubuntu release the host runs, so the libraries match.
FROM ubuntu:26.04

# Runtime dependencies, from the package list the .deb declares plus what the
# client library pulls in.
RUN apt-get update \
 && apt-get install -y --no-install-recommends \
      libssl3t64 liblz4-1 libsystemd0 libjemalloc2 libyyjson0 liblmdb0 \
      libprotobuf32t64 libgrpc++1.51t64 libspdlog1.15 libfmt10 ca-certificates \
 && rm -rf /var/lib/apt/lists/*

COPY hostbin/smartbotic-database /usr/bin/smartbotic-database
COPY hostbin/libsmartbotic-db-client.so* /usr/lib/x86_64-linux-gnu/
RUN ldconfig && ldd /usr/bin/smartbotic-database | grep -q "not found" && exit 1 || true

# Matching the host unit, which sets these to stop the allocator holding on to
# freed memory - the reason this is being moved off that machine at all.
ENV MALLOC_ARENA_MAX=2
ENV MALLOC_CONF=background_thread:true,dirty_decay_ms:1000,muzzy_decay_ms:1000

# The encryption key lives inside the data directory, so the data and the key
# that reads it are never separated.
VOLUME ["/var/lib/smartbotic-database"]
EXPOSE 9004

ENTRYPOINT ["/usr/bin/smartbotic-database", "--config", "/etc/smartbotic-database/config.json"]
