Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ollama sysext #85

Merged
merged 1 commit into from
Sep 3, 2024
Merged

Add Ollama sysext #85

merged 1 commit into from
Sep 3, 2024

Conversation

joonas
Copy link
Contributor

@joonas joonas commented Aug 25, 2024

Add Ollama sysext

This creates a sysext for running Ollama on Flatcar.

How to use

Create a Flatcar instance with configuration that looks roughly something like this:

---
variant: flatcar
version: 1.0.0
passwd:
  users:
    - name: core
      ssh_authorized_keys: 
        - ${ssh_keys}
storage:
  files:
    - path: /opt/extensions/ollama/ollama-0.3.6-x86-64.raw
      contents:
        source: https://github.com/flatcar/sysext-bakery/releases/download/latest/ollama-0.3.6-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.6-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=OLLAMA_MODELS="/var/lib/ollama"
            Environment=HOME="/var/lib/ollama"
            Environment=OLLAMA_RUNNERS_DIR="/var/lib/ollama"
    - name: systemd-sysupdate.timer
      enabled: true
    - name: systemd-sysupdate.service
      dropins:
        - name: ollama.conf
          contents: |
            [Service]
            ExecStartPre=/usr/lib/systemd/systemd-sysupdate -C ollama update
        - name: sysext.conf
          contents: |
            [Service]
            ExecStartPost=systemctl restart systemd-sysext

Testing done

I've deployed a DigitalOcean droplet with the above configuration and verified that the expected version of Ollama was available and could be used to inference (following steps from Ollama vision models blog post):

Flatcar Container Linux by Kinvolk stable 3975.2.0 for DigitalOcean
core@flatcar-demo-01 ~ $ ollama --version
ollama version is 0.3.6
core@flatcar-demo-01 ~ $ sudo systemctl start ollama
core@flatcar-demo-01 ~ $ sudo journalctl  -fu ollama
Aug 25 21:37:43 flatcar-demo-01 systemd[1]: Started ollama.service - Ollama.
Aug 25 21:37:43 flatcar-demo-01 ollama[1658]: Couldn't find '/var/lib/ollama/.ollama/id_ed25519'. Generating new private key.
Aug 25 21:37:43 flatcar-demo-01 ollama[1658]: Your new public key is:
Aug 25 21:37:43 flatcar-demo-01 ollama[1658]: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDzMvDKAScGwUiKb5ydjyOan9f8dAaqZ2uYRZhpPG/eI
Aug 25 21:37:43 flatcar-demo-01 ollama[1658]: 2024/08/25 21:37:43 routes.go:1125: INFO server config env="map[CUDA_VISIBLE_DEVICES: GPU_DEVICE_ORDINAL: HIP_VISIBLE_DEVICES: HSA_OVERRIDE_GFX_VERSION: OLLAMA_DEBUG:false OLLAMA_FLASH_ATTENTION:false OLLAMA_HOST:http://127.0.0.1:11434 OLLAMA_INTEL_GPU:false OLLAMA_KEEP_ALIVE:5m0s OLLAMA_LLM_LIBRARY: OLLAMA_MAX_LOADED_MODELS:0 OLLAMA_MAX_QUEUE:512 OLLAMA_MODELS:/var/lib/ollama OLLAMA_NOHISTORY:false OLLAMA_NOPRUNE:false OLLAMA_NUM_PARALLEL:0 OLLAMA_ORIGINS:[http://localhost https://localhost http://localhost:* https://localhost:* http://127.0.0.1 https://127.0.0.1 http://127.0.0.1:* https://127.0.0.1:* http://0.0.0.0 https://0.0.0.0 http://0.0.0.0:* https://0.0.0.0:* app://* file://* tauri://*] OLLAMA_RUNNERS_DIR:/var/lib/ollama OLLAMA_SCHED_SPREAD:false OLLAMA_TMPDIR: ROCR_VISIBLE_DEVICES:]"
Aug 25 21:37:43 flatcar-demo-01 ollama[1658]: time=2024-08-25T21:37:43.828Z level=INFO source=images.go:782 msg="total blobs: 0"
Aug 25 21:37:43 flatcar-demo-01 ollama[1658]: time=2024-08-25T21:37:43.829Z level=INFO source=images.go:790 msg="total unused blobs removed: 0"
Aug 25 21:37:43 flatcar-demo-01 ollama[1658]: time=2024-08-25T21:37:43.829Z level=INFO source=routes.go:1172 msg="Listening on 127.0.0.1:11434 (version 0.3.6)"
Aug 25 21:37:43 flatcar-demo-01 ollama[1658]: time=2024-08-25T21:37:43.831Z level=INFO source=payload.go:30 msg="extracting embedded files" dir=/var/lib/ollama
core@flatcar-demo-01 ~ $ ollama pull llava
pulling manifest 
pulling 170370233dd5... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 4.1 GB                         
pulling 72d6f08a42f6... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ 624 MB                         
pulling 43070e2d4e53... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏  11 KB                         
pulling c43332387573... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏   67 B                         
pulling ed11eda7790d... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏   30 B                         
pulling 7c658f9561e5... 100% ▕█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏  564 B                         
verifying sha256 digest 
writing manifest 
removing any unused layers 
success 
core@flatcar-demo-01 ~ $ cd /tmp
core@flatcar-demo-01 /tmp $ curl -O https://ollama.com/public/blog/jmb.jpg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  281k  100  281k    0     0  10.1M      0 --:--:-- --:--:-- --:--:-- 10.5M
core@flatcar-demo-01 /tmp $ ollama run llava "describe this image: ./jmb.jpg"
Added image './jmb.jpg'
 The image shows a colorful graffiti-style artwork on what appears to be the side of a building. The central figure is a stylized, fantastical creature with a dragon-like 
