diff --git a/README.md b/README.md index 073c1c0..93b2091 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ For extensions that are not part of the GitHub Release or which you want to cust | `k3s` | released | | `rke2` | released | | `keepalived` | build script | +| `ollama` | released | ### Consuming the published images @@ -380,6 +381,42 @@ storage: overwrite: true ``` +#### Ollama + +The ollama sysext can be configured by using the following snippet: + +``` +variant: flatcar +version: 1.0.0 +storage: + files: + - path: /opt/extensions/ollama/ollama-0.3.9-x86-64.raw + contents: + source: https://github.com/flatcar/sysext-bakery/releases/download/latest/ollama-0.3.9-x86-64.raw + - path: /etc/sysupdate.ollama.d/ollama.conf + contents: + source: https://github.com/flatcar/sysext-bakery/releases/download/latest/ollama.conf + links: + - target: /opt/extensions/ollama/ollama-0.3.9-x86-64.raw + path: /etc/extensions/ollama.raw + hard: false +systemd: + units: + - name: ollama.service + enabled: true + dropins: + - name: 10-ollama-env-override.conf + contents: | + [Service] + Environment=HOME="/var/lib/ollama" + Environment=OLLAMA_MODELS="/var/lib/ollama/models" + Environment=OLLAMA_RUNNERS_DIR="/var/lib/ollama/runners" +``` + +Note that this configuration can be customized in terms of where Ollama is configured to store its models, configuration and runtime libraries by changing the `HOME`, `OLLAMA_MODELS` and `OLLAMA_RUNNERS_DIR`. + +Please refer to the [Ollama documentation for further details](https://github.com/ollama/ollama/tree/main/docs). + ### Creating a custom Docker sysext image The Docker releases publish static binaries including containerd and the only missing piece are the systemd units. diff --git a/create_ollama_sysext.sh b/create_ollama_sysext.sh new file mode 100755 index 0000000..e68ba26 --- /dev/null +++ b/create_ollama_sysext.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +set -euo pipefail + +export ARCH="${ARCH-x86-64}" +SCRIPTFOLDER="$(dirname "$(readlink -f "$0")")" + +if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + echo "Usage: $0 VERSION SYSEXTNAME" + echo "The script will download ollama release binaries (e.g., for v0.3.9) and create a sysext squashfs image with the name SYSEXTNAME.raw in the current folder." + echo "A temporary directory named SYSEXTNAME in the current folder will be created and deleted again." + echo "All files in the sysext image will be owned by root." + echo "To use arm64 pass 'ARCH=arm64' as environment variable (current value is '${ARCH}')." + "${SCRIPTFOLDER}"/bake.sh --help + exit 1 +fi + +VERSION="$1" +SYSEXTNAME="$2" + +if [ "${ARCH}" = "x86_64" ] || [ "${ARCH}" = "x86-64" ]; then + ARCH="amd64" +elif [ "${ARCH}" = "aarch64" ]; then + ARCH="arm64" +fi + +VERSION="v${VERSION#v}" + +TARBALL="ollama-linux-${ARCH}.tgz" +SHASUM="sha256sum.txt" + +TARBALL_URL="https://github.com/ollama/ollama/releases/download/${VERSION}/${TARBALL}" +SHASUM_URL="https://github.com/ollama/ollama/releases/download/${VERSION}/${SHASUM}" + +rm -rf "${SYSEXTNAME}" + +TMP_DIR="${SYSEXTNAME}/tmp" +mkdir -p "${TMP_DIR}" + +curl --parallel --fail --silent --show-error --location \ + --output "${TMP_DIR}/${TARBALL}" "${TARBALL_URL}" \ + --output "${TMP_DIR}/${SHASUM}" "${SHASUM_URL}" + +pushd "${TMP_DIR}" > /dev/null +grep "${TARBALL}$" "${SHASUM}" | sha256sum -c - +popd > /dev/null + +mkdir -p "${SYSEXTNAME}/usr/local" + +tar --force-local -xf "${TMP_DIR}/${TARBALL}" -C "${SYSEXTNAME}/usr/local" +chmod +x "${SYSEXTNAME}/usr/local/bin/ollama" + +mkdir -p "${SYSEXTNAME}/usr/lib/systemd/system" +cat > "${SYSEXTNAME}/usr/lib/systemd/system/ollama.service" <<-'EOF' +[Unit] +Description=Ollama +Documentation=https://github.com/ollama/ollama/tree/main/docs +Wants=network-online.target +After=network-online.target + +[Service] +Environment="HOME=/var/lib/ollama" +Environment="OLLAMA_MODELS=/var/lib/ollama/models" +Environment="OLLAMA_RUNNERS_DIR=/var/lib/ollama/runners" +ExecStart=/usr/local/bin/ollama serve +Restart=always + +[Install] +WantedBy=multi-user.target +EOF + +mkdir -p "${SYSEXTNAME}"/usr/lib/systemd/system/multi-user.target.d +{ echo "[Unit]"; echo "Upholds=ollama.service"; } > "${SYSEXTNAME}"/usr/lib/systemd/system/multi-user.target.d/10-ollama.conf + +rm -rf "${TMP_DIR}" + +RELOAD=1 "${SCRIPTFOLDER}"/bake.sh "${SYSEXTNAME}" +rm -rf "${SYSEXTNAME}" diff --git a/release_build_versions.txt b/release_build_versions.txt index eb0e801..a105c33 100644 --- a/release_build_versions.txt +++ b/release_build_versions.txt @@ -29,3 +29,5 @@ k3s-v1.29.2+k3s1 rke2-v1.29.2+rke2r1 nvidia_runtime-v1.16.1 + +ollama-0.3.9