Fix version injection for docker builds

- 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 <noreply@anthropic.com>
This commit is contained in:
Shang Chieh Tseng
2025-12-17 00:42:04 +08:00
parent f25016b7d5
commit 1e99c1bb50
5 changed files with 35 additions and 5 deletions

View File

@@ -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 }}

11
docker/.env.example Normal file
View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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