Spaces:
Running
Running
| # Multi-stage Dockerfile for GGUF Splitter | |
| # Supports production, local development, and testing configurations | |
| # Base stage with common dependencies | |
| FROM python:3.11-slim as base | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| curl \ | |
| wget \ | |
| libgomp1 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Build llama.cpp binaries (only needed for test stage) | |
| FROM base as llama-builder | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| git \ | |
| build-essential \ | |
| cmake \ | |
| && rm -rf /var/lib/apt/lists/* | |
| RUN git clone https://github.com/ggerganov/llama.cpp.git /tmp/llama.cpp | |
| WORKDIR /tmp/llama.cpp | |
| RUN cmake -B build -DCMAKE_BUILD_TYPE=Release | |
| RUN cmake --build build --config Release -j --target llama-gguf-split | |
| # Production stage | |
| FROM base as production | |
| # Download pre-built llama.cpp binaries | |
| WORKDIR /tmp | |
| RUN LLAMA_VERSION=$(wget -qO- https://api.github.com/repos/ggml-org/llama.cpp/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")') && \ | |
| wget -q "https://github.com/ggml-org/llama.cpp/releases/download/${LLAMA_VERSION}/llama-${LLAMA_VERSION}-bin-ubuntu-x64.tar.gz" && \ | |
| tar -xzf "llama-${LLAMA_VERSION}-bin-ubuntu-x64.tar.gz" && \ | |
| mkdir -p /usr/local/llama.cpp && \ | |
| mv llama-${LLAMA_VERSION}/* /usr/local/llama.cpp/ && \ | |
| rm -rf /tmp/* | |
| ENV PATH="/usr/local/llama.cpp:${PATH}" | |
| ENV LLAMA_GGUF_SPLIT_PATH=/usr/local/llama.cpp/llama-gguf-split | |
| WORKDIR /home/user/app | |
| COPY requirements.txt /home/user/app/requirements.txt | |
| # Create virtual environment | |
| RUN python3 -m venv /opt/venv | |
| ENV PATH="/opt/venv/bin:$PATH" | |
| RUN /opt/venv/bin/pip install --upgrade pip | |
| RUN /opt/venv/bin/pip install -r /home/user/app/requirements.txt | |
| ENV HF_HUB_HOME=/home/user/app | |
| ENV GRADIO_HF_OFFLINE_SPACE_OK=1 | |
| COPY . /home/user/app | |
| ENTRYPOINT ["python", "app.py"] | |
| # Local development stage | |
| FROM production as local | |
| ENV GRADIO_SERVER_NAME="0.0.0.0" | |
| ENV RUN_LOCALLY=1 | |
| EXPOSE 7860 | |
| CMD ["python", "app.py"] | |
| # Test stage | |
| FROM base as test | |
| # Copy llama-gguf-split from builder stage | |
| COPY --from=llama-builder /tmp/llama.cpp/build/bin/llama-gguf-split /usr/local/bin/ | |
| COPY --from=llama-builder /tmp/llama.cpp/build/bin/*.so* /usr/local/bin/ | |
| WORKDIR /home/user/app | |
| COPY requirements.txt /home/user/app/requirements.txt | |
| RUN pip install --no-cache-dir -r /home/user/app/requirements.txt | |
| # Install test dependencies | |
| COPY requirements-dev.txt /home/user/app/requirements-dev.txt | |
| RUN pip install --no-cache-dir -r /home/user/app/requirements-dev.txt | |
| ENV PYTHONPATH=/home/user/app | |
| ENV RUN_LOCALLY=1 | |
| ENV LLAMA_GGUF_SPLIT_PATH=/usr/local/bin/llama-gguf-split | |
| ENV LD_LIBRARY_PATH=/usr/local/bin | |
| COPY . /home/user/app | |
| CMD ["pytest", "tests/", "-v", "--tb=short"] |