build_linux.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. #
  3. # Mac ARM users, rosetta can be flaky, so to use a remote x86 builder
  4. #
  5. # docker context create amd64 --docker host=ssh://mybuildhost
  6. # docker buildx create --name mybuilder amd64 --platform linux/amd64
  7. # docker buildx create --name mybuilder --append desktop-linux --platform linux/arm64
  8. # docker buildx use mybuilder
  9. set -eu
  10. . $(dirname $0)/env.sh
  11. mkdir -p dist
  12. docker buildx build \
  13. --output type=local,dest=./dist/ \
  14. --platform=${PLATFORM} \
  15. ${OLLAMA_COMMON_BUILD_ARGS} \
  16. --target archive \
  17. -f Dockerfile \
  18. .
  19. if echo $PLATFORM | grep "amd64" > /dev/null; then
  20. outDir="./dist"
  21. if echo $PLATFORM | grep "," > /dev/null ; then
  22. outDir="./dist/linux_amd64"
  23. fi
  24. docker buildx build \
  25. --output type=local,dest=${outDir} \
  26. --platform=linux/amd64 \
  27. ${OLLAMA_COMMON_BUILD_ARGS} \
  28. --build-arg FLAVOR=rocm \
  29. --target archive \
  30. -f Dockerfile \
  31. .
  32. fi
  33. # buildx behavior changes for single vs. multiplatform
  34. echo "Compressing linux tar bundles..."
  35. if echo $PLATFORM | grep "," > /dev/null ; then
  36. tar c -C ./dist/linux_arm64 --exclude cuda_jetpack5 --exclude cuda_jetpack6 . | pigz -9vc >./dist/ollama-linux-arm64.tgz
  37. tar c -C ./dist/linux_arm64 ./lib/ollama/cuda_jetpack5 | pigz -9vc >./dist/ollama-linux-arm64-jetpack5.tgz
  38. tar c -C ./dist/linux_arm64 ./lib/ollama/cuda_jetpack6 | pigz -9vc >./dist/ollama-linux-arm64-jetpack6.tgz
  39. tar c -C ./dist/linux_amd64 --exclude rocm . | pigz -9vc >./dist/ollama-linux-amd64.tgz
  40. tar c -C ./dist/linux_amd64 ./lib/ollama/rocm | pigz -9vc >./dist/ollama-linux-amd64-rocm.tgz
  41. elif echo $PLATFORM | grep "arm64" > /dev/null ; then
  42. tar c -C ./dist/ --exclude cuda_jetpack5 --exclude cuda_jetpack6 bin lib | pigz -9vc >./dist/ollama-linux-arm64.tgz
  43. tar c -C ./dist/ ./lib/ollama/cuda_jetpack5 | pigz -9vc >./dist/ollama-linux-arm64-jetpack5.tgz
  44. tar c -C ./dist/ ./lib/ollama/cuda_jetpack6 | pigz -9vc >./dist/ollama-linux-arm64-jetpack6.tgz
  45. elif echo $PLATFORM | grep "amd64" > /dev/null ; then
  46. tar c -C ./dist/ --exclude rocm bin lib | pigz -9vc >./dist/ollama-linux-amd64.tgz
  47. tar c -C ./dist/ ./lib/ollama/rocm | pigz -9vc >./dist/ollama-linux-amd64-rocm.tgz
  48. fi