From 0889d662c9ad0598bc85689e5ef43428c05e4de2 Mon Sep 17 00:00:00 2001 From: mik-tf Date: Thu, 6 Feb 2025 11:15:53 -0500 Subject: [PATCH] add flist and dockerfile for openwebui --- tfgrid3/openwebui/Dockerfile | 18 +++ tfgrid3/openwebui/README.md | 115 ++++++++++++++++++ tfgrid3/openwebui/scripts/sshd_init.sh | 6 + tfgrid3/openwebui/scripts/start_containers.sh | 22 ++++ tfgrid3/openwebui/zinit/dockerd.yaml | 1 + tfgrid3/openwebui/zinit/ssh-init.yaml | 2 + tfgrid3/openwebui/zinit/sshd.yaml | 3 + tfgrid3/openwebui/zinit/start_containers.yaml | 4 + 8 files changed, 171 insertions(+) create mode 100644 tfgrid3/openwebui/Dockerfile create mode 100644 tfgrid3/openwebui/README.md create mode 100644 tfgrid3/openwebui/scripts/sshd_init.sh create mode 100644 tfgrid3/openwebui/scripts/start_containers.sh create mode 100644 tfgrid3/openwebui/zinit/dockerd.yaml create mode 100644 tfgrid3/openwebui/zinit/ssh-init.yaml create mode 100644 tfgrid3/openwebui/zinit/sshd.yaml create mode 100644 tfgrid3/openwebui/zinit/start_containers.yaml diff --git a/tfgrid3/openwebui/Dockerfile b/tfgrid3/openwebui/Dockerfile new file mode 100644 index 00000000..fe9d0d19 --- /dev/null +++ b/tfgrid3/openwebui/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu:22.04 + +RUN apt update && \ + apt -y install wget openssh-server curl sudo iproute2 + +RUN wget -O /sbin/zinit https://github.com/threefoldtech/zinit/releases/download/v0.2.5/zinit && \ + chmod +x /sbin/zinit + +RUN curl -fsSL https://get.docker.com -o /usr/local/bin/install-docker.sh && \ + chmod +x /usr/local/bin/install-docker.sh + +RUN sh /usr/local/bin/install-docker.sh + +COPY ./scripts/ /scripts/ +COPY ./zinit/ /etc/zinit/ +RUN chmod +x /scripts/*.sh + +ENTRYPOINT ["/sbin/zinit", "init"] \ No newline at end of file diff --git a/tfgrid3/openwebui/README.md b/tfgrid3/openwebui/README.md new file mode 100644 index 00000000..dfd53d83 --- /dev/null +++ b/tfgrid3/openwebui/README.md @@ -0,0 +1,115 @@ +

OpenWebUI Deployment with Ollama Flist

+ +

Table of Contents

