scriptsledge commited on
Commit
11f2db1
·
verified ·
1 Parent(s): c37ec45

fix: resolve libc.musl error by compiling llama-cpp-python from source in builder stage

Browse files
Files changed (1) hide show
  1. Dockerfile +11 -11
Dockerfile CHANGED
@@ -1,9 +1,14 @@
1
  # Stage 1: Builder
2
- # We use a standard Python image and install uv, which is safer and still incredibly fast.
3
  FROM python:3.10-slim-bookworm AS builder
4
  WORKDIR /app
5
 
6
- # Install uv (The extremely fast Python package installer)
 
 
 
 
 
 
7
  RUN pip install uv
8
 
9
  # Configure uv
@@ -13,13 +18,12 @@ ENV UV_LINK_MODE=copy
13
  # Copy requirements
14
  COPY requirements.txt .
15
 
16
- # Create a virtual environment and install dependencies using uv
17
- # We point to the extra index URL for the pre-built llama-cpp-python wheels
18
  RUN uv venv /app/.venv && \
19
  uv pip install \
20
  --no-cache \
21
  -r requirements.txt \
22
- --extra-index-url https://abetlen.github.io/llama-cpp-python/whl/cpu \
23
  --python /app/.venv
24
 
25
  # Stage 2: Final Runtime Image
@@ -29,22 +33,18 @@ WORKDIR /app
29
  # Copy the virtual environment from the builder stage
30
  COPY --from=builder /app/.venv /app/.venv
31
 
32
- # Set environment variables to use the virtual environment automatically
33
  ENV PATH="/app/.venv/bin:$PATH"
34
 
35
  # Copy the application code
36
  COPY . .
37
 
38
- # Create a non-root user for security (Hugging Face Spaces requirement)
39
  RUN useradd -m -u 1000 user
40
  USER user
41
  ENV HOME=/home/user
42
 
43
- # Expose the application port
44
  EXPOSE 7860
45
-
46
- # Runtime configuration
47
  ENV MODEL_CTX_SIZE=8192
48
 
49
- # Run the application
50
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  # Stage 1: Builder
 
2
  FROM python:3.10-slim-bookworm AS builder
3
  WORKDIR /app
4
 
5
+ # Install build tools
6
+ RUN apt-get update && apt-get install -y \
7
+ build-essential \
8
+ cmake \
9
+ && rm -rf /var/lib/apt/lists/*
10
+
11
+ # Install uv
12
  RUN pip install uv
13
 
14
  # Configure uv
 
18
  # Copy requirements
19
  COPY requirements.txt .
20
 
21
+ # Create venv and install dependencies
22
+ # We allow building from source for llama-cpp-python to ensure libc compatibility
23
  RUN uv venv /app/.venv && \
24
  uv pip install \
25
  --no-cache \
26
  -r requirements.txt \
 
27
  --python /app/.venv
28
 
29
  # Stage 2: Final Runtime Image
 
33
  # Copy the virtual environment from the builder stage
34
  COPY --from=builder /app/.venv /app/.venv
35
 
36
+ # Set environment variables
37
  ENV PATH="/app/.venv/bin:$PATH"
38
 
39
  # Copy the application code
40
  COPY . .
41
 
42
+ # Create a non-root user
43
  RUN useradd -m -u 1000 user
44
  USER user
45
  ENV HOME=/home/user
46
 
 
47
  EXPOSE 7860
 
 
48
  ENV MODEL_CTX_SIZE=8192
49
 
 
50
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]