Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions Dockerfile-ollama-local
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ FROM python:3.11-slim AS ollama_base
RUN apt-get update && apt-get install -y \
curl
# Detect architecture and download appropriate Ollama version
# ARG TARGETARCH can be set at build time with --build-arg TARGETARCH=arm64 or TARGETARCH=amd64
ARG TARGETARCH=arm64
RUN OLLAMA_ARCH="" && \
if [ "$TARGETARCH" = "arm64" ]; then \
echo "Building for ARM64 architecture." && \
OLLAMA_ARCH="arm64"; \
elif [ "$TARGETARCH" = "amd64" ]; then \
echo "Building for AMD64 architecture." && \
OLLAMA_ARCH="amd64"; \
RUN OLLAMA_ARCH=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) && \
if [ "$OLLAMA_ARCH" = "arm64" ]; then \
echo "Building for ARM64 architecture."; \
elif [ "$OLLAMA_ARCH" = "amd64" ]; then \
echo "Building for AMD64 architecture."; \
else \
echo "Error: Unsupported architecture '$TARGETARCH'. Supported architectures are 'arm64' and 'amd64'." >&2 && \
echo "Error: Unsupported architecture '$OLLAMA_ARCH'. Supported architectures are 'arm64' and 'amd64'." >&2 && \
exit 1; \
fi && \
Comment on lines +27 to 35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While the if/elif/else structure works, using a case statement is more idiomatic and readable for shell scripts when checking a variable against multiple possible values. This also provides an opportunity to use the more portable uname -m command instead of arch, slightly optimize the sed command by combining expressions, and remove unnecessary semicolons.

RUN OLLAMA_ARCH=$(uname -m | sed -e 's/aarch64/arm64/' -e 's/x86_64/amd64/') && \
    case "$OLLAMA_ARCH" in \
        arm64) \
            echo "Building for ARM64 architecture." \
            ;; \
        amd64) \
            echo "Building for AMD64 architecture." \
            ;; \
        *) \
            echo "Error: Unsupported architecture '$OLLAMA_ARCH'. Supported architectures are 'arm64' and 'amd64'." >&2 && \
            exit 1 \
            ;; \
    esac && \

curl -L "https://ollama.com/download/ollama-linux-${OLLAMA_ARCH}.tgz" -o ollama.tgz && \
Expand Down