"macapp/tsconfig.json" did not exist on "ebec1c61db24859c415eed66d31827f8fce9e744"
Dockerfile 6.65 KB
Newer Older
1
ARG GOLANG_VERSION=1.22.5
2
ARG CMAKE_VERSION=3.22.1
3
# this CUDA_VERSION corresponds with the one specified in docs/gpu.md
4
ARG CUDA_VERSION=11.3.1
Daniel Hiltgen's avatar
Daniel Hiltgen committed
5
ARG ROCM_VERSION=6.1.2
Michael Yang's avatar
Michael Yang committed
6

7
8
9
10
11
# Copy the minimal context we need to run the generate scripts
FROM scratch AS llm-code
COPY .git .git
COPY .gitmodules .gitmodules
COPY llm llm
Michael Yang's avatar
Michael Yang committed
12

13
14
15
16
17
FROM --platform=linux/amd64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-build-amd64
ARG CMAKE_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
18
19
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
20
ARG CGO_CFLAGS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
21
ENV GOARCH amd64 
22
23
RUN --mount=type=cache,target=/root/.ccache \
    OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 bash gen_linux.sh
24

25
FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-rockylinux8 AS cuda-build-arm64
26
27
28
ARG CMAKE_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
29
ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
30
31
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
32
ARG CGO_CFLAGS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
33
ENV GOARCH arm64 
34
35
36
37
38
39
RUN --mount=type=cache,target=/root/.ccache \
    OLLAMA_SKIP_STATIC_GENERATE=1 \
    OLLAMA_SKIP_CPU_GENERATE=1 \
    CMAKE_CUDA_ARCHITECTURES="${CUDA_V11_ARCHITECTURES}" \
    CUDA_VARIANT="_v11" \
    bash gen_linux.sh
40

Daniel Hiltgen's avatar
Daniel Hiltgen committed
41
FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete AS rocm-build-amd64
42
43
44
45
46
ARG CMAKE_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
ENV LIBRARY_PATH /opt/amdgpu/lib64
47
48
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
49
50
ARG CGO_CFLAGS
ARG AMDGPU_TARGETS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
51
ENV GOARCH amd64 
52
53
RUN --mount=type=cache,target=/root/.ccache \
    OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 bash gen_linux.sh
Daniel Hiltgen's avatar
Daniel Hiltgen committed
54
55
RUN mkdir -p ../../dist/linux-amd64/ollama_libs && \
    (cd /opt/rocm/lib && tar cf - rocblas/library) | (cd ../../dist/linux-amd64/ollama_libs && tar xf - )
56

57
FROM --platform=linux/amd64 centos:7 AS cpu-builder-amd64
58
59
60
61
62
ARG CMAKE_VERSION
ARG GOLANG_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
63
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
64
65
ARG OLLAMA_CUSTOM_CPU_DEFS
ARG CGO_CFLAGS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
66
ENV GOARCH amd64 
67
WORKDIR /go/src/github.com/ollama/ollama/llm/generate
68

69
FROM --platform=linux/amd64 cpu-builder-amd64 AS static-build-amd64
70
71
RUN --mount=type=cache,target=/root/.ccache \
    OLLAMA_CPU_TARGET="static" bash gen_linux.sh
72
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64
73
74
RUN --mount=type=cache,target=/root/.ccache \
    OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu" bash gen_linux.sh
75
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64
76
77
RUN --mount=type=cache,target=/root/.ccache \
    OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu_avx" bash gen_linux.sh
78
FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64
79
80
RUN --mount=type=cache,target=/root/.ccache \
    OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu_avx2" bash gen_linux.sh
81

82
FROM --platform=linux/arm64 rockylinux:8 AS cpu-builder-arm64
83
84
85
86
ARG CMAKE_VERSION
ARG GOLANG_VERSION
COPY ./scripts/rh_linux_deps.sh /
RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
87
ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
88
COPY --from=llm-code / /go/src/github.com/ollama/ollama/
89
90
ARG OLLAMA_CUSTOM_CPU_DEFS
ARG CGO_CFLAGS
Daniel Hiltgen's avatar
Daniel Hiltgen committed
91
ENV GOARCH arm64
92
93
94
WORKDIR /go/src/github.com/ollama/ollama/llm/generate

