diff options
Diffstat (limited to 'Dockerfile')
| -rw-r--r-- | Dockerfile | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cd43d7c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +# X-Haven (web) — server + built web app (PLAN.md Phase 7). +# +# Three stages: +# 1. `web` — build the Svelte app (npm ci + vite build → dist/) +# 2. `server` — compile the Dart server to a standalone native binary +# 3. runtime — debian-slim + the binary + the game assets + the web build +# +# Build and run: +# docker build -t xhaven . +# docker run --rm -p 4567:4567 -v xhaven-saves:/app/saves xhaven +# +# See docs/DEPLOYMENT.md for configuration, persistence, and scaling notes. + +# --- 1. web build --------------------------------------------------------- +FROM node:22 AS web +WORKDIR /web +COPY web/package.json web/package-lock.json ./ +RUN npm ci --no-audit --no-fund +COPY web/ . +RUN npm run build + +# --- 2. server build ------------------------------------------------------- +FROM dart:3.11 AS server +WORKDIR /server +COPY server/pubspec.yaml server/pubspec.lock ./ +RUN dart pub get +COPY server/ . +# Standalone native binary — the runtime image needs no Dart SDK. +RUN dart compile exe bin/main.dart -o /out/xhaven-server + +# --- 3. runtime ------------------------------------------------------------- +FROM debian:bookworm-slim +# ca-certificates only: no SDK, no package manager residue. +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app +COPY --from=server /out/xhaven-server /app/xhaven-server +COPY server/assets/ /app/assets/ +COPY --from=web /web/dist /app/web/dist + +# The game state (game.json, seats.json, settings.json, saves/) lives in a +# volume so a redeploy keeps the game. +ENV PORT=4567 +EXPOSE 4567 +VOLUME ["/app/saves"] + +# bash is in the base image; /dev/tcp gives a dependency-free health probe. +HEALTHCHECK --interval=30s --timeout=5s --start-period=15s \ + CMD bash -c 'exec 3<>/dev/tcp/127.0.0.1/${PORT:-4567}' || exit 1 + +CMD ["/app/xhaven-server", "--port=4567", "--static-dir=/app/web/dist", "--saves-dir=/app/saves", "--data-dir=/app/assets/data/"] |
