Use ollama CLI instead of curl in sync script

The ollama/ollama container image doesn't include curl. Use `ollama list`
and `ollama pull` commands directly, which are always available.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Erich Blume 2026-03-02 20:20:19 -08:00
commit dd678e7454

View file

@ -1,20 +1,22 @@
#!/bin/bash
# Sync models from ConfigMap to Ollama server
# Runs as a sidecar in the ollama deployment
# Runs as a sidecar in the ollama deployment, using the ollama CLI
set -euo pipefail
MODEL_LIST="${MODEL_LIST:-/config/models.txt}"
OLLAMA_HOST="${OLLAMA_HOST:-http://localhost:11434}"
SYNC_INTERVAL="${SYNC_INTERVAL:-1800}"
echo "Syncing models from ${MODEL_LIST} to ollama at ${OLLAMA_HOST}"
export OLLAMA_HOST
echo "Syncing models from ${MODEL_LIST} via ollama CLI (host: ${OLLAMA_HOST})"
while true; do
# Wait for ollama server to be ready
echo "Waiting for Ollama API..."
max_attempts=60
attempt=0
until curl -sf "${OLLAMA_HOST}/api/tags" > /dev/null 2>&1; do
until ollama list > /dev/null 2>&1; do
attempt=$((attempt + 1))
if [[ $attempt -ge $max_attempts ]]; then
echo "Ollama not ready after ${max_attempts} attempts, will retry next cycle"
@ -26,7 +28,7 @@ while true; do
echo "Ollama is ready"
# Get list of currently pulled models
current=$(curl -sf "${OLLAMA_HOST}/api/tags" | grep -o '"name":"[^"]*"' | cut -d'"' -f4 || true)
current=$(ollama list 2>/dev/null | tail -n +2 | awk '{print $1}' || true)
pulled=0
skipped=0
@ -38,13 +40,13 @@ while true; do
model=$(echo "$model" | xargs)
[[ -z "$model" ]] && continue
# Check if model is already pulled
# Check if model is already pulled (ollama list shows name:tag)
if echo "$current" | grep -qF "$model"; then
echo "Already present: $model"
((skipped++)) || true
else
echo "Pulling: $model"
if curl -sf "${OLLAMA_HOST}/api/pull" -d "{\"name\":\"$model\"}" > /dev/null; then
if ollama pull "$model"; then
echo "Pulled: $model"
((pulled++)) || true
else