# panel-native 7 Days to Die runtime image.
#
# Unlike third-party images (vinanrra/LGSM, didstopia, etc.), this image does
# ONE thing: run a 7DTD dedicated server. Download + validate is handled by
# the panel's SteamCMD updater sidecar, which writes into the same Docker
# volume we mount read/write here. No LGSM, no tmux, no GitHub-fetch on
# start, no backup-before-start "surprises" — just the game.
#
# Expected runtime layout inside the container:
#   /game           — SteamCMD-installed 7DTD binaries (panel volume)
#   /game-saves     — save + config data (panel volume)
#   /entrypoint.sh  — this image's entrypoint (renders serverconfig.xml and
#                     execs the game with stdout/stderr unbuffered)

FROM debian:12-slim

ENV DEBIAN_FRONTEND=noninteractive \
    TZ=Etc/UTC \
    LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8

# Runtime deps 7DTD's Linux build needs. lib32* for the 32-bit Steam bits,
# libxi/libxrandr for the server's Unity runtime probes, ca-certs so any
# outbound HTTPS (analytics, steam auth) resolves.
RUN dpkg --add-architecture i386 \
 && apt-get update \
 && apt-get install -y --no-install-recommends \
    ca-certificates \
    locales \
    tini \
    lib32gcc-s1 \
    lib32stdc++6 \
    libc6:i386 \
    python3-minimal \
 && sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
 && locale-gen \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

# Unprivileged user that owns /game. The updater sidecar writes as root, so
# at start time we chown once to panel (cheap since SteamCMD leaves a known
# set of files). This keeps the long-running game process non-root.
RUN groupadd -g 1000 panel \
 && useradd -u 1000 -g 1000 -m -s /bin/bash panel \
 && mkdir -p /game /game-saves \
 && chown -R panel:panel /game /game-saves

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Vendored nim-tools: the in-container decoration remapper used by the cluster
# auto-provision step in entrypoint.sh. Self-contained (nimtool.read_nim inlined),
# python3-minimal (above) is its only dependency. A new clustered world's native
# decorations are remapped to the cluster canonical here so it loads clean.
COPY nim-freeze/remap_7dt.vendored.py /opt/panel-nimtools/remap_7dt.py

# Panel-owned helper mod — exposes blood-moon status as a JSON file the
# scheduler reads to defer restarts through hordes. Lives in /opt so the
# entrypoint can copy it into /game/Mods/ on every boot (so a steam
# validate or operator overwrite re-seeds it).
COPY mod-source/PanelBloodMoonAgent/bin/Release/net48/PanelBloodMoonAgent.dll /opt/panel-mods/PanelBloodMoonAgent/PanelBloodMoonAgent.dll
COPY mod-source/PanelBloodMoonAgent/ModInfo.xml                                /opt/panel-mods/PanelBloodMoonAgent/ModInfo.xml

# Game UDP ports — published by the panel manifest at run time.
EXPOSE 26900/udp 26901/udp 26902/udp
# Telnet RCON
EXPOSE 8081/tcp

# tini reaps zombies + forwards signals cleanly so our SIGTERM → graceful stop
# actually lands on the 7DTD process (otherwise docker stop becomes kill -9).
ENTRYPOINT ["/usr/bin/tini", "--", "/entrypoint.sh"]
