# Station Master's multiplayer server, built from source — there is no published image to wrap.
# Source is the `station-master` git submodule, pinned to a tag; see UPDATING.md for how that pin
# is bumped. This Dockerfile never needs to change for a version bump, only the submodule ref.

# --- builder: produces the static browser client (dist/) ---
# The server itself has zero runtime dependencies (station-master/TODO.md), but `npm run
# build:web` shells out to `tsc`, which lives in devDependencies — hence the separate stage.
FROM node:22.23.1-slim AS builder
WORKDIR /build
COPY station-master/package.json station-master/package-lock.json ./
RUN npm ci
COPY station-master/ ./
RUN npm run build:web

# --- runtime: the server, no node_modules needed at all ---
FROM node:22.23.1-slim
WORKDIR /app
# Node >=22.18 strips TypeScript types natively (station-master/package.json's engines field),
# so the server runs straight from source with no build/compile step.
COPY station-master/package.json ./
COPY station-master/src/ ./src/
COPY --from=builder /build/dist/ ./dist/
CMD ["node", "src/server/index.ts"]
