https://github.com/r0wi-dev/workflow_ocr_backend
Alternative backend for https://github.com/R0Wi-DEV/workflow_ocr
https://github.com/r0wi-dev/workflow_ocr_backend
nextcloud nextcloud-workflow-ocr ocr pdf-files
Last synced: 2 months ago
JSON representation
Alternative backend for https://github.com/R0Wi-DEV/workflow_ocr
- Host: GitHub
- URL: https://github.com/r0wi-dev/workflow_ocr_backend
- Owner: R0Wi-DEV
- License: agpl-3.0
- Created: 2025-01-07T18:32:08.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2025-02-17T20:10:05.000Z (3 months ago)
- Last Synced: 2025-02-17T21:24:42.143Z (3 months ago)
- Topics: nextcloud, nextcloud-workflow-ocr, ocr, pdf-files
- Language: Python
- Homepage:
- Size: 132 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Workflow OCR Backend

This is an alternative backend for the [workflow_ocr](https://github.com/R0Wi-DEV/workflow_ocr) Nextcloud App.
It's written in Python and provides a simple REST API for [ocrmypdf](https://ocrmypdf.readthedocs.io/en/latest/).- [Workflow OCR Backend](#workflow-ocr-backend)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [`docker-compose` Example](#docker-compose-example)## Prerequisites
This app should be installed via Nextcloud [ExApp / AppApi](https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/AppAPIAndExternalApps.html).
It will take care of all the heavy lifting like installation, orchestration, configuration and authentication between Nextcloud and this backend implementation.1. Install [`docker`](https://docs.docker.com/engine/install/ubuntu/) on the host where the app should be installed.
2. Install the [`AppApi`](https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/AppAPIAndExternalApps.html#installing-appapi) app. It will take care of the installation and orchestration of the backend as Docker Container.
3. Setup a [Deploy Daemon](https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/AppAPIAndExternalApps.html#setup-deploy-daemon). It's recommended to use the [Docker Socket Proxy](https://github.com/nextcloud/docker-socket-proxy#readme) to communicate with the docker daemon.## Installation
The easiest way to install this app is to use the [Nexcloud Appstore](https://docs.nextcloud.com/server/latest/admin_manual/exapps_management/AppAPIAndExternalApps.html#installing-exapps).
Alternatively, use the folling [`occ`](https://docs.nextcloud.com/server/latest/admin_manual/occ_command.html) command to register the latest version of this app:
```bash
sudo -u www-data php occ app_api:app:register workflow_ocr_backend \
--info-xml https://raw.githubusercontent.com/R0Wi-DEV/workflow_ocr_backend/refs/heads/master/appinfo/info.xml
```Use `sudo -u www-data php occ app_api --help` to get a full list of AppApi commands.
## `docker-compose` Example
If you want to run both Nextcloud **and** this backend in Docker, you can use the following `docker-compose.yml` to start Nextcloud, a database and the docker-socket-proxy.
**(1)** Create a new docker network first:
```bash
docker network create nextcloud
```**(2)** Then create a `docker-compose.yml` file with the following content:
```yaml
volumes:
nextcloud:
db:networks:
nextcloud:
name: nextcloud
external: trueservices:
db:
image: mariadb:10.6
restart: no
command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
volumes:
- db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=
- MYSQL_PASSWORD=
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MARIADB_ROOT_PASSWORD=nextcloud
networks:
- nextcloudapp:
image: nextcloud:
container_name: nextcloud-in-docker
restart: no
ports:
- 80:80
volumes:
- nextcloud:/var/www/html
environment:
- MYSQL_PASSWORD=
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_HOST=db
- PHP_MEMORY_LIMIT=1024M
- PHP_UPLOAD_LIMIT=1024M
networks:
- nextcloudnextcloud-cron:
image: nextcloud:
container_name: nextcloud-in-docker-cron
restart: no
volumes:
- nextcloud:/var/www/html
entrypoint: /cron.sh
depends_on:
- app
networks:
- nextcloud
environment:
- PHP_MEMORY_LIMIT=1024M
- PHP_UPLOAD_LIMIT=1024M# Proxy for Docker Socket
nextcloud-appapi-dsp:
image: ghcr.io/nextcloud/nextcloud-appapi-dsp:release
container_name: docker-socket-proxy
hostname: nextcloud-appapi-dsp
environment:
- NC_HAPROXY_PASSWORD=password
volumes:
- /var/run/docker.sock:/var/run/docker.sock
restart: no
privileged: true
networks:
- nextcloud
```Adjust the values for `` and `NC_HAPROXY_PASSWORD` to your needs, then start the stack with `docker-compose up -d`.
**(3)** Before configuring the Deploy Daemon, make sure to add the Docker network DNS name (`nextcloud-in-docker`) of the Nextcloud container to the `trusted_domains` in `config/config.php`:
```php
array (
0 => 'localhost',
1 => 'nextcloud-in-docker'
)
)
```Otherwise, ExApps might not be able to connect back to your Nextcloud instance and fail with errors like this:
```bash
# Taken from "docker logs
File "/home/serviceuser/.local/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 2461, in run_sync_in_worker_thread
return await future
^^^^^^^^^^^^
File "/home/serviceuser/.local/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 962, in run
result = context.run(func, *args)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/serviceuser/.local/lib/python3.12/site-packages/nc_py_api/ex_app/integration_fastapi.py", line 138, in fetch_models_task
nc.set_init_status(100)
File "/home/serviceuser/.local/lib/python3.12/site-packages/nc_py_api/nextcloud.py", line 431, in set_init_status
self._session.ocs(
File "/home/serviceuser/.local/lib/python3.12/site-packages/nc_py_api/_session.py", line 213, in ocs
check_error(response, info)
File "/home/serviceuser/.local/lib/python3.12/site-packages/nc_py_api/_exceptions.py", line 65, in check_error
raise NextcloudException(status_code, reason=codes(status_code).phrase, info=info)
nc_py_api._exceptions.NextcloudException: [400] Bad Request```
**(4)** The Deploy Daemon configuration for this setup would look like this:
![]()
> :warning: Make sure to create the docker network `nextcloud` before starting the stack. If you don't declare the network as
> `external`, `docker-compose` will create the network with some [project/directory prefix](https://docs.docker.com/compose/how-tos/networking/), which will cause the Deploy Daemon to fail because it doesn't find the network.