N7: Dedicated server packaging, health endpoint and graceful shutdown

- packaging/server/tidewall-server: a wrapper that turns SIGTERM and SIGINT
  into a clean stop through the server's new --stop-file, since the engine
  can't catch signals. The server tells everyone it shut down, logs its
  statistics and exits 0; the wrapper kills it only after 15 s.
- --config=PATH reads options from a file (packaging/server/server.cfg);
  options after it on the command line win.
- --health-port answers GET /health with JSON (phase, players, tick, uptime)
  on loopback by default. HealthServer is non-blocking and bounded.
- packaging/docker: a debian:13 image that checks the engine against
  tools/engine.sha512, imports the game at build time, runs as an unprivileged
  user, and works with a read-only root and a small /tmp. compose.yaml is
  project and container tidewall-server, read-only, no capabilities.
- packaging/systemd: a hardened unit with a dynamic user.
- make server-package-check: compose up, healthy, non-root, read-only, a real
  headless client joins over UDP into the drop, then SIGTERM stops it cleanly.

This also covers H7 (graceful shutdown on SIGTERM).

Closes #38
Closes #70

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 22:07:24 -05:00
co-authored by Claude Opus 5.5
parent 05c7568ec1
commit 8eb6e587fb
17 changed files with 644 additions and 2 deletions
+45
View File
@@ -0,0 +1,45 @@
# A Tidewall dedicated server image. Build it from the repository's root, which must
# hold the pinned engine in tools/godot/ (see tools/godot.sh):
#
# docker build -f packaging/docker/Dockerfile -t tidewall-server:dev .
#
# or let packaging/docker/compose.yaml do it. The engine is checked against
# tools/engine.sha512 before it goes in. The game is imported while building, so at
# run time the image needs no writable filesystem apart from a small /tmp.
FROM debian:13
ARG ENGINE=tools/godot/Godot_v4.7.2-stable_linux.x86_64
RUN groupadd --system --gid 10650 tidewall \
&& useradd --system --uid 10650 --gid tidewall --home-dir /nonexistent --no-create-home --shell /usr/sbin/nologin tidewall
COPY tools/engine.sha512 /tmp/engine.sha512
COPY ${ENGINE} /opt/tidewall/engine/godot
RUN expected="$(awk '$2 ~ /_linux\.x86_64$/ { print $1 }' /tmp/engine.sha512)" \
&& actual="$(sha512sum /opt/tidewall/engine/godot | cut -d' ' -f1)" \
&& [ -n "$expected" ] && [ "$expected" = "$actual" ] \
&& chmod 0755 /opt/tidewall/engine/godot \
&& rm /tmp/engine.sha512
COPY project.godot LICENSE LICENSE-ASSETS /opt/tidewall/game/
COPY src /opt/tidewall/game/src
COPY data /opt/tidewall/game/data
COPY packaging/server/tidewall-server /usr/local/bin/tidewall-server
COPY packaging/server/server.cfg /etc/tidewall/server.cfg
# Import once here, so the server never has to write into the game's directory.
RUN XDG_DATA_HOME=/tmp/import XDG_CONFIG_HOME=/tmp/import XDG_CACHE_HOME=/tmp/import \
/opt/tidewall/engine/godot --headless --path /opt/tidewall/game --import --quit >/dev/null 2>&1 ; \
test -d /opt/tidewall/game/.godot \
&& rm -rf /tmp/import \
&& chmod 0755 /usr/local/bin/tidewall-server
USER tidewall
ENV TIDEWALL_STATE=/tmp/tidewall-server
# Game traffic, LAN discovery, and the health check (TCP, on loopback by default).
EXPOSE 24650/udp 24651/udp
STOPSIGNAL SIGTERM
HEALTHCHECK --interval=10s --timeout=3s --start-period=20s --retries=3 \
CMD ["bash", "-c", "exec 3<>/dev/tcp/127.0.0.1/24650 && printf 'GET /health HTTP/1.0\\r\\n\\r\\n' >&3 && head -n 1 <&3 | grep -q ' 200 '"]
ENTRYPOINT ["/usr/local/bin/tidewall-server"]
CMD ["--config=/etc/tidewall/server.cfg"]