# panel-native Rust runtime image.
#
# Rust's dedicated server is a native Linux binary (SteamCMD app 258550),
# so no Wine. We need:
#   - 32-bit runtime libs (RustDedicated is ELF64 but loads steamclient.so
#     which pulls in 32-bit deps).
#   - tini for signal forwarding (server does a graceful "Saving..." + exit
#     on SIGTERM when its RCON is unreachable).
#   - SDL/GL shims — Rust dedicated server does NOT need a display, but it
#     dlopens libGL and a couple of X libs at startup; we ship the stubs.
#
# Expected runtime layout inside the container:
#   /game                              — SteamCMD install (panel volume)
#   /game/RustDedicated                — server binary
#   /game/server/<identity>/           — world + save data (symlinked to /game-saves)
#   /game-saves                        — save + logs volume
#   /entrypoint.sh                     — boot script (seeds cfg, launches binary)

FROM debian:12-slim

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

RUN dpkg --add-architecture i386 \
 && apt-get update \
 && apt-get install -y --no-install-recommends \
    ca-certificates \
    locales \
    tini \
    curl \
    lib32gcc-s1 \
    lib32stdc++6 \
    libc6:i386 \
    libgdiplus \
    libgl1 \
    libx11-6 \
    libxcursor1 \
    libxext6 \
    libxi6 \
    libxrandr2 \
    libxrender1 \
    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/*

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

# Rust default ports (see module.yaml comment for reference).
EXPOSE 28015/udp 28016/tcp 28082/tcp

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