# Use Ubuntu 22.04 as a base image FROM ubuntu:22.04 # Disable interactive prompts and set timezone to UTC ENV DEBIAN_FRONTEND=noninteractive ENV TZ=Etc/UTC # Configure cache paths to a writable /tmp location ENV XDG_CACHE_HOME=/tmp/.cache ENV HF_HOME=/tmp/.cache/huggingface # Use bash with strict modes for better debugging SHELL ["/bin/bash", "-euxo", "pipefail", "-c"] # Preseed tzdata to avoid interactive prompt RUN echo "tzdata tzdata/Areas select Etc" > /tmp/tzdata.seed && \ echo "tzdata tzdata/Zones/Etc select UTC" >> /tmp/tzdata.seed && \ debconf-set-selections /tmp/tzdata.seed # STEP 1: Install OS-level build and runtime dependencies RUN echo "### STEP 1: Installing OS-level dependencies" && \ apt-get update && \ apt-get install -y --no-install-recommends \ tzdata \ build-essential \ cmake \ libopenblas-dev \ pkg-config \ git \ python3 \ python3-pip \ python3-dev \ python3-opencv && \ rm -rf /var/lib/apt/lists/* # STEP 2: Prepare application directory and copy source code WORKDIR /app COPY requirements.txt ./ COPY app.py ./ # Copy additional source as needed # STEP 3: Install Python dependencies RUN echo "### STEP 3: Installing Python dependencies" && \ python3 -m pip install --upgrade pip setuptools wheel scikit-build-core && \ pip install --no-cache-dir -r requirements.txt # STEP 4: Ensure cache directories are writable RUN echo "### STEP 4: Configuring cache directories" && \ mkdir -p "$XDG_CACHE_HOME" "$HF_HOME" && \ chmod -R a+rwX "$XDG_CACHE_HOME" "$HF_HOME" # STEP 5: Build and install llama-cpp-python from Git with OpenBLAS support RUN echo "### STEP 5: Building llama-cpp-python from source" && \ git clone --depth 1 --recurse-submodules https://github.com/abetlen/llama-cpp-python.git /tmp/llama-cpp-python && \ cd /tmp/llama-cpp-python && \ CMAKE_ARGS="-DGGML_BLAS=ON -DGGML_BLAS_VENDOR=OpenBLAS" pip install . && \ rm -rf /tmp/llama-cpp-python # Expose port and set default command EXPOSE 7860 CMD ["python3", "app.py"]