FROM node:22-slim

WORKDIR /app

# Dependencies first (better layer caching): copy the root manifest, the lock,
# and the workspace package manifest so `npm ci` can link the workspace.
COPY package.json package-lock.json ./
COPY packages/docmost-client/package.json packages/docmost-client/package.json
RUN npm ci

# Runtime state directory (mounted as a volume in production).
RUN mkdir -p data

# Source + TS config, then build the workspace lib and compile the app to build/.
COPY tsconfig.json tsconfig.base.json ./
COPY packages/ packages/
COPY src/ src/
RUN npm run build

# Drop dev dependencies (typescript, tsx, vitest) to slim the runtime image.
RUN npm prune --omit=dev

CMD ["node", "build/index.js"]
