# panel-native Empyrion runtime image.
#
# Empyrion's dedicated server is a Windows-only Unity build, so we bring
# along just enough Wine + Xvfb to host it headlessly. SteamCMD is NOT
# installed here — the panel's generic updater sidecar uses the official
# steamcmd image and writes into our /game volume.
#
# Expected runtime layout inside the container:
#   /game                                      — SteamCMD-installed Windows build (panel volume)
#   /game/DedicatedServer/DedicatedServer64/
#     EmpyrionDedicated.exe                    — the dedicated server binary
#   /game-saves                                — saves, dedicated.yaml, admin files
#   /entrypoint.sh                             — boot Xvfb, launch exe under Wine

FROM debian:12-slim

ENV DEBIAN_FRONTEND=noninteractive \
    TZ=Etc/UTC \
    LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8 \
    WINEDEBUG=-all \
    WINEPREFIX=/home/panel/.wine \
    DISPLAY=:99

# Wine pulls in ~500 MB of deps; keep to the 64-bit stack (Empyrion's
# dedicated binary is x86_64). winetricks isn't strictly required — the
# game's Mono runtime ships with the install — but it's 8 MB and saves
# future debugging headaches.
RUN dpkg --add-architecture i386 \
 && apt-get update \
 && apt-get install -y --no-install-recommends \
    ca-certificates \
    locales \
    tini \
    curl \
    xvfb \
    xauth \
    wine64 \
    wine \
    winbind \
    cabextract \
    procps \
 && 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 owning /game + /game-saves. The SteamCMD sidecar
# writes as root (official image runs as root); we chown once at start
# time so the long-running game process stays 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 /home/panel

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

# Pre-staged EPM mod (TCP relay for the Eleon Mod API). Entrypoint copies
# this into /game/Content/Mods/EPM/ on first boot so every empyrion
# instance comes EAH-bridge-ready out of the box. See modules/empyrion/epm-mod/.
COPY epm-mod/ /opt/panel-epm/

# Empyrion default ports (see module.yaml comment for reference).
EXPOSE 30000/udp 30001/udp 30002/udp 30003/udp
EXPOSE 30004/tcp

ENTRYPOINT ["/usr/bin/tini", "--", "/entrypoint.sh"]
