From c004ecdccc8cffc42776626f91d42ebba193bd7d Mon Sep 17 00:00:00 2001 From: Joseph Young <130690493+yousecjoe@users.noreply.github.com> Date: Sun, 17 Mar 2024 17:03:43 -0400 Subject: [PATCH] Refactor Dockerfile for CPU and CUDA builds Switched to Chainguard images as base for both CPU and CUDA backend builds for improved security and compatibility. Replaced Ubuntu base with Chainguard's Python image for the CPU builds and PyTorch CUDA image for GPU acceleration, resolving python requirements conflicts. Updated package installation commands to align with the new Redhat-compatible base images. The Dockerfile now installs only the necessary dependencies, as Python is provided by the base image. These changes will facilitate a more secure and streamlined build process with better dependency management across different platforms. --- Dockerfile-cuda | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Dockerfile-cuda b/Dockerfile-cuda index 5bd0c377..c396b95f 100644 --- a/Dockerfile-cuda +++ b/Dockerfile-cuda @@ -15,16 +15,21 @@ RUN npm run build ######## CPU-only WebUI backend ######## # To support both CPU and GPU backend, we need to keep the ability to build the CPU-only image. #FROM python:3.11-slim-bookworm as base +FROM --platform=linux/amd64 cgr.dev/chainguard/python:latest-dev AS cpu-build-amd64 #FROM --platform=linux/amd64 ubuntu:22.04 AS cpu-builder-amd64 + #FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64 #RUN OPENWEBUI_CPU_TARGET="cpu" sh gen_linux.sh + #FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64 #RUN OPENWEBUI_CPU_TARGET="cpu_avx" sh gen_linux.sh + #FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64 #RUN OPENWEBUI_CPU_TARGET="cpu_avx2" sh gen_linux.sh ######## CUDA WebUI backend ######## -FROM --platform=linux/amd64 nvidia/cuda:"$CUDA_VERSION"-devel-ubuntu22.04 AS cuda-build-amd64 +#FROM --platform=linux/amd64 nvidia/cuda:"$CUDA_VERSION"-devel-ubuntu22.04 AS cuda-build-amd64 +#FROM --platform=linux/amd64 cgr.dev/chainguard/pytorch-cuda12:latest AS cuda-build-amd64 # fails with python requirements conflicts # Set environment variables for NVIDIA Container Toolkit ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64 \ @@ -64,9 +69,20 @@ ENV RAG_EMBEDDING_MODEL="all-MiniLM-L6-v2" \ WORKDIR /app/backend # Install Python & dependencies in the container -RUN apt-get update && \ - apt-get install -y --no-install-recommends python3.11 python3-pip ffmpeg libsm6 libxext6 pandoc netcat-openbsd && \ - rm -rf /var/lib/apt/lists/* +# Used for Debian +#RUN apt-get update && \ +# apt-get install -y --no-install-recommends python3.11 python3-pip ffmpeg libsm6 libxext6 pandoc netcat-openbsd && \ +# rm -rf /var/lib/apt/lists/* + +# Used for Redhat +#RUN apk update && \ +# apk add --no-install-recommends python3.11 python3-pip ffmpeg libsm6 libxext6 pandoc netcat-openbsd && \ +# apk del /var/cache/apk/*.tbz2 + +# Install only the dependencies in the container, python will come from the base image used +RUN apk update && \ + apk add --no-install-recommends ffmpeg libsm6 libxext6 pandoc netcat-openbsd && \ + apk del /var/cache/apk/*.tbz2 COPY ./backend/requirements.txt ./requirements.txt RUN pip3 install torch torchvision torchaudio --no-cache-dir && \