Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +43 -29
Dockerfile
CHANGED
|
@@ -1,50 +1,64 @@
|
|
| 1 |
-
#
|
| 2 |
-
FROM
|
| 3 |
|
| 4 |
# Set environment variables to prevent interactive prompts during apt operations
|
| 5 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 6 |
|
| 7 |
-
# Install system dependencies: curl for Ollama
|
| 8 |
-
RUN apt
|
| 9 |
|
| 10 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
RUN curl -fsSL https://ollama.com/install.sh | sh
|
| 12 |
|
| 13 |
-
# Set
|
| 14 |
-
|
| 15 |
-
ENV MODEL_FILENAME="gemma-3-4b-it-qat.Q4_K_M.gguf"
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
# Download the GGUF model file directly from Hugging Face Hub.
|
| 23 |
-
RUN wget "https://huggingface.co/unsloth/gemma-3-4b-it-qat-GGUF/resolve/main/gemma-3-4b-it-qat-Q4_K_M.gguf?download=true" -O ${MODEL_FILENAME}
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
COPY --chown=user
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
# Install Python dependencies
|
| 32 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 33 |
|
| 34 |
-
# Make the startup script executable
|
| 35 |
RUN chmod +x run.sh
|
| 36 |
|
| 37 |
-
#
|
|
|
|
|
|
|
| 38 |
USER user
|
| 39 |
|
| 40 |
-
# Set environment variables for the user
|
| 41 |
-
#
|
| 42 |
-
ENV HOME=/home/user
|
| 43 |
-
|
| 44 |
-
ENV OLLAMA_HOST=127.0.0.1
|
| 45 |
|
| 46 |
-
# Expose the port
|
| 47 |
EXPOSE 7860
|
| 48 |
|
| 49 |
-
# Set the
|
|
|
|
| 50 |
CMD ["./run.sh"]
|
|
|
|
| 1 |
+
# Use a base Ubuntu image
|
| 2 |
+
FROM ubuntu:22.04
|
| 3 |
|
| 4 |
# Set environment variables to prevent interactive prompts during apt operations
|
| 5 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 6 |
|
| 7 |
+
# Install system dependencies: curl for Ollama, wget for model download, git, python3 and pip
|
| 8 |
+
RUN apt update && apt install -y curl wget git python3 python3-pip
|
| 9 |
|
| 10 |
+
# --- PERMISSIONS FIX 1: CREATE USER ---
|
| 11 |
+
# Create a non-root user named 'user' with user ID 1000.
|
| 12 |
+
# This matches the user ID that Hugging Face Spaces uses to run the container.
|
| 13 |
+
# The -m flag creates a home directory at /home/user.
|
| 14 |
+
RUN useradd -m -u 1000 user
|
| 15 |
+
|
| 16 |
+
# Install Ollama using its official installation script
|
| 17 |
+
# This will be run as root, which is correct for system-wide installation.
|
| 18 |
RUN curl -fsSL https://ollama.com/install.sh | sh
|
| 19 |
|
| 20 |
+
# Set the working directory inside the container
|
| 21 |
+
WORKDIR /app
|
|
|
|
| 22 |
|
| 23 |
+
# Define environment variables for the model repository and filename
|
| 24 |
+
ENV MODEL_REPO="unsloth/gemma-3-4b-it-GGUF"
|
| 25 |
+
ENV MODEL_FILENAME="gemma-3-4b-it.Q4_K_M.gguf"
|
| 26 |
+
ENV MODEL_enableDL="?download=true"
|
| 27 |
+
|
| 28 |
+
# Download the specific GGUF model file directly from Hugging Face Hub.
|
| 29 |
+
RUN wget -O ${MODEL_FILENAME} https://huggingface.co/${MODEL_REPO}/resolve/main/${MODEL_FILENAME}${MODEL_enableDL}
|
| 30 |
|
| 31 |
+
# This OK.... Download the GGUF model file directly from Hugging Face Hub.
|
| 32 |
+
#RUN wget "https://huggingface.co/unsloth/gemma-3-4b-it-qat-GGUF/resolve/main/gemma-3-4b-it-qat-Q4_K_M.gguf?download=true" -O ${MODEL_FILENAME}
|
| 33 |
|
| 34 |
+
# --- PERMISSIONS FIX 2: COPY FILES WITH OWNERSHIP ---
|
| 35 |
+
# Copy all application files into the container.
|
| 36 |
+
# Use the --chown=user flag to set the owner of these files to the 'user' we created.
|
| 37 |
+
# This is critical for giving the application write permissions.
|
| 38 |
+
COPY --chown=user Modelfile .
|
| 39 |
+
COPY --chown=user app.py .
|
| 40 |
+
COPY --chown=user requirements.txt .
|
| 41 |
+
COPY --chown=user run.sh .
|
| 42 |
|
| 43 |
+
# Install Python dependencies required by your Gradio application
|
| 44 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 45 |
|
| 46 |
+
# Make the startup script executable
|
| 47 |
RUN chmod +x run.sh
|
| 48 |
|
| 49 |
+
# --- PERMISSIONS FIX 3: SWITCH TO USER ---
|
| 50 |
+
# Switch the context of the Dockerfile to our non-root user.
|
| 51 |
+
# All subsequent commands (including the final CMD) will now be executed as 'user', not 'root'.
|
| 52 |
USER user
|
| 53 |
|
| 54 |
+
# Set environment variables for the user's home directory. This ensures that
|
| 55 |
+
# tools like pip and transformers cache files in a location writable by the user (/home/user/.cache).
|
| 56 |
+
ENV HOME=/home/user \
|
| 57 |
+
PATH=/home/user/.local/bin:$PATH
|
|
|
|
| 58 |
|
| 59 |
+
# Expose the port that your Gradio application will listen on.
|
| 60 |
EXPOSE 7860
|
| 61 |
|
| 62 |
+
# Set the entrypoint for the container to execute our startup script.
|
| 63 |
+
# This will now be run as the 'user'.
|
| 64 |
CMD ["./run.sh"]
|