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

Snap packaging #724

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ if [ "$USE_CUDA_DOCKER" = "true" ]; then
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/python3.11/site-packages/torch/lib:/usr/local/lib/python3.11/site-packages/nvidia/cudnn/lib"
fi

WEBUI_SECRET_KEY="$WEBUI_SECRET_KEY" exec uvicorn main:app --host 0.0.0.0 --port "$PORT" --forwarded-allow-ips '*'
WEBUI_SECRET_KEY="$WEBUI_SECRET_KEY" exec uvicorn main:app --host "$HOST" --port "$PORT" --forwarded-allow-ips '*'
4 changes: 4 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

snapctl stop "$SNAP_INSTANCE_NAME"
snapctl start "$SNAP_INSTANCE_NAME"
14 changes: 14 additions & 0 deletions snap/hooks/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -e

snapctl set host="0.0.0.0"
snapctl set port="8080"
snapctl set secret-key=$(head -c 12 /dev/random | base64)

snapctl set ollama-api-base-url="http://localhost:11434/api"
snapctl set openai-api-base-url="https://api.openai.com/v1"
snapctl set openai-api-key=""

snapctl set enable-signup="true"
snapctl set data-dir="$SNAP_COMMON/data"

2 changes: 2 additions & 0 deletions snap/hooks/post-refresh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
mkdir -p $SNAP_COMMON/data
30 changes: 30 additions & 0 deletions snap/local/info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

HOST=$(snapctl get host)
PORT=$(snapctl get port)

SERVICE_INFO=$(snapctl services $SNAP_INSTANCE_NAME.listener)

STATUS=$(echo "$SERVICE_INFO" | awk '/open-webui.listener/{print $3}')

echo "$SNAP_INSTANCE_NAME.listener: $STATUS"

if [ "$STATUS" == "active" ]; then
echo ''
echo "To use $SNAP_INSTANCE_NAME, open the following URL in your browser: http://$HOST:$PORT"
else
echo ''
echo "If you expected the service to be up, check that the port $PORT is available, not bound by some other service."
fi

echo ''
echo 'For documentation, see https://docs.openwebui.com'
echo ''
echo "You can use a local AI model with $SNAP_INSTANCE_NAME with ollama (http://ollama.com)."
echo ' - You can install ollama with `sudo snap install ollama --channel=beta`'
echo ' - ollama is by default expected to be serving at 'http://localhost:11434/api'. To customize that, do `sudo snap set open-webui ollama-api-base-url=...`'
echo ' - for all available configuration parameters, see `sudo snap get open-webui`'
echo ''
echo "You can access any OpenAI compatible API endpoint with $SNAP_INSTANCE_NAME."
echo ' - To configure the OpenAI endpoint (by default expected to be "https://api.openai.com/v1"), do `sudo snap set open-webui openai-api-base-url=...`'
echo ' - To configure the OpenAI API key (by default an empty string), do `sudo snap set open-webui openai-api-key=...`'
18 changes: 18 additions & 0 deletions snap/local/run-snap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e

STATIC_DIR=$SNAP_DATA/static
mkdir -p $STATIC_DIR

DATA_DIR=$(snapctl get data-dir) \
STATIC_DIR=$STATIC_DIR \
FRONTEND_BUILD_DIR=$SNAP/build \
HOST=$(snapctl get host) \
PORT=$(snapctl get port) \
WEBUI_SECRET_KEY=$(snapctl get secret-key) \
OLLAMA_API_BASE_URL=$(snapctl get ollama-api-base-url) \
OPENAI_API_BASE_URL=$(snapctl get openai-api-base-url) \
OPENAI_API_KEY=$(snapctl get openai-api-key) \
ENABLE_SIGNUP=$(snapctl get enable-signup) \
$SNAP/backend/start.sh $@
105 changes: 105 additions & 0 deletions snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
name: open-webui
base: core22
version: "0" # no released version yet
summary: ChatGPT-Style Web UI Client for Ollama 🦙 (formerly Ollama WebUI)
description: |
The Open WebUI consists of two primary components:
the frontend and the backend (which serves as a reverse proxy,
handling static frontend files, and additional features).
Both are set up.
adopt-info: backend
grade: stable
confinement: strict
license: MIT
architectures:
- build-on: [amd64]
build-for: [amd64]
- build-on: [arm64]
build-for: [arm64]

apps:
open-webui:
command: bin/info.sh
listener:
command: bin/run-snap.sh
daemon: simple
install-mode: enable
restart-condition: on-failure
plugs:
- home
- removable-media
- network
- network-bind
- opengl
environment:
ENV: prod
SCARF_NO_ANALYTICS: "true"
DO_NOT_TRACK: "true"
parts:
launcher:
plugin: dump
source: ./snap/local
organize:
info.sh: bin/info.sh
run-snap.sh: bin/run-snap.sh
minilm:
plugin: dump
source: https://chroma-onnx-models.s3.amazonaws.com/all-MiniLM-L6-v2/onnx.tar.gz
organize:
onnx: root/.cache/chroma/onnx_models/all-MiniLM-L6-v2/onnx
frontend:
after: [launcher, minilm]
plugin: nil
source: .
source-type: git
override-build: |
craftctl default
npm ci
npm run build
cp -r build $CRAFT_PART_INSTALL/build
stage-snaps:
- node/20/stable
backend:
after: [frontend]
plugin: python
source: .
source-type: git
build-packages:
- netcat-openbsd
- python3.11
- python3.11-venv
- python3.11-dev
- python3-pip
- git
- execstack
stage-packages:
- python3.11
- python3.11-venv
- pandoc
- libavcodec58
- libavformat58
- libavdevice58
- libavfilter7
python-requirements:
- backend/requirements.txt
override-pull: |
craftctl default
last_committed_tag="$(git describe --tags --abbrev=0)"
last_committed_tag_ver="$(echo ${last_committed_tag} | sed 's/v//')"
craftctl set version="$(git describe --tags | sed 's/v//')"
override-build: |
craftctl default
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu --no-cache-dir
cp -r backend $CRAFT_PART_INSTALL
override-prime: |
craftctl default

# libctranslate2.so... is caught with an executable stack (something to investigate)
# for now forcibly cleared below.
#
# see https://forum.snapcraft.io/t/snap-and-executable-stacks/1812 for more info on the check
for f in `find $CRAFT_PRIME | grep -e libctranslate2.*\.so\..*`; do
strip --strip-all $f;
execstack --clear-execstack $f;
done