Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

update build_darwin.sh

Michael Yang92d454ec5f3f
diff --git a/Dockerfile b/Dockerfile
index df1b18de4..17cd7fd3e 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,6 +2,7 @@ FROM nvidia/cuda:11.8.0-devel-ubuntu22.04
ARG TARGETARCH
ARG VERSION=0.0.0
+ARG GOFLAGS="'-ldflags -w -s'"
WORKDIR /go/src/github.com/jmorganca/ollama
RUN apt-get update && apt-get install -y git build-essential cmake
@@ -11,7 +12,7 @@ RUN mkdir -p /usr/local && tar xz -C /usr/local </tmp/go1.21.1.tar.gz
COPY . .
ENV GOARCH=$TARGETARCH
RUN /usr/local/go/bin/go generate ./... \
- && /usr/local/go/bin/go build -ldflags "-linkmode=external -extldflags='-static' -X=github.com/jmorganca/ollama/version.Version=$VERSION -X=github.com/jmorganca/ollama/server.mode=release" .
+ && /usr/local/go/bin/go build .
FROM ubuntu:22.04
ENV OLLAMA_HOST 0.0.0.0
diff --git a/Dockerfile.build b/Dockerfile.build
index ff85d8620..32760696e 100644
--- a/Dockerfile.build
+++ b/Dockerfile.build
@@ -1,4 +1,3 @@
-ARG VERSION=0.0.0
# centos7 amd64 dependencies
FROM --platform=linux/amd64 nvidia/cuda:11.8.0-devel-centos7 AS base-amd64
@@ -23,7 +22,11 @@ RUN mkdir -p /usr/local && tar xz -C /usr/local </tmp/go1.21.1.tar.gz
# build the final binary
WORKDIR /go/src/github.com/jmorganca/ollama
COPY . .
+ENV GOOS=linux
ENV GOARCH=$TARGETARCH
+ARG VERSION=0.0.0
+ARG GOFLAGS="'-ldflags -w -s'"
+
RUN /usr/local/go/bin/go generate ./... && \
- /usr/local/go/bin/go build -ldflags "-X=github.com/jmorganca/ollama/version.Version=$VERSION -X=github.com/jmorganca/ollama/server.mode=release" .
+ /usr/local/go/bin/go build .
diff --git a/scripts/build.sh b/scripts/build.sh
new file mode 100644
index 000000000..a50dc7dbf
--- /dev/null
+++ b/scripts/build.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -eu
+
+usage() {
+ echo "usage: $(basename $0) VERSION"
+ exit 1
+}
+
+[ "$#" -eq 1 ] || usage
+
+export VERSION="$1"
+
+# build universal MacOS binary
+sh $(dirname $0)/build_darwin.sh
+
+# # build arm64 and amd64 Linux binaries
+sh $(dirname $0)/build_linux.sh
+
+# # build arm64 and amd64 Docker images
+sh $(dirname $0)/build_docker.sh
diff --git a/scripts/build_darwin.sh b/scripts/build_darwin.sh
index 24217b1d0..54aef9a4c 100755
--- a/scripts/build_darwin.sh
+++ b/scripts/build_darwin.sh
@@ -1,29 +1,30 @@
-#!/bin/bash
+#!/bin/sh
+
+set -eu
+
+export VERSION=${VERSION:-0.0.0}
+export GOFLAGS="'-ldflags=-w -s \"-X=github.com/jmorganca/ollama/version.Version=$VERSION\" \"-X=github.com/jmorganca/ollama/server.mode=release\"'"
mkdir -p dist
-GO_LDFLAGS="-X github.com/jmorganca/ollama/version.Version=$VERSION"
-GO_LDFLAGS="$GO_LDFLAGS -X github.com/jmorganca/ollama/server.mode=release"
+for TARGETARCH in arm64 amd64; do
+ GOOS=darwin GOARCH=$TARGETARCH go generate ./...
+ GOOS=darwin GOARCH=$TARGETARCH go build -o dist/ollama-darwin-$TARGETARCH
+done
-# build universal binary
-GOARCH=arm64 go generate ./...
-GOARCH=arm64 go build -ldflags "$GO_LDFLAGS" -o dist/ollama-darwin-arm64
-rm -rf llm/llama.cpp/*/build/*/bin
-GOARCH=amd64 go generate ./...
-GOARCH=amd64 go build -ldflags "$GO_LDFLAGS" -o dist/ollama-darwin-amd64
-lipo -create -output dist/ollama dist/ollama-darwin-arm64 dist/ollama-darwin-amd64
-rm dist/ollama-darwin-amd64 dist/ollama-darwin-arm64
+lipo -create -output dist/ollama dist/ollama-darwin-*
+rm -f dist/ollama-darwin-*
codesign --deep --force --options=runtime --sign "$APPLE_IDENTITY" --timestamp dist/ollama
chmod +x dist/ollama
# build and sign the mac app
npm install --prefix app
npm run --prefix app make:sign
-cp app/out/make/zip/darwin/universal/Ollama-darwin-universal-${VERSION:-0.0.0}.zip dist/Ollama-darwin.zip
+cp app/out/make/zip/darwin/universal/Ollama-darwin-universal-$VERSION.zip dist/Ollama-darwin.zip
# sign the binary and rename it
codesign -f --timestamp -s "$APPLE_IDENTITY" --identifier ai.ollama.ollama --options=runtime dist/ollama
ditto -c -k --keepParent dist/ollama dist/temp.zip
xcrun notarytool submit dist/temp.zip --wait --timeout 10m --apple-id $APPLE_ID --password $APPLE_PASSWORD --team-id $APPLE_TEAM_ID
mv dist/ollama dist/ollama-darwin
-rm dist/temp.zip
+rm -f dist/temp.zip
diff --git a/scripts/build_docker.sh b/scripts/build_docker.sh
new file mode 100644
index 000000000..1f612def2
--- /dev/null
+++ b/scripts/build_docker.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+set -eu
+
+export VERSION=${VERSION:-0.0.0}
+export GOFLAGS="'-ldflags=-w -s \"-X=github.com/jmorganca/ollama/version.Version=$VERSION\" \"-X=github.com/jmorganca/ollama/server.mode=release\"'"
+
+docker buildx build \
+ --load \
+ --platform=linux/arm64,linux/amd64 \
+ --build-arg=VERSION \
+ --build-arg=GOFLAGS \
+ -f Dockerfile \
+ -t ollama \
+ .
diff --git a/scripts/build_linux.sh b/scripts/build_linux.sh
index 833f75714..0a1099fcd 100755
--- a/scripts/build_linux.sh
+++ b/scripts/build_linux.sh
@@ -1,12 +1,15 @@
-#!/bin/bash
+#!/bin/sh
-set -e
+set -eu
+
+export VERSION=${VERSION:-0.0.0}
+export GOFLAGS="'-ldflags=-w -s \"-X=github.com/jmorganca/ollama/version.Version=$VERSION\" \"-X=github.com/jmorganca/ollama/server.mode=release\"'"
mkdir -p dist
-for ARCH in arm64 amd64; do
- docker buildx build --platform=linux/$ARCH -f Dockerfile.build . -t builder:$ARCH --load
- docker create --platform linux/$ARCH --name builder builder:$ARCH
- docker cp builder:/go/src/github.com/jmorganca/ollama/ollama ./dist/ollama-linux-$ARCH
- docker rm builder
+for TARGETARCH in arm64 amd64; do
+ docker buildx build --load --platform=linux/$TARGETARCH --build-arg=VERSION --build-arg=GOFLAGS -f Dockerfile.build -t builder:$TARGETARCH .
+ docker create --platform linux/$TARGETARCH --name builder-$TARGETARCH builder:$TARGETARCH
+ docker cp builder-$TARGETARCH:/go/src/github.com/jmorganca/ollama/ollama ./dist/ollama-linux-$TARGETARCH
+ docker rm builder-$TARGETARCH
done