File size: 1,890 Bytes
79a6975
 
 
f384c74
 
 
79a6975
 
 
 
 
 
 
 
 
f384c74
 
 
 
 
 
c7a088c
 
 
f384c74
 
 
 
f4e572b
 
 
79a6975
 
 
 
f4e572b
79a6975
 
 
 
 
 
f384c74
 
79a6975
f4e572b
 
f384c74
79a6975
f384c74
f4e572b
f384c74
79a6975
 
 
 
f384c74
79a6975
 
f384c74
79a6975
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
# Use a Python 3.10 base image with Debian Bookworm
FROM python:3.10-bookworm

# Set environment variables to avoid Python buffering and ensure non-interactive installs
ENV PYTHONUNBUFFERED=1 \
    DEBIAN_FRONTEND=noninteractive

# Install system dependencies, including OpenBLAS, Git, and build tools
RUN apt-get update && apt-get install -y \
    git \
    build-essential \
    cmake \
    libopenblas-dev \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user with configurable UID/GID
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN groupadd -g ${GROUP_ID} appuser && \
    useradd -m -u ${USER_ID} -g ${GROUP_ID} -s /bin/bash appuser

# Set up Hugging Face cache directory and /app with proper permissions
RUN mkdir -p /home/appuser/.cache/huggingface /app && \
    chown -R appuser:appuser /home/appuser/.cache /app

# Set working directory
WORKDIR /app

# Clone llama-cpp-python repository with submodules as appuser
USER appuser
RUN git clone --recursive https://github.com/abetlen/llama-cpp-python.git /app/llama-cpp-python

# Set working directory to llama-cpp-python
WORKDIR /app/llama-cpp-python

# Update llama.cpp submodule to the latest version as appuser
RUN git submodule update --remote vendor/llama.cpp

# Set environment variables for building with OpenBLAS
ENV FORCE_CMAKE=1
ENV CMAKE_ARGS="-DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS -DLLAMA_CURL=OFF"

# Install llama-cpp-python from source as appuser
RUN pip install . --user --upgrade --force-reinstall --no-cache-dir

# Switch to root to copy application code (to ensure permissions)
USER root
COPY --chown=appuser:appuser app.py /app/

# Install additional Python dependencies for your app as appuser
USER appuser
RUN pip install --user gradio huggingface_hub

# Set working directory for the application
WORKDIR /app

# Expose port for Gradio
EXPOSE 7860

# Run the application as appuser
CMD ["python", "app.py"]