File size: 2,444 Bytes
327af4c
b408ef1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d3e10e
b408ef1
 
 
 
 
 
 
 
327af4c
 
 
1cc36e0
327af4c
 
 
b408ef1
 
 
327af4c
 
 
 
b23fddb
b408ef1
 
 
 
 
 
 
327af4c
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
FROM python:3.14-slim AS prod

ENV PYTHONUNBUFFERED=1 \
    UV_LINK_MODE=copy

WORKDIR /app

# Install system dependencies for document parsing, OCR, and native builds
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    cmake \
    curl \
    git \
    libgl1 \
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Install uv package manager
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

# Copy dependency specifications first for Docker layer caching
COPY pyproject.toml uv.lock* requirements.txt* packages.txt* README.md* /app/

# Install dependencies into system environment
RUN uv pip install --system -r requirements.txt

# Copy configuration, static assets, scripts and application source code
COPY config.toml /app/config.toml
COPY assets /app/assets
COPY scripts /app/scripts
COPY src /app/src
COPY app.py /app/app.py

# Optional build arg for CPU-only environments (e.g. CI runners lacking NVIDIA GPU drivers)
ARG INSTALL_CPU_LLAMA=false
RUN if [ "$INSTALL_CPU_LLAMA" = "true" ]; then \
        uv pip uninstall --system llama-cpp-python && \
        uv pip install --system "llama-cpp-python @ https://github.com/abetlen/llama-cpp-python/releases/download/v0.3.36/llama_cpp_python-0.3.36-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl"; \
    fi

# Install docneedle package itself without re-fetching dependencies
RUN uv pip install --system --no-deps .

# Pre-bake Hugging Face tokenizer cache into image layer for air-gapped offline execution
ENV HF_HOME=/app/hf-cache
RUN python -c "from transformers import AutoTokenizer; AutoTokenizer.from_pretrained('Qwen/Qwen3-Reranker-0.6B')"

# Port 7860 serves both the Gradio 6 Web Dashboard and the FastAPI REST API.
EXPOSE 7860

HEALTHCHECK --interval=30s --timeout=5s --start-period=45s --retries=3 \
    CMD curl -f http://localhost:7860/healthz || exit 1

# Start unified Gradio UI + FastAPI backend
CMD ["python", "app.py"]

# ==============================================================================
# Dedicated test stage for container-enforced read-only rootfs validation in CI
# ==============================================================================
FROM prod AS test
COPY tests /app/tests
RUN uv pip install --system pytest pytest-asyncio anyio
ENV PYTHONDONTWRITEBYTECODE=1
CMD ["python", "-m", "pytest", "tests/test_zero_disk.py", "-v", "-p", "no:cacheprovider", "-o", "cache_dir=/tmp/.pytest_cache"]