ARG IMAGE_TYPE=extras ARG BASE_IMAGE=ubuntu:22.04 ARG GRPC_BASE_IMAGE=${BASE_IMAGE} ARG INTEL_BASE_IMAGE=${BASE_IMAGE} # The requirements-core target is common to all images. It should not be placed in requirements-core unless every single build will use it. FROM ${BASE_IMAGE} AS requirements-core # TODO(mudler): install all accellerators here # and use make dist instead of build. # TODO(mudler): modify make dist to build also go-piper and stablediffusion # This way the same binary can work for everything(!) # TODO(mudler): also make sure that we bundle all the required libs in the backend-assets/lib # For the GPU-accell we are going to generate a tar file instead that will be extracted by the bash installer, and the libs will also be installed in the final docker image, so no need to pull ALL the dependencies USER root ARG GO_VERSION=1.22.4 ARG TARGETARCH ARG TARGETVARIANT ENV DEBIAN_FRONTEND=noninteractive ENV EXTERNAL_GRPC_BACKENDS="coqui:/build/backend/python/coqui/run.sh,huggingface-embeddings:/build/backend/python/sentencetransformers/run.sh,petals:/build/backend/python/petals/run.sh,transformers:/build/backend/python/transformers/run.sh,sentencetransformers:/build/backend/python/sentencetransformers/run.sh,rerankers:/build/backend/python/rerankers/run.sh,autogptq:/build/backend/python/autogptq/run.sh,bark:/build/backend/python/bark/run.sh,diffusers:/build/backend/python/diffusers/run.sh,exllama:/build/backend/python/exllama/run.sh,openvoice:/build/backend/python/openvoice/run.sh,vall-e-x:/build/backend/python/vall-e-x/run.sh,vllm:/build/backend/python/vllm/run.sh,mamba:/build/backend/python/mamba/run.sh,exllama2:/build/backend/python/exllama2/run.sh,transformers-musicgen:/build/backend/python/transformers-musicgen/run.sh,parler-tts:/build/backend/python/parler-tts/run.sh" RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ ccache \ ca-certificates \ cmake \ curl \ git \ unzip && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* # Install Go RUN curl -L -s https://go.dev/dl/go${GO_VERSION}.linux-${TARGETARCH}.tar.gz | tar -C /usr/local -xz ENV PATH $PATH:/root/go/bin:/usr/local/go/bin # Install grpc compilers RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.2 && \ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@1958fcbe2ca8bd93af633f11e97d44e567e945af COPY --chmod=644 custom-ca-certs/* /usr/local/share/ca-certificates/ RUN update-ca-certificates # Use the variables in subsequent instructions RUN echo "Target Architecture: $TARGETARCH" RUN echo "Target Variant: $TARGETVARIANT" # Cuda ENV PATH /usr/local/cuda/bin:${PATH} # HipBLAS requirements ENV PATH /opt/rocm/bin:${PATH} # OpenBLAS requirements and stable diffusion, tts (espeak) RUN apt-get update && \ apt-get install -y --no-install-recommends \ libopenblas-dev \ espeak-ng \ espeak \ libopencv-dev && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* # Set up OpenCV RUN ln -s /usr/include/opencv4/opencv2 /usr/include/opencv2 WORKDIR /build RUN test -n "$TARGETARCH" \ || (echo 'warn: missing $TARGETARCH, either set this `ARG` manually, or run using `docker buildkit`') ################################### ################################### # The requirements-extras target is for any builds with IMAGE_TYPE=extras. It should not be placed in this target unless every IMAGE_TYPE=extras build will use it FROM requirements-core AS requirements-extras RUN curl -LsSf https://astral.sh/uv/install.sh | sh ENV PATH="/root/.cargo/bin:${PATH}" RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y RUN apt-get update && \ apt-get install -y --no-install-recommends \ python3-pip \ python-is-python3 \ python3-dev \ python3-venv && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* && \ pip install --upgrade pip # Install grpcio-tools (the version in 22.04 is too old) RUN pip install --user grpcio-tools ################################### ################################### # Base image for the build-type. FROM requirements-${IMAGE_TYPE} AS run-requirements-drivers ARG BUILD_TYPE ARG CUDA_MAJOR_VERSION=12 ARG CUDA_MINOR_VERSION=5 ENV BUILD_TYPE=${BUILD_TYPE} # Vulkan requirements RUN < /dev/null && echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | tee /etc/apt/sources.list.d/oneAPI.list && apt update && apt install -y intel-basekit && apt-get clean && \ rm -rf /var/lib/apt/lists/* # hipblas RUN wget https://repo.radeon.com/rocm/rocm.gpg.key -O - | \ gpg --dearmor | tee /etc/apt/keyrings/rocm.gpg > /dev/null && apt-get update && \ echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/amdgpu/6.1.2/ubuntu jammy main" \ | tee /etc/apt/sources.list.d/amdgpu.list && \ echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/6.1.2 jammy main" | tee --append /etc/apt/sources.list.d/rocm.list && printf 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' | tee /etc/apt/preferences.d/rocm-pin-600 && \ apt update && \ apt-get install -y --no-install-recommends \ hipblas-dev rocm-dev \ rocblas-dev && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* && \ # I have no idea why, but the ROCM lib packages don't trigger ldconfig after they install, which results in local-ai and others not being able # to locate the libraries. We run ldconfig ourselves to work around this packaging deficiency ldconfig ################################### ################################### # Temporary workaround for Intel's repository to work correctly # https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/APT-Repository-not-working-signatures-invalid/m-p/1599436/highlight/true#M36143 # This is a temporary workaround until Intel fixes their repository FROM ${INTEL_BASE_IMAGE} AS intel RUN wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | \ gpg --yes --dearmor --output /usr/share/keyrings/intel-graphics.gpg RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/gpu/ubuntu jammy/lts/2350 unified" > /etc/apt/sources.list.d/intel-graphics.list ################################### ################################### # The grpc target does one thing, it builds and installs GRPC. This is in it's own layer so that it can be effectively cached by CI. # You probably don't need to change anything here, and if you do, make sure that CI is adjusted so that the cache continues to work. FROM ${GRPC_BASE_IMAGE} AS grpc # This is a bit of a hack, but it's required in order to be able to effectively cache this layer in CI ARG GRPC_MAKEFLAGS="-j4 -Otarget" ARG GRPC_VERSION=v1.64.2 ENV MAKEFLAGS=${GRPC_MAKEFLAGS} WORKDIR /build RUN apt-get update && \ apt-get install -y --no-install-recommends \ ca-certificates \ build-essential \ cmake \ git && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* # We install GRPC to a different prefix here so that we can copy in only the build artifacts later # saves several hundred MB on the final docker image size vs copying in the entire GRPC source tree # and running make install in the target container RUN git clone --recurse-submodules --jobs 4 -b ${GRPC_VERSION} --depth 1 --shallow-submodules https://github.com/grpc/grpc && \ mkdir -p /build/grpc/cmake/build && \ cd /build/grpc/cmake/build && \ cmake -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX:PATH=/opt/grpc ../.. && \ make && \ make install && \ rm -rf /build ################################### ################################### # The builder target compiles LocalAI. This target is not the target that will be uploaded to the registry. # Adjustments to the build process should likely be made here. FROM build-requirements-drivers AS builder ARG GO_TAGS="stablediffusion tts p2p" ARG GRPC_BACKENDS ARG MAKEFLAGS ENV GRPC_BACKENDS=${GRPC_BACKENDS} ENV GO_TAGS=${GO_TAGS} ENV MAKEFLAGS=${MAKEFLAGS} ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility ENV NVIDIA_REQUIRE_CUDA="cuda>=${CUDA_MAJOR_VERSION}.0" ENV NVIDIA_VISIBLE_DEVICES=all WORKDIR /build COPY . . COPY .git . RUN echo "GO_TAGS: $GO_TAGS" RUN make prepare # We need protoc installed, and the version in 22.04 is too old. We will create one as part installing the GRPC build below # but that will also being in a newer version of absl which stablediffusion cannot compile with. This version of protoc is only # here so that we can generate the grpc code for the stablediffusion build RUN <