# SPDX-License-Identifier: AGPL-3.0-or-later WITH AdditionRef-SemiSpelunker-Addon-Exception
#
# The game and its multiplayer server in one image: the server serves the client's build
# at / and the universe over WebSockets on the same port (see docs/deployment.md).

FROM node:22-slim AS build
WORKDIR /app
RUN corepack enable
# Dependencies first, so they're cached while only the source changes.
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY packages/shared/package.json packages/shared/
COPY packages/client/package.json packages/client/
COPY packages/server/package.json packages/server/
COPY addons/core/package.json addons/core/
RUN pnpm install --frozen-lockfile
COPY . .
RUN pnpm build

FROM node:22-slim
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app /app
# Saves (checkpoints and backups) live here: mount a volume on it.
RUN mkdir -p /data && chown node:node /data
USER node
VOLUME /data
EXPOSE 8787
WORKDIR /app/packages/server
ENTRYPOINT ["node", "src/main.ts", "--host", "0.0.0.0", "--port", "8787", "--saves", "/data", "--client", "/app/packages/client/dist"]
# The universe's settings (the seed and rules only matter the first time it's made).
CMD ["--seed", "1234", "--death", "drop"]
