Skip to content

Commit

Permalink
feat: Add a ujust action to install ollama quadlet (#1072)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Sturla <[email protected]>
  • Loading branch information
anoldguy and p5 authored Apr 7, 2024
1 parent 804d048 commit bb2bcac
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions just/bluefin-tools.just
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,74 @@ tensorflow:
echo 'Follow the prompts and check the tutorial: https://www.tensorflow.org/tutorials/quickstart/beginner'
podman pull docker.io/tensorflow/tensorflow:latest
podman run -it -p 8888:8888 docker.io/tensorflow/tensorflow:latest-jupyter # Start Jupyter server

# Setup a local Ollama instance in a container. Detect hardware, offer a choice if needed.
ollama:
#!/usr/bin/env bash
echo 'Follow the prompts and check the tutorial: '
echo
GPU_CHOICES=()
# Detect nvidia drivers
if which nvidia-smi > /dev/null 2>&1; then
GPU_CHOICES+=("Nvidia (CUDA)")
fi
# Detect radeon hardware
if lspci | grep ' VGA ' | grep -sq Radeon; then
GPU_CHOICES+=("AMD (ROCm)")
fi
GPU_SELECTION=$(printf '%s\n' "${GPU_CHOICES[@]}" | gum choose --select-if-one --header "Select the type of graphics card you have")
echo "Selected ${GPU_SELECTION}!"
case "$GPU_SELECTION" in
"Nvidia (CUDA)")
IMAGE=latest
CUSTOM_ARGS="AddDevice=nvidia.com/gpu=all"
;;
"AMD (ROCm)")
IMAGE=rocm
read -r -d '' CUSTOM_ARGS <<-'EOF'
AddDevice=/dev/dri
AddDevice=/dev/kfd
EOF
;;
esac
read -r -d '' QUADLET <<-EOF
[Unit]
Description=The Ollama container
After=local-fs.target
[Service]
Restart=always
TimeoutStartSec=60
# Ensure there's a userland podman.sock
ExecStartPre=/bin/systemctl --user enable podman.socket
[Container]
ContainerName=ollama
PublishPort=11434:11434
RemapUsers=keep-id
RunInit=yes
NoNewPrivileges=no
Volume=%h/.ollama:/.ollama
PodmanArgs=--userns=keep-id
PodmanArgs=--group-add=keep-groups
PodmanArgs=--ulimit=host
PodmanArgs=--security-opt=label=disable
PodmanArgs=--cgroupns=host
Image=docker.io/ollama/ollama:${IMAGE}
${CUSTOM_ARGS}
[Install]
RequiredBy=default.target
EOF
if [ ! -f ~/.config/containers/systemd/ollama.container ]; then
mkdir -p ~/.config/containers/systemd
echo "${QUADLET}" > ~/.config/containers/systemd/ollama.container
else
echo "Ollama container already exists, skipping..."
fi
systemctl --user daemon-reload
systemctl --user start ollama.service
echo "Please install the ollama cli via \`brew install ollama\`"

0 comments on commit bb2bcac

Please sign in to comment.