# ========================================== # STAGE 1: Build Environment (Temporary) # ========================================== FROM python:3.10-slim AS builder RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ cmake \ libopenblas-dev \ liblapack-dev \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # The builder ONLY needs pybind11 to compile the C++ code! RUN pip install --no-cache-dir pybind11 # Copy only what your engine needs COPY CMakeLists.txt ./ COPY src/ ./src COPY include/ ./include RUN mkdir build && cd build && \ cmake -DCMAKE_BUILD_TYPE=Release .. && \ make vecmini # ========================================== # STAGE 2: Final Runtime Environment (Your App) # ========================================== FROM python:3.10-slim RUN useradd -m -u 1000 user WORKDIR /home/user/app # Install runtime C++ math dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ libopenblas0 \ libomp-dev \ && rm -rf /var/lib/apt/lists/* # Copy the compiled .so module directly into the Python environment COPY --from=builder /app/build/vecmini*.so /home/user/app/ # Copy your frontend code (app.py) COPY --chown=user . /home/user/app # IMPORTANT: This is where ALL the runtime Python packages go! RUN pip install --no-cache-dir gradio numpy pypdf transformers torch urllib3 --extra-index-url https://download.pytorch.org/whl/cpu ENV PORT=7860 EXPOSE 7860 CMD ["python", "app.py"]