Dockerfile 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.1.1
  6. # Copy the minimal context we need to run the generate scripts
  7. FROM scratch AS llm-code
  8. COPY .git .git
  9. COPY .gitmodules .gitmodules
  10. COPY llm llm
  11. FROM --platform=linux/amd64 nvidia/cuda:$CUDA_VERSION-devel-centos7 AS cuda-build-amd64
  12. ARG CMAKE_VERSION
  13. COPY ./scripts/rh_linux_deps.sh /
  14. RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
  15. ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
  16. COPY --from=llm-code / /go/src/github.com/ollama/ollama/
  17. WORKDIR /go/src/github.com/ollama/ollama/llm/generate
  18. ARG CGO_CFLAGS
  19. RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
  20. FROM --platform=linux/arm64 nvidia/cuda:$CUDA_VERSION-devel-rockylinux8 AS cuda-build-arm64
  21. ARG CMAKE_VERSION
  22. COPY ./scripts/rh_linux_deps.sh /
  23. RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
  24. ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
  25. COPY --from=llm-code / /go/src/github.com/ollama/ollama/
  26. WORKDIR /go/src/github.com/ollama/ollama/llm/generate
  27. ARG CGO_CFLAGS
  28. RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
  29. FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete AS rocm-build-amd64
  30. ARG CMAKE_VERSION
  31. COPY ./scripts/rh_linux_deps.sh /
  32. RUN CMAKE_VERSION=${CMAKE_VERSION} sh /rh_linux_deps.sh
  33. ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
  34. ENV LIBRARY_PATH /opt/amdgpu/lib64
  35. COPY --from=llm-code / /go/src/github.com/ollama/ollama/
  36. WORKDIR /go/src/github.com/ollama/ollama/llm/generate
  37. ARG CGO_CFLAGS
  38. ARG AMDGPU_TARGETS
  39. RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_SKIP_CPU_GENERATE=1 sh gen_linux.sh
  40. RUN mkdir /tmp/scratch && \
  41. for dep in $(zcat /go/src/github.com/ollama/ollama/llm/build/linux/x86_64/rocm*/bin/deps.txt.gz) ; do \
  42. cp ${dep} /tmp/scratch/ || exit 1 ; \
  43. done && \
  44. (cd /opt/rocm/lib && tar cf - rocblas/library) | (cd /tmp/scratch/ && tar xf - ) && \
  45. mkdir -p /go/src/github.com/ollama/ollama/dist/deps/ && \
  46. (cd /tmp/scratch/ && tar czvf /go/src/github.com/ollama/ollama/dist/deps/ollama-linux-amd64-rocm.tgz . )
  47. FROM --platform=linux/amd64 centos:7 AS cpu-builder-amd64
  48. ARG CMAKE_VERSION
  49. ARG GOLANG_VERSION
  50. COPY ./scripts/rh_linux_deps.sh /
  51. RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
  52. ENV PATH /opt/rh/devtoolset-10/root/usr/bin:$PATH
  53. COPY --from=llm-code / /go/src/github.com/ollama/ollama/
  54. ARG OLLAMA_CUSTOM_CPU_DEFS
  55. ARG CGO_CFLAGS
  56. WORKDIR /go/src/github.com/ollama/ollama/llm/generate
  57. FROM --platform=linux/amd64 cpu-builder-amd64 AS static-build-amd64
  58. RUN OLLAMA_CPU_TARGET="static" sh gen_linux.sh
  59. FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu-build-amd64
  60. RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
  61. FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx-build-amd64
  62. RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu_avx" sh gen_linux.sh
  63. FROM --platform=linux/amd64 cpu-builder-amd64 AS cpu_avx2-build-amd64
  64. RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu_avx2" sh gen_linux.sh
  65. FROM --platform=linux/arm64 rockylinux:8 AS cpu-builder-arm64
  66. ARG CMAKE_VERSION
  67. ARG GOLANG_VERSION
  68. COPY ./scripts/rh_linux_deps.sh /
  69. RUN CMAKE_VERSION=${CMAKE_VERSION} GOLANG_VERSION=${GOLANG_VERSION} sh /rh_linux_deps.sh
  70. ENV PATH /opt/rh/gcc-toolset-10/root/usr/bin:$PATH
  71. COPY --from=llm-code / /go/src/github.com/ollama/ollama/
  72. ARG OLLAMA_CUSTOM_CPU_DEFS
  73. ARG CGO_CFLAGS
  74. WORKDIR /go/src/github.com/ollama/ollama/llm/generate
  75. FROM --platform=linux/arm64 cpu-builder-arm64 AS static-build-arm64
  76. RUN OLLAMA_CPU_TARGET="static" sh gen_linux.sh
  77. FROM --platform=linux/arm64 cpu-builder-arm64 AS cpu-build-arm64
  78. RUN OLLAMA_SKIP_STATIC_GENERATE=1 OLLAMA_CPU_TARGET="cpu" sh gen_linux.sh
  79. # Intermediate stage used for ./scripts/build_linux.sh
  80. FROM --platform=linux/amd64 cpu-build-amd64 AS build-amd64
  81. ENV CGO_ENABLED 1
  82. WORKDIR /go/src/github.com/ollama/ollama
  83. COPY . .
  84. COPY --from=static-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
  85. COPY --from=cpu_avx-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
  86. COPY --from=cpu_avx2-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
  87. COPY --from=cuda-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
  88. COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
  89. COPY --from=rocm-build-amd64 /go/src/github.com/ollama/ollama/dist/deps/ ./dist/deps/
  90. ARG GOFLAGS
  91. ARG CGO_CFLAGS
  92. RUN go build -trimpath .
  93. # Intermediate stage used for ./scripts/build_linux.sh
  94. FROM --platform=linux/arm64 cpu-build-arm64 AS build-arm64
  95. ENV CGO_ENABLED 1
  96. ARG GOLANG_VERSION
  97. WORKDIR /go/src/github.com/ollama/ollama
  98. COPY . .
  99. COPY --from=static-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
  100. COPY --from=cuda-build-arm64 /go/src/github.com/ollama/ollama/llm/build/linux/ llm/build/linux/
  101. ARG GOFLAGS
  102. ARG CGO_CFLAGS
  103. RUN go build -trimpath .
  104. # Runtime stages
  105. FROM --platform=linux/amd64 ubuntu:22.04 as runtime-amd64
  106. RUN apt-get update && apt-get install -y ca-certificates
  107. COPY --from=build-amd64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
  108. FROM --platform=linux/arm64 ubuntu:22.04 as runtime-arm64
  109. RUN apt-get update && apt-get install -y ca-certificates
  110. COPY --from=build-arm64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
  111. # Radeon images are much larger so we keep it distinct from the CPU/CUDA image
  112. FROM --platform=linux/amd64 rocm/dev-centos-7:${ROCM_VERSION}-complete as runtime-rocm
  113. RUN update-pciids
  114. COPY --from=build-amd64 /go/src/github.com/ollama/ollama/ollama /bin/ollama
  115. EXPOSE 11434
  116. ENV OLLAMA_HOST 0.0.0.0
  117. ENTRYPOINT ["/bin/ollama"]
  118. CMD ["serve"]
  119. FROM runtime-$TARGETARCH
  120. EXPOSE 11434
  121. ENV OLLAMA_HOST 0.0.0.0
  122. ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  123. ENV LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64
  124. ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
  125. ENV NVIDIA_VISIBLE_DEVICES=all
  126. ENTRYPOINT ["/bin/ollama"]
  127. CMD ["serve"]