build_linux.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. set -eu
  3. export VERSION=${VERSION:-$(git describe --tags --first-parent --abbrev=7 --long --dirty --always | sed -e "s/^v//g")}
  4. export GOFLAGS="'-ldflags=-w -s \"-X=github.com/ollama/ollama/version.Version=$VERSION\" \"-X=github.com/ollama/ollama/server.mode=release\"'"
  5. BUILD_ARCH=${BUILD_ARCH:-"amd64 arm64"}
  6. export AMDGPU_TARGETS=${AMDGPU_TARGETS:=""}
  7. mkdir -p dist
  8. for TARGETARCH in ${BUILD_ARCH}; do
  9. docker build \
  10. --platform=linux/$TARGETARCH \
  11. --build-arg=GOFLAGS \
  12. --build-arg=CGO_CFLAGS \
  13. --build-arg=OLLAMA_CUSTOM_CPU_DEFS \
  14. --build-arg=AMDGPU_TARGETS \
  15. --target build-$TARGETARCH \
  16. -f Dockerfile \
  17. -t builder:$TARGETARCH \
  18. .
  19. docker create --platform linux/$TARGETARCH --name builder-$TARGETARCH builder:$TARGETARCH
  20. docker cp builder-$TARGETARCH:/go/src/github.com/ollama/ollama/ollama ./dist/ollama-linux-$TARGETARCH
  21. if [ "$TARGETARCH" = "amd64" ]; then
  22. docker cp builder-$TARGETARCH:/go/src/github.com/ollama/ollama/dist/deps/ ./dist/
  23. fi
  24. docker rm builder-$TARGETARCH
  25. done