# Printhive — Node app + Python/trimesh sidecar (for 3MF -> GLB conversion)
FROM node:22-bookworm-slim

# Python is needed at runtime for the 3MF->GLB / volume sidecar.
RUN apt-get update \
    && apt-get install -y --no-install-recommends python3 python3-venv \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Tell the converter where Python lives (the venv built below).
ENV PYTHON_BIN=/app/tools/venv/bin/python

# Python sidecar deps (cached unless requirements.txt changes).
COPY tools/requirements.txt ./tools/requirements.txt
RUN python3 -m venv /app/tools/venv \
    && /app/tools/venv/bin/pip install --no-cache-dir -r tools/requirements.txt

# Node deps (cached unless package files change).
COPY package.json package-lock.json ./
RUN npm ci --omit=dev \
    # semantic search only needs onnxruntime's Linux binaries (saves ~130 MB)
    && rm -rf node_modules/onnxruntime-node/bin/napi-v3/darwin node_modules/onnxruntime-node/bin/napi-v3/win32

# App source.
COPY . .

# The embedding model for semantic search (~34 MB), fetched at build time so the
# server never has to download it.
ENV MODELS_DIR=/app/models
RUN node -e "require('./lib/embeddingModel').load().then(() => console.log('embedding model ready'))"

ENV NODE_ENV=production \
    PORT=3000
EXPOSE 3000

CMD ["node", "server.js"]
