ruslanmv commited on
Commit
9115504
·
1 Parent(s): 612f6af
Files changed (1) hide show
  1. Dockerfile +148 -5
Dockerfile CHANGED
@@ -1,4 +1,147 @@
1
- FROM python:3.10-slim-buster
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  # Set the working directory
4
  WORKDIR /app
@@ -28,12 +171,12 @@ RUN python -m pip install --upgrade pip
28
  RUN pip install --no-cache-dir -r requirements.txt
29
 
30
  # Install Ollama
31
- RUN curl -fsSL https://ollama.com/install.sh | sh
32
 
33
 
34
- RUN which ollama
35
  # Expose the port the application uses (replace 11434 with the actual port)
36
- EXPOSE 11434
37
 
38
  # Copy the entire application
39
  COPY . .
@@ -41,7 +184,7 @@ COPY . .
41
  # Set proper permissions for the translations directory
42
  RUN chmod -R 777 translations
43
 
44
- RUN /usr/local/bin/ollama pull llama3
45
 
46
  # Copy the init script
47
  COPY init.sh /app/init.sh
 
1
+ ARG GOLANG_VERSION=1.22.1
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
5
+ ARG ROCM_VERSION=6.0.2
6
+
7
+ # Copy the minimal context we need to run the generate scripts
8
+ FROM scratch AS llm-code
9
+ COPY .git .git
10
+ COPY .gitmodules .gitmodules
11
+ COPY llm llm
12
+
13
+ FROM --platform=linux/amd64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-build-amd64
14
+ ARG CMAKE_VERSION
15
+ COPY ./scripts/rh_linux_deps.sh /
16
+ RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
17
+ ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
18
+ COPY --from=llm-code / /go/src/github.com/ollama/ollama/
19
+ WORKDIR /go/src/github.com/ollama/ollama/llm/generate
20
+ ARG CGO_CFLAGS
21
+ RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
22
+
23
+ FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-rockylinux8 AS cuda-build-arm64
24
+ ARG CMAKE_VERSION
25
+ COPY ./scripts/rh_linux_deps.sh /
26
+ RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
27
+ ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
28
+ COPY --from=llm-code / /go/src/github.com/ollama/ollama/
29
+ WORKDIR /go/src/github.com/ollama/ollama/llm/generate
30
+ ARG CGO_CFLAGS
31
+ RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
32
+
33
+ FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete AS rocm-build-amd64
34
+ ARG CMAKE_VERSION
35
+ COPY ./scripts/rh_linux_deps.sh /
36
+ RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
37
+ ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
38
+ ENV LIBRARY_PATH /opt/amdgpu/lib64
39
+ COPY --from=llm-code / /go/src/github.com/ollama/ollama/
40
+ WORKDIR /go/src/github.com/ollama/ollama/llm/generate
41
+ ARG CGO_CFLAGS
42
+ ARG AMDGPU_TARGETS
43
+ RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
44
+ RUN mkdir /tmp/scratch && \
45
+ for dep in $(zcat /go/src/github.com/ollama/ollama/llm/build/linux/x86_64/rocm*/bin/deps.txt.gz) ; do \
46
+ cp ${dep} /tmp/scratch/ || exit 1 ; \
47
+ done && \
48
+ (cd /opt/rocm/lib && tar cf - rocblas/library) | (cd /tmp/scratch/ && tar xf - ) && \
49
+ mkdir -p /go/src/github.com/ollama/ollama/dist/deps/ && \
50
+ (cd /tmp/scratch/ && tar czvf /go/src/github.com/ollama/ollama/dist/deps/ollama-linux-amd64-rocm.tgz . )
51
+
52
+
53
+ FROM --platform=linux/amd64 centos:7 AS cpu-builder-amd64
54
+ ARG CMAKE_VERSION
55
+ ARG GOLANG_VERSION
56
+ COPY ./scripts/rh_linux_deps.sh /
57
+ RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
58
+ ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
59
+ COPY --from=llm-code / /go/src/github.com/ollama/ollama/
60
+ ARG OLLAMA_CUSTOM_CPU_DEFS
61
+ ARG CGO_CFLAGS
62
+ WORKDIR /go/src/github.com/ollama/ollama/llm/generate
63
+
64
+ FROM --platform=linux/amd64 cpu-builder-amd64 AS static-build-amd64
65
+ RUN OLLAMA_CPU_TARGET="static" sh gen_linux.sh
66
+ FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64
67
+ RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
68
+ FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64
69
+ RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu_avx" sh gen_linux.sh
70
+ FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64
71
+ RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu_avx2" sh gen_linux.sh
72
+
73
+ FROM --platform=linux/arm64 centos:7 AS cpu-builder-arm64
74
+ ARG CMAKE_VERSION
75
+ ARG GOLANG_VERSION
76
+ COPY ./scripts/rh_linux_deps.sh /
77
+ RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
78
+ ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
79
+ COPY --from=llm-code / /go/src/github.com/ollama/ollama/
80
+ ARG OLLAMA_CUSTOM_CPU_DEFS
81
+ ARG CGO_CFLAGS
82
+ WORKDIR /go/src/github.com/ollama/ollama/llm/generate
83
+
84
+ FROM --platform=linux/arm64 cpu-builder-arm64 AS static-build-arm64
85
+ RUN OLLAMA_CPU_TARGET="static" sh gen_linux.sh
86
+ FROM --platform=linux/arm64 cpu-builder-arm64 AS cpu-build-arm64
87
+ RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
88
+
89
+
90
+ # Intermediate stage used for ./scripts/build_linux.sh
91
+ FROM --platform=linux/amd64 cpu-build-amd64 AS build-amd64
92
+ ENV CGO_ENABLED 1
93
+ WORKDIR /go/src/github.com/ollama/ollama
94
+ COPY . .
95
+ COPY --from=static-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
96
+ COPY --from=cpu_avx-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
97
+ COPY --from=cpu_avx2-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
98
+ COPY --from=cuda-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
99
+ COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
100
+ COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/dist/deps/ ./dist/deps/
101
+ ARG GOFLAGS
102
+ ARG CGO_CFLAGS
103
+ RUN go build -trimpath .
104
+
105
+ # Intermediate stage used for ./scripts/build_linux.sh
106
+ FROM --platform=linux/arm64 cpu-build-arm64 AS build-arm64
107
+ ENV CGO_ENABLED 1
108
+ ARG GOLANG_VERSION
109
+ WORKDIR /go/src/github.com/ollama/ollama
110
+ COPY . .
111
+ COPY --from=static-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
112
+ COPY --from=cuda-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
113
+ ARG GOFLAGS
114
+ ARG CGO_CFLAGS
115
+ RUN go build -trimpath .
116
+
117
+ # Runtime stages
118
+ FROM --platform=linux/amd64 ubuntu:22.04 as runtime-amd64
119
+ RUN apt-get update && apt-get install -y ca-certificates
120
+ COPY --from=build-amd64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
121
+ FROM --platform=linux/arm64 ubuntu:22.04 as runtime-arm64
122
+ RUN apt-get update && apt-get install -y ca-certificates
123
+ COPY --from=build-arm64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
124
+
125
+ # Radeon images are much larger so we keep it distinct from the CPU/CUDA image
126
+ FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete as runtime-rocm
127
+ RUN update-pciids
128
+ COPY --from=build-amd64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
129
+ EXPOSE 11434
130
+ ENV OLLAMA_HOST 0.0.0.0
131
+
132
+ ENTRYPOINT ["/bin/ollama"]
133
+ CMD ["serve"]
134
+
135
+ FROM runtime-$TARGETARCH
136
+ EXPOSE 11434
137
+ ENV OLLAMA_HOST 0.0.0.0
138
+ ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
139
+ ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
140
+ ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
141
+ ENV NVIDIA_VISIBLE_DEVICES=all
142
+
143
+ ENTRYPOINT ["/bin/ollama"]
144
+ CMD ["serve"]
145
 
146
  # Set the working directory
147
  WORKDIR /app
 
171
  RUN pip install --no-cache-dir -r requirements.txt
172
 
173
  # Install Ollama
174
+ #RUN curl -fsSL https://ollama.com/install.sh | sh
175
 
176
 
177
+ #RUN which ollama
178
  # Expose the port the application uses (replace 11434 with the actual port)
179
+ #EXPOSE 11434
180
 
181
  # Copy the entire application
182
  COPY . .
 
184
  # Set proper permissions for the translations directory
185
  RUN chmod -R 777 translations
186
 
187
+ #RUN /usr/local/bin/ollama pull llama3
188
 
189
  # Copy the init script
190
  COPY init.sh /app/init.sh