FROM --platform=linux/arm64 cpu-builder-arm64 AS static-build-arm64
95
96
RUN --mount=type=cache,target=/root/.ccache \
    OLLAMA_CPU_TARGET="static" bash gen_linux.sh
97
FROM --platform=linux/arm64 cpu-builder-arm64 AS cpu-build-arm64
98
99
RUN --mount=type=cache,target=/root/.ccache \
    OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu" bash gen_linux.sh
100

101

102
103
104
# Intermediate stage used for ./scripts/build_linux.sh
FROM --platform=linux/amd64 cpu-build-amd64 AS build-amd64
ENV CGO_ENABLED 1
105
WORKDIR /go/src/github.com/ollama/ollama
106
COPY . .
107
108
109
COPY --from=static-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
COPY --from=cpu_avx-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
COPY --from=cpu_avx2-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
Daniel Hiltgen's avatar
Daniel Hiltgen committed
110
COPY --from=cuda-build-amd64 /go/src/github.com/ollama/ollama/dist/ dist/
111
COPY --from=cuda-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
Daniel Hiltgen's avatar
Daniel Hiltgen committed
112
COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/dist/ dist/
113
COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
114
115
ARG GOFLAGS
ARG CGO_CFLAGS
116
117
RUN --mount=type=cache,target=/root/.ccache \
    go build -trimpath -o dist/linux-amd64/ollama .
Michael Yang's avatar
Michael Yang committed
118

119
120
121
122
# Intermediate stage used for ./scripts/build_linux.sh
FROM --platform=linux/arm64 cpu-build-arm64 AS build-arm64
ENV CGO_ENABLED 1
ARG GOLANG_VERSION
123
WORKDIR /go/src/github.com/ollama/ollama
Jeffrey Morgan's avatar
Jeffrey Morgan committed
124
COPY . .
125
COPY --from=static-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
Daniel Hiltgen's avatar
Daniel Hiltgen committed
126
COPY --from=cuda-build-arm64 /go/src/github.com/ollama/ollama/dist/ dist/
127
COPY --from=cuda-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
128
129
ARG GOFLAGS
ARG CGO_CFLAGS
130
131
RUN --mount=type=cache,target=/root/.ccache \
    go build -trimpath -o dist/linux-arm64/ollama .
Jeffrey Morgan's avatar
Jeffrey Morgan committed
132

133
# Runtime stages
Daniel Hiltgen's avatar
Daniel Hiltgen committed
134
135
FROM --platform=linux/amd64 ubuntu:22.04 as runtime-amd64
RUN apt-get update && apt-get install -y ca-certificates
Daniel Hiltgen's avatar
Daniel Hiltgen committed
136
COPY --from=build-amd64 /go/src/github.com/ollama/ollama/dist/linux-amd64/ollama /bin/ollama
137
FROM --platform=linux/arm64 ubuntu:22.04 as runtime-arm64
Michael Yang's avatar
Michael Yang committed
138
RUN apt-get update && apt-get install -y ca-certificates
Daniel Hiltgen's avatar
Daniel Hiltgen committed
139
COPY --from=build-arm64 /go/src/github.com/ollama/ollama/dist/linux-arm64/ollama /bin/ollama
140

141
# Radeon images are much larger so we keep it distinct from the CPU/CUDA image
Daniel Hiltgen's avatar
Daniel Hiltgen committed
142
FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete as runtime-rocm
143
RUN update-pciids
Daniel Hiltgen's avatar
Daniel Hiltgen committed
144
COPY --from=build-amd64 /go/src/github.com/ollama/ollama/dist/linux-amd64/ollama /bin/ollama
145
146
147
148
149
150
EXPOSE 11434
ENV OLLAMA_HOST 0.0.0.0

ENTRYPOINT ["/bin/ollama"]
CMD ["serve"]

151
FROM runtime-$TARGETARCH
152
153
EXPOSE 11434
ENV OLLAMA_HOST 0.0.0.0
154
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
155
ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
156
ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
157
ENV NVIDIA_VISIBLE_DEVICES=all
158

Jeffrey Morgan's avatar
Jeffrey Morgan committed
159
ENTRYPOINT ["/bin/ollama"]
Jeffrey Morgan's avatar
Jeffrey Morgan committed
160
CMD ["serve"]