+ +- [Introduction](#introduction) +- [Directory Structure](#directory-structure) +- [Create the Docker Image](#create-the-docker-image) +- [Convert the Docker Image to Zero-OS FList](#convert-the-docker-image-to-zero-os-flist) +- [TFGrid Deployment](#tfgrid-deployment) + - [Playground Steps](#playground-steps) +- [Conclusion](#conclusion) + +*** + +## Introduction + +This project provides a self-contained deployment of **OpenWebUI** on the ThreeFold Grid, using a micro VM. The deployment is managed via **zinit** for automatic service management and includes: + +- Docker daemon for container management +- Secure SSH server configuration +- **OpenWebUI** with Ollama integration +- Automatic container updates via Watchtower +- Self-healing services via **zinit** + +The deployment automatically provisions: +- Secure SSH access +- OpenWebUI on port `8080` +- Persistent storage for Docker and WebUI data + +*** + +## Directory Structure + +``` +. +├── Dockerfile +├── README.md +├── scripts +│ ├── start_containers.sh +│ └── sshd_init.sh +└── zinit + ├── dockerd.yaml + ├── start_containers.yaml + ├── sshd.yaml + └── ssh-init.yaml +``` + +- **`scripts/`**: Contains initialization and service scripts +- **`zinit/`**: Contains **zinit** service configurations for managing services +- **`Dockerfile`**: Defines the Docker image with all dependencies and configurations + +*** + +## Create the Docker Image + +To create the Docker image: + +1. Clone this repository: + ```bash + git clone https://github.com/threefoldtech/tf-images + cd ./tf-images/tfgrid3/openwebui + ``` + +2. Build the Docker image: + ```bash + docker build -t /openwebui-tfgrid . + ``` + +3. Push to Docker Hub: + ```bash + docker push /openwebui-tfgrid + ``` + +*** + +## Convert the Docker Image to Zero-OS FList + +1. Use the [TF Hub Docker Converter](https://hub.grid.tf/docker-convert) +2. Enter your Docker image name: + ```text + /openwebui-tfgrid:latest + ``` +3. Convert and get your FList URL (example): + ```text + https://hub.grid.tf//openwebui-tfgrid-latest.flist + ``` + +*** + +## TFGrid Deployment + +### Playground Steps + +1. Go to [ThreeFold Dashboard](https://dashboard.grid.tf) +2. Create a Micro VM: + - **VM Image**: Paste your FList URL + - **Entry Point**: `/sbin/zinit init` (default) + - **Resources**: Minimum 2 vCPU, 4GB RAM, 10GB disk + - **Mount**: Add a mount point at `/mnt/data` +3. Deploy +4. Set a gateway domain with port 8080 to access OpenWebUI + +*** + +## Conclusion + +This FList provides a self-contained deployment of **OpenWebUI** with Ollama on the ThreeFold Grid with: +- Automatic service management via **zinit** +- Docker container management +- Automatic container updates via Watchtower +- SSH access for maintenance +- Persistent storage for data +- Easy deployment via Docker and TF Grid + +Deploy and enjoy a fully functional OpenWebUI setup on the decentralized ThreeFold Grid! \ No newline at end of file diff --git a/tfgrid3/openwebui/scripts/sshd_init.sh b/tfgrid3/openwebui/scripts/sshd_init.sh new file mode 100644 index 00000000..17f51698 --- /dev/null +++ b/tfgrid3/openwebui/scripts/sshd_init.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +mkdir -p ~/.ssh +mkdir -p /var/run/sshd +chmod 600 ~/.ssh +chmod 600 /etc/ssh/* diff --git a/tfgrid3/openwebui/scripts/start_containers.sh b/tfgrid3/openwebui/scripts/start_containers.sh new file mode 100644 index 00000000..e61641c8 --- /dev/null +++ b/tfgrid3/openwebui/scripts/start_containers.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Wait for Docker daemon +while ! docker info >/dev/null 2>&1; do + echo "Waiting for Docker..." + sleep 2 +done + +# Start OpenWebUI container +docker run \ + -d \ + -p 8080:8080 \ + -v ollama:/root/.ollama \ + -v open-webui:/app/backend/data \ + --name open-webui \ + --restart always \ + ghcr.io/open-webui/open-webui:ollama + +# Start WatchTower container +docker run -d --name watchtower \ + --volume /var/run/docker.sock:/var/run/docker.sock \ + containrrr/watchtower -i 300 open-webui \ No newline at end of file diff --git a/tfgrid3/openwebui/zinit/dockerd.yaml b/tfgrid3/openwebui/zinit/dockerd.yaml new file mode 100644 index 00000000..00b74d5f --- /dev/null +++ b/tfgrid3/openwebui/zinit/dockerd.yaml @@ -0,0 +1 @@ +exec: /usr/bin/dockerd --data-root /mnt/data/docker diff --git a/tfgrid3/openwebui/zinit/ssh-init.yaml b/tfgrid3/openwebui/zinit/ssh-init.yaml new file mode 100644 index 00000000..d4807a2e --- /dev/null +++ b/tfgrid3/openwebui/zinit/ssh-init.yaml @@ -0,0 +1,2 @@ +exec: /scripts/sshd_init.sh +oneshot: true \ No newline at end of file diff --git a/tfgrid3/openwebui/zinit/sshd.yaml b/tfgrid3/openwebui/zinit/sshd.yaml new file mode 100644 index 00000000..e785c688 --- /dev/null +++ b/tfgrid3/openwebui/zinit/sshd.yaml @@ -0,0 +1,3 @@ +exec: bash -c "/usr/sbin/sshd -D" +after: + - ssh-init \ No newline at end of file diff --git a/tfgrid3/openwebui/zinit/start_containers.yaml b/tfgrid3/openwebui/zinit/start_containers.yaml new file mode 100644 index 00000000..fb3c4d76 --- /dev/null +++ b/tfgrid3/openwebui/zinit/start_containers.yaml @@ -0,0 +1,4 @@ +exec: /scripts/start_containers.sh +oneshot: true +after: + - dockerd \ No newline at end of file