Skip to content

Commit

Permalink
Merge pull request #85 from joonas/add-ollama
Browse files Browse the repository at this point in the history
Add Ollama sysext
  • Loading branch information
tormath1 authored Sep 3, 2024
2 parents 3b3827e + f478023 commit d2700fe
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
77 changes: 77 additions & 0 deletions create_ollama_sysext.sh
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 2 additions & 0 deletions release_build_versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ k3s-v1.29.2+k3s1
rke2-v1.29.2+rke2r1

nvidia_runtime-v1.16.1

ollama-0.3.9

0 comments on commit d2700fe

Please sign in to comment.