Skip to content

Commit 238aa11

Browse files
committed
DELPXECO-11971 Adding Delphix's custom changes to Ollama
1 parent 43107b1 commit 238aa11

File tree

2 files changed

+152
-0
lines changed

2 files changed

+152
-0
lines changed

Dockerfile-cpu

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# vim: filetype=dockerfile
2+
3+
ARG FLAVOR=${TARGETARCH}
4+
5+
ARG ROCMVERSION=6.3.3
6+
ARG JETPACK5VERSION=r35.4.1
7+
ARG JETPACK6VERSION=r36.4.0
8+
ARG CMAKEVERSION=3.31.2
9+
10+
# CUDA v11 requires gcc v10. v10.3 has regressions, so the rockylinux 8.5 AppStream has the latest compatible version
11+
FROM --platform=linux/amd64 rocm/dev-almalinux-8:${ROCMVERSION}-complete AS base-amd64
12+
RUN yum install -y yum-utils \
13+
&& yum-config-manager --add-repo https://dl.rockylinux.org/vault/rocky/8.5/AppStream/\$basearch/os/ \
14+
&& rpm --import https://dl.rockylinux.org/pub/rocky/RPM-GPG-KEY-Rocky-8 \
15+
&& dnf install -y yum-utils ccache gcc-toolset-10-gcc-10.2.1-8.2.el8 gcc-toolset-10-gcc-c++-10.2.1-8.2.el8 \
16+
&& yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo
17+
ENV PATH=/opt/rh/gcc-toolset-10/root/usr/bin:$PATH
18+
19+
20+
21+
22+
FROM --platform=linux/arm64 almalinux:8 AS base-arm64
23+
# install epel-release for ccache
24+
RUN yum install -y yum-utils epel-release \
25+
&& dnf install -y clang ccache \
26+
&& yum-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel8/sbsa/cuda-rhel8.repo
27+
ENV CC=clang CXX=clang++
28+
29+
FROM base-${TARGETARCH} AS base
30+
ARG CMAKEVERSION
31+
RUN curl -fsSL https://github.com/Kitware/CMake/releases/download/v${CMAKEVERSION}/cmake-${CMAKEVERSION}-linux-$(uname -m).tar.gz | tar xz -C /usr/local --strip-components 1
32+
COPY CMakeLists.txt CMakePresets.json .
33+
COPY ml/backend/ggml/ggml ml/backend/ggml/ggml
34+
ENV LDFLAGS=-s
35+
36+
FROM base AS cpu
37+
RUN dnf install -y gcc-toolset-11-gcc gcc-toolset-11-gcc-c++
38+
ENV PATH=/opt/rh/gcc-toolset-11/root/usr/bin:$PATH
39+
RUN --mount=type=cache,target=/root/.ccache \
40+
cmake --preset 'CPU' \
41+
&& cmake --build --parallel --preset 'CPU' \
42+
&& cmake --install build --component CPU --strip --parallel 2
43+
44+
45+
FROM base AS build
46+
ARG GOVERSION=1.24.4
47+
RUN curl -fsSL https://golang.org/dl/go${GOVERSION}.linux-$(case $(uname -m) in x86_64) echo amd64 ;; aarch64) echo arm64 ;; esac).tar.gz | tar xz -C /usr/local
48+
ENV PATH=/usr/local/go/bin:$PATH
49+
WORKDIR /go/src/github.com/ollama/ollama
50+
COPY . .
51+
ARG GOFLAGS="'-ldflags=-w -s'"
52+
ENV CGO_ENABLED=1
53+
RUN --mount=type=cache,target=/root/.cache/go-build \
54+
go build -trimpath -buildmode=pie -o /bin/ollama .
55+
56+
FROM --platform=linux/amd64 scratch AS amd64
57+
58+
FROM --platform=linux/arm64 scratch AS arm64
59+
60+
FROM ${FLAVOR} AS archive
61+
COPY --from=cpu dist/lib/ollama /lib/ollama
62+
COPY --from=build /bin/ollama /bin/ollama
63+
64+
FROM ubuntu:24.04
65+
RUN apt-get update \
66+
&& apt-get install -y ca-certificates curl openssl \
67+
&& apt-get install --only-upgrade -y libpam0g libpam-modules libpam-modules-bin libpam-runtime \
68+
libsystemd0 libudev1 \
69+
&& update-ca-certificates \
70+
&& apt-get clean \
71+
&& rm -rf /var/lib/apt/lists/*
72+
COPY --from=archive /bin /usr/bin
73+
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
74+
COPY --from=archive /lib/ollama /usr/lib/ollama
75+
ENV OLLAMA_HOST=0.0.0.0:11434
76+
EXPOSE 11434
77+
ENTRYPOINT ["/bin/ollama"]
78+
CMD ["serve"]

build-for-cpu.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
# Set your organization and image name
5+
ORG=${ORG:-"arunskurian"}
6+
IMAGE_NAME=${IMAGE_NAME:-"ollama-cpu"}
7+
VERSION=${VERSION:-"latest"}
8+
9+
# Docker Hub credentials (can be set via environment variables)
10+
DOCKER_USERNAME=${DOCKER_USERNAME:-""}
11+
DOCKER_PASSWORD=${DOCKER_PASSWORD:-""}
12+
13+
# Target platforms - same as Ollama's defaults
14+
PLATFORMS=${PLATFORMS:-"linux/arm64,linux/amd64"}
15+
16+
# Silent login if credentials are provided
17+
if [ -n "$DOCKER_USERNAME" ] && [ -n "$DOCKER_PASSWORD" ]; then
18+
echo "Logging in to Docker Hub as $DOCKER_USERNAME..."
19+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin >/dev/null 2>&1
20+
echo "Login successful"
21+
22+
# If login successful, use the provided username as the org
23+
if [ "$ORG" = "yourorg" ]; then
24+
ORG=$DOCKER_USERNAME
25+
echo "Using Docker username '$ORG' as organization"
26+
fi
27+
else
28+
echo "Docker credentials not provided, assuming you're already logged in"
29+
fi
30+
31+
# Ensure QEMU is installed for cross-platform builds
32+
echo "Setting up QEMU for cross-platform builds..."
33+
docker run --privileged --rm tonistiigi/binfmt --install all
34+
35+
# Set up buildx if needed
36+
BUILDER_NAME="multiarch-builder"
37+
if ! docker buildx inspect ${BUILDER_NAME} &>/dev/null; then
38+
echo "Creating new buildx builder: ${BUILDER_NAME}"
39+
docker buildx create --name ${BUILDER_NAME} --driver docker-container --use
40+
else
41+
docker buildx use ${BUILDER_NAME}
42+
fi
43+
docker buildx inspect --bootstrap
44+
45+
# Set PUSH to a non-empty string to trigger push instead of load
46+
PUSH=${PUSH:-""}
47+
if [ -z "${PUSH}" ] ; then
48+
echo "Building ${ORG}/${IMAGE_NAME}:${VERSION} locally. Set PUSH=1 to push"
49+
# Note: --load only works for single platform, so if building locally, adjust PLATFORMS
50+
if [[ "${PLATFORMS}" == *","* ]]; then
51+
echo "WARNING: --load only works for single platform. Setting platform to linux/$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')"
52+
PLATFORMS="linux/$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')"
53+
fi
54+
LOAD_OR_PUSH="--load"
55+
else
56+
echo "Will be pushing ${ORG}/${IMAGE_NAME}:${VERSION}"
57+
LOAD_OR_PUSH="--push"
58+
fi
59+
60+
# Build and push/load the multi-arch image
61+
echo "Building for platforms: ${PLATFORMS}"
62+
docker buildx build \
63+
--network=host \
64+
${LOAD_OR_PUSH} \
65+
--platform=${PLATFORMS} \
66+
-f Dockerfile.cpu \
67+
-t ${ORG}/${IMAGE_NAME}:${VERSION} \
68+
.
69+
70+
echo "Build completed successfully!"
71+
if [ -n "${PUSH}" ]; then
72+
echo "Image pushed to: ${ORG}/${IMAGE_NAME}:${VERSION}"
73+
echo "To pull: docker pull ${ORG}/${IMAGE_NAME}:${VERSION}"
74+
fi

0 commit comments

Comments
 (0)