2023-09-26 17:38:32 +00:00
|
|
|
#!/bin/sh
|
2023-09-22 19:20:12 +00:00
|
|
|
|
2023-09-26 17:38:32 +00:00
|
|
|
set -eu
|
|
|
|
|
2024-01-23 01:12:20 +00:00
|
|
|
export VERSION=${VERSION:-$(git describe --tags --first-parent --abbrev=7 --long --dirty --always | sed -e "s/^v//g")}
|
2024-03-26 20:04:17 +00:00
|
|
|
export GOFLAGS="'-ldflags=-w -s \"-X=github.com/ollama/ollama/version.Version=$VERSION\" \"-X=github.com/ollama/ollama/server.mode=release\"'"
|
2024-08-09 14:21:40 +00:00
|
|
|
GZIP=$(which pigz 2>/dev/null || echo "gzip")
|
2023-09-22 19:20:12 +00:00
|
|
|
|
2024-01-10 22:41:02 +00:00
|
|
|
BUILD_ARCH=${BUILD_ARCH:-"amd64 arm64"}
|
2024-01-21 20:57:13 +00:00
|
|
|
export AMDGPU_TARGETS=${AMDGPU_TARGETS:=""}
|
2023-09-22 19:20:12 +00:00
|
|
|
mkdir -p dist
|
|
|
|
|
2024-01-10 22:41:02 +00:00
|
|
|
for TARGETARCH in ${BUILD_ARCH}; do
|
2024-01-21 19:37:11 +00:00
|
|
|
docker build \
|
|
|
|
--platform=linux/$TARGETARCH \
|
|
|
|
--build-arg=GOFLAGS \
|
|
|
|
--build-arg=CGO_CFLAGS \
|
|
|
|
--build-arg=OLLAMA_CUSTOM_CPU_DEFS \
|
2024-01-21 20:57:13 +00:00
|
|
|
--build-arg=AMDGPU_TARGETS \
|
2024-01-21 19:37:11 +00:00
|
|
|
--target build-$TARGETARCH \
|
|
|
|
-f Dockerfile \
|
|
|
|
-t builder:$TARGETARCH \
|
|
|
|
.
|
2023-12-22 00:54:54 +00:00
|
|
|
docker create --platform linux/$TARGETARCH --name builder-$TARGETARCH builder:$TARGETARCH
|
2024-05-31 04:54:07 +00:00
|
|
|
rm -rf ./dist/linux-$TARGETARCH
|
2024-07-08 19:50:11 +00:00
|
|
|
docker cp builder-$TARGETARCH:/go/src/github.com/ollama/ollama/dist/linux-$TARGETARCH ./dist
|
2024-08-20 14:26:38 +00:00
|
|
|
if echo ${TARGETARCH} | grep "amd64" > /dev/null; then
|
|
|
|
docker cp builder-$TARGETARCH:/go/src/github.com/ollama/ollama/dist/linux-$TARGETARCH-rocm ./dist
|
|
|
|
fi
|
2023-12-22 00:54:54 +00:00
|
|
|
docker rm builder-$TARGETARCH
|
2024-07-08 19:50:11 +00:00
|
|
|
echo "Compressing final linux bundle..."
|
|
|
|
rm -f ./dist/ollama-linux-$TARGETARCH.tgz
|
2024-08-09 14:21:40 +00:00
|
|
|
(cd dist/linux-$TARGETARCH && tar cf - . | ${GZIP} --best > ../ollama-linux-$TARGETARCH.tgz )
|
2024-08-20 14:26:38 +00:00
|
|
|
if [ -d dist/linux-$TARGETARCH-rocm ]; then
|
|
|
|
(cd dist/linux-$TARGETARCH-rocm && tar cf - . | ${GZIP} --best > ../ollama-linux-$TARGETARCH-rocm.tgz )
|
|
|
|
fi
|
2023-09-22 19:20:12 +00:00
|
|
|
done
|