Skip to content

Commit a24f7e1

Browse files
committed
fix(ollama): self-install upstream binary when no rpm exists
The previous 37-ollama-prep.sh bailed early on every CI build because its 'command -v ollama' check assumed ollama was installed via packages-ai -- but ollama is NOT a Fedora RPM. Visible symptom: the build duration only grew ~36 seconds when 37-ollama-prep.sh re-entered the main pipeline, instead of the multi-minute pull a real qwen2.5-coder:7b download would take. The image shipped with no build-baked models. Fix: when 'command -v ollama' returns nothing, fetch the official upstream tarball from github.com/ollama/ollama/releases/latest, pick the right -amd64 / -arm64 asset by uname -m, extract the ELF, and install it to /usr/bin/ollama (immutable composefs surface, FHS- canonical for system binaries). Try .tgz first, fall back to .tar.zst if upstream changes asset format. All failures fall through to 'skipping bake' rather than failing the build, so a transient network issue doesn't block the rest of the pipeline. PACKAGES.md gets a comment in the packages-ai block documenting why ollama isn't listed there (no Fedora RPM upstream) and pointing at the runtime path (docker.io/ollama/ollama image used by the mios-ollama Quadlet). After this lands, the build duration should grow by the time it takes to pull the configured bake set (MIOS_OLLAMA_BAKE_MODELS, default qwen2.5-coder:7b + nomic-embed-text ~5 GB). The seed lands at /usr/share/ollama/models on the immutable surface, then mios-ollama-firstboot.service hardlink-copies it into /var/lib/ollama/models on first deploy.
1 parent c27442c commit a24f7e1

2 files changed

Lines changed: 52 additions & 5 deletions

File tree

automation/37-ollama-prep.sh

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,49 @@ if [[ -d "${BAKE_DIR}/manifests" ]] && [[ -n "$(ls -A "${BAKE_DIR}/manifests" 2>
4343
exit 0
4444
fi
4545

46-
# ollama is installed as part of packages-ai (see usr/share/mios/PACKAGES.md).
47-
# If it's not on PATH the build context didn't include the AI pack -- skip
48-
# rather than fail so unrelated CI builds still pass.
46+
# ollama is NOT a Fedora RPM -- fetch the official upstream tarball
47+
# from github.com/ollama/ollama/releases when it isn't already on
48+
# PATH. The binary lands in /usr/bin/ollama (immutable composefs
49+
# surface, FHS-canonical for system binaries) and stays there in the
50+
# deployed image so the mios-ollama Quadlet's container can also exec
51+
# it via 'podman exec mios-ollama ollama ...' if needed.
4952
if ! command -v ollama >/dev/null 2>&1; then
50-
log "ollama binary not found -- skipping bake (AI pack missing from this build)"
51-
exit 0
53+
log "ollama binary missing -- fetching upstream tarball"
54+
arch="$(uname -m)"
55+
case "$arch" in
56+
x86_64) ollama_arch="amd64" ;;
57+
aarch64) ollama_arch="arm64" ;;
58+
*) log "Unsupported arch '$arch' for ollama upstream tarball -- skipping bake"; exit 0 ;;
59+
esac
60+
url="https://github.com/ollama/ollama/releases/latest/download/ollama-linux-${ollama_arch}.tgz"
61+
tmp="$(mktemp -d /tmp/ollama-fetch.XXXXXX)"
62+
trap 'rm -rf "$tmp"' EXIT
63+
if ! command -v zstd >/dev/null 2>&1; then
64+
# The .tgz upstream uses gzip, but newer releases ship .tar.zst.
65+
# Pull zstd in case the asset shape changes -- 'dnf install' is
66+
# only invoked when missing so this is a no-op on most builds.
67+
$DNF_BIN "${DNF_SETOPT[@]}" install -y zstd >/dev/null 2>&1 || true
68+
fi
69+
if scurl -fsSL "$url" -o "$tmp/ollama.tgz"; then
70+
# Try .tgz first; fall back to zst extraction if upstream changes.
71+
if tar -xzf "$tmp/ollama.tgz" -C "$tmp" 2>/dev/null \
72+
|| tar --zstd -xf "$tmp/ollama.tgz" -C "$tmp" 2>/dev/null; then
73+
bin="$(find "$tmp" -type f -name 'ollama' -perm -u+x | head -1)"
74+
if [[ -n "$bin" ]] && file "$bin" 2>/dev/null | grep -q ELF; then
75+
install -m 0755 -t /usr/bin/ "$bin"
76+
log "Installed /usr/bin/ollama from upstream tarball"
77+
else
78+
log "Upstream tarball did not contain a usable ollama ELF -- skipping bake"
79+
exit 0
80+
fi
81+
else
82+
log "Failed to extract ollama tarball -- skipping bake"
83+
exit 0
84+
fi
85+
else
86+
log "Failed to download ${url} -- skipping bake"
87+
exit 0
88+
fi
5289
fi
5390

5491
# Bake destination; OLLAMA_MODELS is the canonical override env var

usr/share/mios/PACKAGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,16 @@ Rust-based LLM CLI agents and shell integrations.
722722
aichat
723723
aichat-ng
724724
```
725+
<!--
726+
ollama is NOT a Fedora RPM; it ships as a tarball from
727+
https://github.com/ollama/ollama/releases and is fetched by
728+
automation/37-ollama-prep.sh at build time. The runtime container
729+
also has its own ollama binary baked into the docker.io/ollama/
730+
ollama image used by the mios-ollama Quadlet -- both are
731+
ARM/x86_64-multi-arch and share the same model store at
732+
/usr/share/ollama/models (build-baked) and /var/lib/ollama/models
733+
(runtime, hardlink-seeded by mios-ollama-firstboot.service).
734+
-->
725735

726736
## Internal -- Critical Validation
727737

0 commit comments

Comments
 (0)