# lore-server container image.
# Build from the repo root:  docker build -f deploy/Dockerfile -t lore .
# Normally used via deploy/compose.yaml (server + Ollama + volumes).
# Stage 1: build the web dashboard (served by lore-server at /).
FROM node:22-slim AS webui
WORKDIR /web
COPY web/package.json web/package-lock.json ./
RUN npm ci
COPY web/ ./
# vite.config.ts outputs to ../src/lore/webui, i.e. /src/lore/webui here.
RUN npm run build

FROM python:3.11-slim

WORKDIR /app

# Install the package (hatchling build includes src/lore + built-in task
# templates). Wheels exist for all heavy deps (chromadb, pymupdf,
# tree-sitter) so no build toolchain is needed in the image.
COPY pyproject.toml README.md ./
COPY src ./src
COPY --from=webui /src/lore/webui ./src/lore/webui
# The package version comes from git tags (hatch-vcs), but .git isn't copied
# into the image — CI passes the tag via LORE_VERSION; local builds get a dev
# version.
ARG LORE_VERSION=0.0.0.dev0
RUN SETUPTOOLS_SCM_PRETEND_VERSION="$LORE_VERSION" pip install --no-cache-dir .

# All state (config, SQLite, vector store, logs) lives under the volume.
ENV LORE_HOME=/data/lore \
    LORE_HOST=0.0.0.0 \
    LORE_PORT=5673
VOLUME /data
EXPOSE 5673

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s CMD \
    python -c "import urllib.request as u; u.urlopen('http://127.0.0.1:5673/health', timeout=3)" \
    || exit 1

CMD ["python", "-m", "lore.server"]
