summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 5d40d3460372f10bc4ef944cd6935dbe73ab7963 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Maintainer: Aseem Athale <athaleaseem@gmail.com>

_pkgname=open-webui
pkgname=${_pkgname}-no-venv
pkgver=0.5.4
pkgrel=2
pkgdesc="Web UI and OpenAI API for various LLM runners, including Ollama, built without creating virtualenv"
arch=('any')
url="https://github.com/open-webui/open-webui"
license=('MIT')
depends=(python
        python-aiocache
        python-aiofiles
        python-aiohttp
        python-alembic
        python-authlib
        python-beautifulsoup4
        python-black
        python-boto3
        python-botocore
        python-chromadb
        python-colbert-ai
        python-datasets
        python-dotenv
        python-duckduckgo-search
        python-fastapi
        python-faster-whisper
        python-fpdf2
        python-ftfy
        python-huggingface-hub
        python-pyjwt
        python-langchain
        python-langchain-community
        python-langchain-core
        python-ldap3
        python-markdown
        python-numpy
        python-opensearch
        python-passlib
        python-peewee
        python-peewee-migrate
        python-pgvector
        python-pydantic
        python-pydub
        python-pymilvus
        python-python-multipart
        python-qdrant-client
        python-redis
        python-requests
        python-sentence-transformers
        python-socketio
        python-soundfile
        python-sqlalchemy
        python-starlette
        python-tiktoken
        python-pytorch
        python-transformers
        python-typer
        python-typing_extensions
        uvicorn
        python-validators
        python-websocket-client
        python-yaml
        python-yarl
        python-youtube-transcript-api
# Transitive dependencies that are needed but not added yet in direct dependencies PKGBUILDs
        python-lxml
        )
checkdepends=('python-pytest' 'python-docker' 'python-pytest-docker')
makedepends=('npm' 'nvm' 'python-setuptools' 'python-build' 'python-installer' 'python-wheel' 'python-hatch' 'python-ctranslate2-bin' 'python-jaxlib-bin' 'python-tensorstore-bin' 'python-primp-bin')
optdepends=('ollama' 'tika-server')
conflicts=('open-webui-git' 'open-webui')
source=("${pkgname}-${pkgver}.tar.gz"::"${url}/archive/refs/tags/v${pkgver}.tar.gz"
        "build-only-backend.patch"
        "open-webui.service"
        "open-webui.conf")
sha1sums=('4260ae1d411ea547fa280eb80df6b4b18badc981'
          '3dc37cbf6a962fe16c3f5f740b7100e9ae87fd8e'
          '8a1fad8ffad186f3265e173557eb160c06497435'
          'fc563a2f3e240d76672b09c4627d654248d70186')
options=(!strip !debug)
install="$_pkgname.install"

_ensure_local_nvm() {
    # let's be sure we are starting clean
    which nvm >/dev/null 2>&1 && nvm deactivate && nvm unload
    export NVM_DIR="${srcdir}/.nvm"

    # The init script returns 3 if version specified
    # in ./.nvrc is not (yet) installed in $NVM_DIR
    # but nvm itself still gets loaded ok
    source /usr/share/nvm/init-nvm.sh || [[ $? != 1 ]]
}

prepare() {
    # Frontend part
    _ensure_local_nvm
    nvm install lts/iron

    # Backend part
    cd "${_pkgname}-${pkgver}"
    patch -i ../build-only-backend.patch
}

build() {
    _ensure_local_nvm
    cd "${_pkgname}-${pkgver}"

    # Backend part
    python -m build --wheel --no-isolation

    # Frontend part
    export NODE_OPTIONS="--max_old_space_size=4096"
    npm install
    npm run format
    npm run i18n:parse
    npm run build
}

check() {
    _ensure_local_nvm
    cd "${_pkgname}-${pkgver}"

    # Frontend part
    export NODE_OPTIONS="--max_old_space_size=4096"
    npm run test:frontend

    # Backend part
    python -m installer -d tmp_install dist/*.whl
    local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
    local python_version=$(python -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
    PYTHONPATH="$PWD/tmp_install/usr/lib/python${python_version}/site-packages" python -m pytest -o addopts="" || warning "Tests failed"
}

package() {
    # Install systemd service
    install -Dm644 "./$_pkgname.service" "$pkgdir/usr/lib/systemd/system/$_pkgname.service"

    # Install license
    install -Dm 644 "$srcdir/${_pkgname}-${pkgver}"/LICENSE -t "${pkgdir}/usr/share/licenses/${_pkgname}"

    # Install the default config file to /usr/share/$_pkgname/open-webui.conf
    install -d "$pkgdir/usr/share/$_pkgname"
    install -Dm644 "./$_pkgname.conf" "$pkgdir/usr/share/$_pkgname/$_pkgname.conf"

    # Copy source to app's home directory
    parent_dir="$pkgdir/opt"  # /opt

    install -d "$pkgdir/opt/$_pkgname"
    install -d "$pkgdir/var/opt/$_pkgname"
    install -d "$pkgdir/var/opt/$_pkgname/data"

    # copy over files
    cp -R "$srcdir/${_pkgname}-${pkgver}/build/." "$pkgdir/opt/$_pkgname"

    # Fix permissions
    echo "Setting permissions for $pkgdiropt/$_pkgname"
    chmod 755 "$pkgdir/opt/$_pkgname"
    find "$pkgdir/opt/$_pkgname" -type d -exec chmod 755 {} \;
    find "$pkgdir/opt/$_pkgname" -type f -exec chmod 644 {} \;

    echo "Setting permissions for $pkgdirvar/opt/$_pkgname"
    chmod 700 "$pkgdir/var/opt/$_pkgname"
    find "$pkgdir/var/opt/$_pkgname" -type d -exec chmod 755 {} \;
    find "$pkgdir/var/opt/$_pkgname" -type f -exec chmod 664 {} \;

    cd "${_pkgname}-${pkgver}"
    python -m installer --destdir="$pkgdir" dist/*.whl
    rm -r "$pkgdir/usr/lib/python3.13/site-packages/data"
}