From 1e99c1bb50ffcf2813c4dbf9d225510c4f0711be Mon Sep 17 00:00:00 2001 From: Shang Chieh Tseng Date: Wed, 17 Dec 2025 00:42:04 +0800 Subject: [PATCH] Fix version injection for docker builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add OLLAMA_VERSION build arg to Dockerfiles - Update Makefile to pass version via --build-arg - Add .env.example as local development reference - Update build.yml to use cicd-1 environment for vars.OLLAMA_VERSION Fixes #8 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .github/workflows/build.yml | 3 +++ docker/.env.example | 11 +++++++++++ docker/Makefile | 18 +++++++++++++++--- docker/runtime/Dockerfile | 4 +++- docker/runtime/Dockerfile.local | 4 +++- 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 docker/.env.example diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 71e8b69e..3901711f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,6 +38,9 @@ jobs: build: name: Build Verification runs-on: self-hosted + environment: cicd-1 + env: + OLLAMA_VERSION: ${{ vars.OLLAMA_VERSION || '0.0.0' }} outputs: result: ${{ steps.build-tests.outcome }} diff --git a/docker/.env.example b/docker/.env.example new file mode 100644 index 00000000..99b1934c --- /dev/null +++ b/docker/.env.example @@ -0,0 +1,11 @@ +# Ollama37 Build Configuration +# Copy this file to .env and customize as needed +# +# Usage: +# cp .env.example .env +# # Edit .env with your values +# make build + +# Ollama version to embed in the binary +# This version is displayed by 'ollama --version' and in logs +OLLAMA_VERSION=2.0.1 diff --git a/docker/Makefile b/docker/Makefile index 85fe2d76..0a7907f1 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -22,12 +22,17 @@ # docker-compose logs -f # docker-compose down +# Load .env file if it exists (for local development) +-include .env + # Configuration BUILDER_IMAGE := ollama37-builder BUILDER_TAG := latest RUNTIME_IMAGE := ollama37 RUNTIME_TAG := latest SOURCE_DIR := $(shell cd .. && pwd) +# Version: environment variable > .env file > fallback 0.0.0 +OLLAMA_VERSION ?= 0.0.0 BUILDER_DOCKERFILE := $(SOURCE_DIR)/docker/builder/Dockerfile RUNTIME_DOCKERFILE := $(SOURCE_DIR)/docker/runtime/Dockerfile @@ -87,6 +92,7 @@ build-runtime: ensure-builder @echo " - Package runtime environment" @echo "" @docker build \ + --build-arg OLLAMA_VERSION=$(OLLAMA_VERSION) \ -f $(RUNTIME_DOCKERFILE) \ -t $(RUNTIME_IMAGE):$(RUNTIME_TAG) \ $(RUNTIME_CONTEXT) @@ -102,15 +108,17 @@ build-runtime-no-cache: ensure-builder @echo " Image: $(RUNTIME_IMAGE):$(RUNTIME_TAG)" @echo " Dockerfile: $(RUNTIME_DOCKERFILE)" @echo " Source: GitHub (fresh clone, no cache)" + @echo " Version: $(OLLAMA_VERSION)" @echo "" @echo " This will:" @echo " - Force fresh clone from GitHub" @echo " - Rebuild all layers without cache" @echo " - Configure with CMake (CUDA 11 preset)" @echo " - Compile C/C++/CUDA libraries" - @echo " - Build Go binary" + @echo " - Build Go binary with version $(OLLAMA_VERSION)" @echo "" @docker build --no-cache \ + --build-arg OLLAMA_VERSION=$(OLLAMA_VERSION) \ -f $(RUNTIME_DOCKERFILE) \ -t $(RUNTIME_IMAGE):$(RUNTIME_TAG) \ $(RUNTIME_CONTEXT) @@ -126,15 +134,17 @@ build-runtime-local: ensure-builder @echo " Image: $(RUNTIME_IMAGE):$(RUNTIME_TAG)" @echo " Dockerfile: $(RUNTIME_DOCKERFILE_LOCAL)" @echo " Source: Local directory (uses cache)" + @echo " Version: $(OLLAMA_VERSION)" @echo "" @echo " This will:" @echo " - Copy local source code to container" @echo " - Configure with CMake (CUDA 11 preset)" @echo " - Compile C/C++/CUDA libraries" - @echo " - Build Go binary" + @echo " - Build Go binary with version $(OLLAMA_VERSION)" @echo " - Package runtime environment" @echo "" @docker build \ + --build-arg OLLAMA_VERSION=$(OLLAMA_VERSION) \ -f $(RUNTIME_DOCKERFILE_LOCAL) \ -t $(RUNTIME_IMAGE):$(RUNTIME_TAG) \ $(RUNTIME_CONTEXT) @@ -150,15 +160,17 @@ build-runtime-local-no-cache: ensure-builder @echo " Image: $(RUNTIME_IMAGE):$(RUNTIME_TAG)" @echo " Dockerfile: $(RUNTIME_DOCKERFILE_LOCAL)" @echo " Source: Local directory (no cache)" + @echo " Version: $(OLLAMA_VERSION)" @echo "" @echo " This will:" @echo " - Copy local source code to container" @echo " - Rebuild all layers without cache" @echo " - Configure with CMake (CUDA 11 preset)" @echo " - Compile C/C++/CUDA libraries" - @echo " - Build Go binary" + @echo " - Build Go binary with version $(OLLAMA_VERSION)" @echo "" @docker build --no-cache \ + --build-arg OLLAMA_VERSION=$(OLLAMA_VERSION) \ -f $(RUNTIME_DOCKERFILE_LOCAL) \ -t $(RUNTIME_IMAGE):$(RUNTIME_TAG) \ $(RUNTIME_CONTEXT) diff --git a/docker/runtime/Dockerfile b/docker/runtime/Dockerfile index 9f95776c..8a71ad21 100644 --- a/docker/runtime/Dockerfile +++ b/docker/runtime/Dockerfile @@ -32,7 +32,9 @@ RUN bash -c 'LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:/usr/lib64:$LD_LIBR # Build Go binary # VCS info is embedded automatically since we cloned from git # Build to source directory so binary can find libraries via relative path -RUN go build -o ./ollama . +# Set version via -ldflags - pass OLLAMA_VERSION as build arg +ARG OLLAMA_VERSION +RUN go build -ldflags "-X github.com/ollama/ollama/version.Version=${OLLAMA_VERSION}" -o ./ollama . # Create symlink to standard binary location # The code in ml/path.go uses filepath.EvalSymlinks() which resolves this symlink diff --git a/docker/runtime/Dockerfile.local b/docker/runtime/Dockerfile.local index 3f4f12e3..5bab0020 100644 --- a/docker/runtime/Dockerfile.local +++ b/docker/runtime/Dockerfile.local @@ -36,7 +36,9 @@ RUN bash -c 'LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:/usr/lib64:$LD_LIBR # Build Go binary # Build to source directory so binary can find libraries via relative path -RUN go build -o ./ollama . +# Set version via -ldflags - pass OLLAMA_VERSION as build arg +ARG OLLAMA_VERSION +RUN go build -ldflags "-X github.com/ollama/ollama/version.Version=${OLLAMA_VERSION}" -o ./ollama . # Create symlink to standard binary location # The code in ml/path.go uses filepath.EvalSymlinks() which resolves this symlink