try use mesa git.
Docker Build and Release Upload / build-vulkan (push) Failing after 2m27s
Docker Build and Release Upload / build-cuda (push) Failing after 5s
Docker Build and Release Upload / build-uvicorn (push) Successful in 3s

This commit is contained in:
derek committed 2026-09-10 10:04:14 -07:00
1 parent c78e1e9fbd
commit 8a8c312a2d
1 file changed
+111 -21
+111 -21
View File
@@ -1,48 +1,138 @@
# Stage 1: Build Ollama with Vulkan support FROM ubuntu:24.04 AS mesa-builder
FROM ubuntu:26.04 AS builder
ENV DEBIAN_FRONTEND=noninteractive ENV DEBIAN_FRONTEND=noninteractive
ENV REBUILD_FLAG=1
RUN apt update && apt upgrade -y && apt install -y \ RUN apt-get update && apt-get install -y \
git \
python3-mako \
python3-yaml \
python3-packaging \
meson \
ninja-build \
build-essential \
pkg-config \
flex \
bison \
libpciaccess-dev \
libexpat1-dev \
libelf-dev \
libvulkan-dev \
glslang-tools \
spirv-tools \
llvm-dev \
libclang-dev \
cmake \
libwayland-dev \
wayland-protocols \
libwayland-bin \
libxcb1-dev \
libx11-xcb-dev \
libxcb-dri3-dev \
libxcb-present-dev \
libxcb-sync-dev \
libxshmfence-dev \
libx11-dev \
libxcb-shm0-dev \
libxrandr-dev \
&& rm -rf /var/lib/apt/lists/*
# 1. Build required newer libdrm from source
RUN git clone --depth 1 https://gitlab.freedesktop.org/mesa/drm.git /drm
WORKDIR /drm
RUN meson setup build -Dbuildtype=release -Dprefix=/opt/mesa
RUN ninja -C build -j16 && ninja -C build install
# 2. Build matching LLVMSPIRVLib (SPIRV-LLVM-Translator) for LLVM 21
RUN git clone --branch llvm_release_210 --depth 1 https://github.com/KhronosGroup/SPIRV-LLVM-Translator.git /spirv-llvm-translator
WORKDIR /spirv-llvm-translator
RUN cmake -B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/mesa \
-DLLVM_DIR=/usr/lib/llvm-21/cmake
RUN cmake --build build --parallel 16
RUN cmake --install build
# 3. Build Mesa-git pointing to the custom libdrm and LLVMSPIRVLib paths
RUN git clone --depth 1 https://gitlab.freedesktop.org/mesa/mesa.git /mesa
WORKDIR /mesa
ENV PKG_CONFIG_PATH=/opt/mesa/lib/pkgconfig:/opt/mesa/lib/aarch64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH
ENV CMAKE_PREFIX_PATH=/opt/mesa:$CMAKE_PREFIX_PATH
RUN meson setup build \
-Dbuildtype=release \
-Dgallium-drivers= \
-Dvulkan-drivers=amd \
-Dplatforms=x11,wayland \
-Dprefix=/opt/mesa
RUN ninja -C build -j16
RUN ninja -C build install
# Stage 2: Build Ollama with Vulkan support
FROM ubuntu:24.04 AS ollama-builder
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
build-essential \ build-essential \
git \ git \
curl \ curl \
wget \ wget \
cmake \ cmake \
golang-go \ golang-go \
ca-certificates ca-certificates \
ninja-build \
# Directly install glslc via Debian arm64 package
RUN wget http://ftp.debian.org/debian/pool/main/s/shaderc/glslc_2023.2-1_arm64.deb \
&& apt-get update && apt-get install -y ./glslc_2023.2-1_arm64.deb \
&& rm glslc_2023.2-1_arm64.deb
# install the rest of the requirements
RUN apt update && apt upgrade -y && apt install -y \
libvulkan-dev \ libvulkan-dev \
vulkan-tools \ vulkan-tools \
glslang-tools \ glslang-tools \
ninja-build \
spirv-headers \ spirv-headers \
spirv-tools spirv-tools \
libshaderc-dev \
glslc \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app WORKDIR /app
RUN git clone --recursive https://github.com/ollama/ollama.git . RUN git clone --recursive https://github.com/ollama/ollama.git .
# Configure and safely build with constrained parallelism to protect 96GB RAM # Configure and compile Ollama using the Vulkan backend
RUN cmake -B build . -DOLLAMA_LLAMA_BACKENDS="vulkan" -DGGML_VULKAN=ON -DCMAKE_BUILD_TYPE=Release RUN cmake -B build . \
RUN cmake --build build --parallel 16 -DOLLAMA_LLAMA_BACKENDS="vulkan" \
-DGGML_VULKAN=ON \
-DCMAKE_BUILD_TYPE=Release
# Build the main Go application binary RUN cmake --build build --parallel 16
RUN go build -o ollama . RUN go build -o ollama .
# Start the server # Stage 3: Minimal Runtime Image
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
ca-certificates \
libvulkan1 \
vulkan-tools \
libexpat1 \
libelf1 \
libdrm2 \
&& rm -rf /var/lib/apt/lists/*
# Copy compiled Mesa-git libraries and ICD files from Stage 1
COPY --from=mesa-builder /opt/mesa /opt/mesa
# Copy compiled Ollama binary from Stage 2
COPY --from=ollama-builder /app/ollama /app/ollama
COPY --from=ollama-builder /app/build /app/build
EXPOSE 11434 EXPOSE 11434
ENV OLLAMA_HOST=0.0.0.0:11434 ENV OLLAMA_HOST=0.0.0.0:11434
ENV GGML_VULKAN_DISABLE_FMA=1 ENV GGML_VULKAN_DISABLE_FMA=1
ENV RADV_PERFOPTS="no_outoforder" ENV RADV_PERFOPTS="no_outoforder"
ENV AMD_DEBUG="notcc" ENV AMD_DEBUG="notcc"
ENV OLLAMA_MODELS=/root/.ollama/models ENV OLLAMA_MODELS=/root/.ollama/models
# Point the loader directly to the custom Mesa-git ICD driver
ENV VK_ICD_FILENAMES=/opt/mesa/share/vulkan/icd.d/radeon_icd.aarch64.json
ENV LD_LIBRARY_PATH=/opt/mesa/lib/aarch64-linux-gnu:/opt/mesa/lib:$LD_LIBRARY_PATH
ENTRYPOINT ["/app/ollama", "serve"] ENTRYPOINT ["/app/ollama", "serve"]