# Headless Mirror game server for JustDifferent-JD.
#
# Build the Unity Linux dedicated server FIRST (from the repo root):
#   JD > Build > Linux Dedicated Server        (Editor menu)
# or
#   Unity -quit -batchmode -projectPath . -executeMethod HeadlessServerBuild.BuildLinuxServer
#
# Then, from the repo root:
#   docker build -f server/gameserver/Dockerfile -t jd-gameserver .
#   docker run --rm --env-file server/.env -p 25565:25565/udp jd-gameserver
#
# Modelled on Mirror's own Edgegap image (Assets/Mirror/Hosting/Edgegap/Editor/Dockerfile).

FROM ubuntu:22.04

# Unity Linux players need libc6-dev and libgcc; ca-certificates is required for
# the HTTPS calls to Nakama in production.
RUN apt-get update \
 && apt-get install -y --no-install-recommends \
      ca-certificates \
      libc6-dev \
      libgcc-s1 \
 && rm -rf /var/lib/apt/lists/*

# Run unprivileged. A game server is internet-facing and has no reason to be root.
RUN useradd --create-home --shell /bin/bash gameserver

WORKDIR /app

COPY Builds/LinuxServer/ /app/
COPY server/gameserver/entrypoint.sh /app/entrypoint.sh

RUN chmod +x /app/JDGameServer /app/entrypoint.sh \
 && chown -R gameserver:gameserver /app

USER gameserver

# KCP is UDP. Publishing this as TCP silently produces a server nobody can reach.
EXPOSE 25565/udp

ENTRYPOINT ["/app/entrypoint.sh"]
