FROM node:22-slim

WORKDIR /app

# The daemon shells out to the system `git` binary at runtime (git is the vault
# state store), but node:22-slim does NOT ship git. Install it and KEEP it in
# the final image. Placed before `npm ci` so this layer caches across rebuilds.
# `npm prune --omit=dev` below cannot remove this — it is an OS package, not an
# npm dependency.
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*

# 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"]
