# Sales Trainer — single-container runtime (Python 3.11 + Flask)
#
# The Vue frontend is BUILT LOCALLY (`cd frontend && npm run build`) and the
# resulting `frontend/dist/` is committed to the repo. This image does NOT run
# npm/node at all — it just copies the prebuilt SPA and serves it via Flask.
# This eliminates `vite: not found` / npm postinstall flakiness from the build.
#
# To update the UI: edit frontend/src, run `npm run build` locally, commit dist/.

FROM python:3.11-slim

# Runtime deps (none required beyond Python + pip packages; curl for healthcheck)
RUN apt-get update \
  && apt-get install -y --no-install-recommends curl ca-certificates \
  && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# 1) Copy prebuilt frontend SPA (built locally, committed to repo)
COPY frontend/dist/ ./frontend/dist/

# 2) Install backend deps
COPY backend/requirements.txt ./backend/
RUN pip install --no-cache-dir -r backend/requirements.txt

# 3) Copy backend source (and stub frontend dir so static serving finds dist)
COPY backend/ ./backend/

# Run
WORKDIR /app/backend
# Explicit data dir so operators mount a persistent volume here.
# Without a volume, ALL user data (incl. the admin password change from first-run
# setup) is lost on every container recreate -> re-login with the new password fails.
# Persist with:  docker run -v ./data:/app/backend/data  (or compose ./data)
ENV DATA_DIR=/app/backend/data
ENV FLASK_DEBUG=0
EXPOSE 5001
VOLUME ["/app/backend/data"]
CMD ["python", "run.py"]