appearance, adorned with a crown and holding a scepter in its right hand. Below this creature is a text that reads "Jean Michel Basquiat / AYON," with the word "AYON" 
underlined. The style of the artwork is reminiscent of street art or pop culture aesthetics, characterized by bold outlines and vibrant colors. The building surface has other 
graffiti and images in various styles, contributing to an urban, artistic atmosphere. The background is blue with a hint of orange near the bottom edge of the image. 
  • Changelog entries added in the respective changelog/ directory (user-facing change, bug fix, security fix, update)
  • Inspected CI output for image differences: /boot and /usr size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.

@jepio
Copy link
Member

jepio commented Aug 30, 2024

Awesome idea!

Copy link
Member

@jepio jepio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally support the idea, just want to hear the answer to the two comments

README.md Outdated Show resolved Hide resolved
create_ollama_sysext.sh Show resolved Hide resolved
@joonas
Copy link
Contributor Author

joonas commented Sep 2, 2024

I've reworked this a bit to include the environment variables by default and using the tarball-based distribution instead of just downloading the binary as before.

create_ollama_sysext.sh Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@joonas joonas force-pushed the add-ollama branch 2 times, most recently from 7f81383 to d59f881 Compare September 3, 2024 13:17
Copy link
Contributor

@tormath1 tormath1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks! Note that ollama.service won't start automatically when the sysext will be loaded. If it's not an issue, we can go ahead. :)

README.md Outdated Show resolved Hide resolved
@joonas
Copy link
Contributor Author

joonas commented Sep 3, 2024

LGTM. Thanks! Note that ollama.service won't start automatically when the sysext will be loaded. If it's not an issue, we can go ahead. :)

hmm, that seems like it probably should happen on boot, I'll take a look at changing that

@tormath1
Copy link
Contributor

tormath1 commented Sep 3, 2024

LGTM. Thanks! Note that ollama.service won't start automatically when the sysext will be loaded. If it's not an issue, we can go ahead. :)

hmm, that seems like it probably should happen on boot, I'll take a look at changing that

When a service has to be started when the sysext is loaded, we usually add a drop-in to multi-user.target:

mkdir -p "${SYSEXTNAME}/usr/lib/systemd/system/multi-user.target.d"
{ echo "[Unit]"; echo "Upholds=wasmcloud.service"; } > "${SYSEXTNAME}/usr/lib/systemd/system/multi-user.target.d/10-wasmcloud-service.conf"
{ echo "[Unit]"; echo "Upholds=nats.service"; } > "${SYSEXTNAME}/usr/lib/systemd/system/multi-user.target.d/10-nats-service.conf"

@joonas
Copy link
Contributor Author

joonas commented Sep 3, 2024

@tormath1 thanks for the pointer, I thought I had originally already included that, but looks like I'd overlooked it.

Should be good to go now 🙂

Copy link
Contributor

@tormath1 tormath1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Feel free to squash everything in a single commit (feat: add ollama sysext)

README.md Outdated Show resolved Hide resolved
Signed-off-by: Joonas Bergius <joonas@cosmonic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants