Refactor: Paperless-AI (#9588)

Co-authored-by: Tobias <96661824+CrazyWolf13@users.noreply.github.com>
This commit is contained in:
CanbiZ 2025-12-02 14:55:02 +01:00 committed by GitHub
parent 7978c3176c
commit 433aafe365
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 51 deletions

View File

@ -27,58 +27,33 @@ function update_script() {
msg_error "No ${APP} Installation Found!" msg_error "No ${APP} Installation Found!"
exit exit
fi fi
if ! dpkg -s python3-pip >/dev/null 2>&1; then
$STD apt install -y python3-pip if check_for_gh_release "paperless-ai" "clusterzx/paperless-ai"; then
fi
RELEASE=$(curl -fsSL https://api.github.com/repos/clusterzx/paperless-ai/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
msg_info "Stopping Service" msg_info "Stopping Service"
systemctl stop paperless-ai systemctl stop paperless-ai paperless-rag
msg_info "Stopped Service" msg_ok "Stopped Service"
msg_info "Updating $APP to v${RELEASE}" fetch_and_deploy_gh_release "paperless-ai" "clusterzx/paperless-ai"
cd /opt
mv /opt/paperless-ai /opt/paperless-ai_bak msg_info "Updating Paperless-AI"
curl -fsSL "https://github.com/clusterzx/paperless-ai/archive/refs/tags/v${RELEASE}.zip" -o $(basename "https://github.com/clusterzx/paperless-ai/archive/refs/tags/v${RELEASE}.zip")
$STD unzip v${RELEASE}.zip
mv paperless-ai-${RELEASE} /opt/paperless-ai
mkdir -p /opt/paperless-ai/data
cp -a /opt/paperless-ai_bak/data/. /opt/paperless-ai/data/
cd /opt/paperless-ai cd /opt/paperless-ai
if [[ ! -f /etc/systemd/system/paperless-rag.service ]]; then source /opt/paperless-ai/venv/bin/activate
cat <<EOF >/etc/systemd/system/paperless-rag.service $STD pip install --upgrade pip
[Unit]
Description=PaperlessAI-RAG Service
After=network.target
[Service]
WorkingDirectory=/opt/paperless-ai
ExecStart=/usr/bin/python3 main.py --host 0.0.0.0 --port 8000 --initialize
Restart=always
[Install]
WantedBy=multi-user.target
EOF
echo "RAG_SERVICE_URL=http://localhost:8000" >>/opt/paperless-ai/data/.env
echo "RAG_SERVICE_ENABLED=true" >>/opt/paperless-ai/data/.env
fi
$STD pip install --no-cache-dir -r requirements.txt $STD pip install --no-cache-dir -r requirements.txt
mkdir -p data/chromadb mkdir -p data/chromadb
$STD npm install $STD npm ci --only=production
rm -rf /opt/v${RELEASE}.zip msg_ok "Updated Paperless-AI"
rm -rf /opt/paperless-ai_bak
echo "${RELEASE}" >/opt/${APP}_version.txt
msg_ok "Updated $APP to v${RELEASE}"
msg_info "Starting Service" msg_info "Starting Service"
systemctl start paperless-rag
sleep 3
systemctl start paperless-ai systemctl start paperless-ai
msg_ok "Started Service" msg_ok "Started Service"
msg_ok "Updated successfully!" msg_ok "Updated successfully!"
else
msg_ok "No update required. ${APP} is already at v${RELEASE}"
fi fi
exit exit
} }
start start
build_container build_container
description description

View File

@ -20,21 +20,27 @@ msg_ok "Installed Dependencies"
msg_info "Installing Python3" msg_info "Installing Python3"
$STD apt install -y \ $STD apt install -y \
python3-pip python3-pip \
python3-dev \
python3-venv
mkdir -p ~/.config/pip
cat >~/.config/pip/pip.conf <<EOF
[global]
break-system-packages = true
EOF
msg_ok "Installed Python3" msg_ok "Installed Python3"
setup_nodejs NODE_VERSION="22" setup_nodejs
fetch_and_deploy_gh_release "paperless-ai" "clusterzx/paperless-ai"
msg_info "Setup Paperless-AI" msg_info "Setup Paperless-AI"
cd /opt
RELEASE=$(curl -fsSL https://api.github.com/repos/clusterzx/paperless-ai/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
curl -fsSL "https://github.com/clusterzx/paperless-ai/archive/refs/tags/v${RELEASE}.zip" -o "v${RELEASE}.zip"
$STD unzip v${RELEASE}.zip
mv paperless-ai-${RELEASE} /opt/paperless-ai
cd /opt/paperless-ai cd /opt/paperless-ai
$STD python3 -m venv /opt/paperless-ai/venv
source /opt/paperless-ai/venv/bin/activate
$STD pip install --upgrade pip
$STD pip install --no-cache-dir -r requirements.txt $STD pip install --no-cache-dir -r requirements.txt
mkdir -p data/chromadb mkdir -p data/chromadb
$STD npm install $STD npm ci --only=production
mkdir -p /opt/paperless-ai/data mkdir -p /opt/paperless-ai/data
cat <<EOF >/opt/paperless-ai/data/.env cat <<EOF >/opt/paperless-ai/data/.env
PAPERLESS_API_URL= PAPERLESS_API_URL=
@ -61,8 +67,6 @@ CUSTOM_MODEL=
RAG_SERVICE_URL=http://localhost:8000 RAG_SERVICE_URL=http://localhost:8000
RAG_SERVICE_ENABLED=true RAG_SERVICE_ENABLED=true
EOF EOF
rm -rf v${RELEASE}.zip
echo "${RELEASE}" >"/opt/${APPLICATION}_version.txt"
msg_ok "Setup Paperless-AI" msg_ok "Setup Paperless-AI"
msg_info "Creating Service" msg_info "Creating Service"
@ -74,7 +78,9 @@ Requires=paperless-rag.service
[Service] [Service]
WorkingDirectory=/opt/paperless-ai WorkingDirectory=/opt/paperless-ai
ExecStart=/usr/bin/npm start Environment="NODE_ENV=production"
EnvironmentFile=/opt/paperless-ai/data/.env
ExecStart=/usr/bin/node server.js
Restart=always Restart=always
[Install] [Install]
@ -88,7 +94,8 @@ After=network.target
[Service] [Service]
WorkingDirectory=/opt/paperless-ai WorkingDirectory=/opt/paperless-ai
ExecStart=/usr/bin/python3 main.py --host 0.0.0.0 --port 8000 --initialize EnvironmentFile=/opt/paperless-ai/data/.env
ExecStart=/opt/paperless-ai/venv/bin/python3 main.py --host 0.0.0.0 --port 8000 --initialize
Restart=always Restart=always
[Install] [Install]