2023-09-26 17:38:32 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
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\"'"
|
2023-09-26 17:38:32 +00:00
|
|
|
|
2024-03-07 18:54:21 +00:00
|
|
|
# We use 2 different image repositories to handle combining architecture images into multiarch manifest
|
|
|
|
# (The ROCm image is x86 only and is not a multiarch manifest)
|
|
|
|
# For developers, you can override the DOCKER_ORG to generate multiarch manifests
|
|
|
|
# DOCKER_ORG=jdoe PUSH=1 ./scripts/build_docker.sh
|
|
|
|
DOCKER_ORG=${DOCKER_ORG:-"ollama"}
|
2024-03-28 22:34:19 +00:00
|
|
|
RELEASE_IMAGE_REPO=${RELEASE_IMAGE_REPO:-"${DOCKER_ORG}/release"}
|
2024-03-07 18:54:21 +00:00
|
|
|
FINAL_IMAGE_REPO=${FINAL_IMAGE_REPO:-"${DOCKER_ORG}/ollama"}
|
|
|
|
|
|
|
|
BUILD_ARCH=${BUILD_ARCH:-"amd64 arm64"}
|
|
|
|
|
|
|
|
# Set PUSH to a non-empty string to trigger push instead of load
|
|
|
|
PUSH=${PUSH:-""}
|
|
|
|
|
|
|
|
# In CI mode, we break things down
|
|
|
|
OLLAMA_SKIP_MANIFEST_CREATE=${OLLAMA_SKIP_MANIFEST_CREATE:-""}
|
|
|
|
OLLAMA_SKIP_IMAGE_BUILD=${OLLAMA_SKIP_IMAGE_BUILD:-""}
|
|
|
|
|
|
|
|
if [ -z "${PUSH}" ] ; then
|
|
|
|
LOAD_OR_PUSH="--load"
|
|
|
|
else
|
2024-03-28 22:34:19 +00:00
|
|
|
echo "Will be pushing ${RELEASE_IMAGE_REPO}:$VERSION for ${BUILD_ARCH}"
|
2024-03-07 18:54:21 +00:00
|
|
|
LOAD_OR_PUSH="--push"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${OLLAMA_SKIP_IMAGE_BUILD}" ]; then
|
|
|
|
for TARGETARCH in ${BUILD_ARCH}; do
|
|
|
|
docker build \
|
|
|
|
${LOAD_OR_PUSH} \
|
|
|
|
--platform=linux/${TARGETARCH} \
|
|
|
|
--build-arg=VERSION \
|
|
|
|
--build-arg=GOFLAGS \
|
|
|
|
-f Dockerfile \
|
2024-03-28 22:34:19 +00:00
|
|
|
-t ${RELEASE_IMAGE_REPO}:$VERSION-${TARGETARCH} \
|
2024-03-07 18:54:21 +00:00
|
|
|
.
|
|
|
|
done
|
|
|
|
|
|
|
|
if echo ${BUILD_ARCH} | grep "amd64" > /dev/null; then
|
|
|
|
docker build \
|
|
|
|
${LOAD_OR_PUSH} \
|
|
|
|
--platform=linux/amd64 \
|
|
|
|
--build-arg=VERSION \
|
|
|
|
--build-arg=GOFLAGS \
|
|
|
|
--target runtime-rocm \
|
|
|
|
-f Dockerfile \
|
2024-03-28 22:34:19 +00:00
|
|
|
-t ${RELEASE_IMAGE_REPO}:$VERSION-rocm \
|
2024-03-07 18:54:21 +00:00
|
|
|
.
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${OLLAMA_SKIP_MANIFEST_CREATE}" ]; then
|
|
|
|
if [ -n "${PUSH}" ]; then
|
|
|
|
docker manifest create ${FINAL_IMAGE_REPO}:$VERSION \
|
2024-03-28 22:34:19 +00:00
|
|
|
${RELEASE_IMAGE_REPO}:$VERSION-amd64 \
|
|
|
|
${RELEASE_IMAGE_REPO}:$VERSION-arm64
|
2024-03-07 18:54:21 +00:00
|
|
|
docker manifest push ${FINAL_IMAGE_REPO}:$VERSION
|
|
|
|
|
|
|
|
# For symmetry, tag/push the rocm image
|
2024-03-28 22:34:19 +00:00
|
|
|
if [ "${RELEASE_IMAGE_REPO}" != "${FINAL_IMAGE_REPO}" ]; then
|
2024-03-07 18:54:21 +00:00
|
|
|
echo "Tagging and pushing rocm image"
|
2024-03-28 22:34:19 +00:00
|
|
|
docker pull ${RELEASE_IMAGE_REPO}:$VERSION-rocm
|
|
|
|
docker tag ${RELEASE_IMAGE_REPO}:$VERSION-rocm ${FINAL_IMAGE_REPO}:$VERSION-rocm
|
2024-03-07 18:54:21 +00:00
|
|
|
docker push ${FINAL_IMAGE_REPO}:$VERSION-rocm
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Skipping manifest generation when not pushing images are available locally as "
|
2024-03-28 22:34:19 +00:00
|
|
|
echo " ${RELEASE_IMAGE_REPO}:$VERSION-amd64"
|
|
|
|
echo " ${RELEASE_IMAGE_REPO}:$VERSION-arm64"
|
|
|
|
echo " ${RELEASE_IMAGE_REPO}:$VERSION-rocm"
|
2024-03-07 18:54:21 +00:00
|
|
|
fi
|
2024-03-26 20:04:17 +00:00
|
|
|
fi
|