unoconv / unoserver

MIT License
496 stars 69 forks source link

Dockerizing Unoserver #47

Closed RafaPolit closed 1 year ago

RafaPolit commented 1 year ago

Much like the scenario described in #17 , I am planning a service that hooks to our platform for document conversion.

Ideally, we provide these services dockerized, in order to minimize the complexity of installation for those users that self-host our platform (which is open source).

Do you have any hints / tips / procedures that could help in the process of dockerizing Unoserver (including Libreoffice in the way Unoserver requires it)?

Thanks for any insight.

regebro commented 1 year ago

I'm not good at docker, so unfortunately I have no tips. But as long as you use the default system installation of Libreoffice Unoserver should find and use it automatically,

lfvjimisola commented 1 year ago

We are dockerizing unoserver (alpine) and stumbled upon the problem below. We're happy to share the container once it's working.

Traceback (most recent call last):
  File "/usr/bin/unoconvert", line 5, in <module>
    from unoserver.converter import main
  File "/usr/lib/python3.10/site-packages/unoserver/converter.py", line 4, in <module>
    raise ImportError(
ImportError: Could not find the 'uno' library. This package must be installed with a Python installation hat has a 'uno' library. This typically means you should installit with the same Python executable as your Libreoffice installation uses.
regebro commented 1 year ago

If you are using the standard Python that comes with the operating system, it should typically find the standard LibreOffice package. If it doesn't do that, there is something unusual in your distributions packaging of Python and/or LibreOffice.

lfvjimisola commented 1 year ago

We are using Alpine 3.16.2 and, as for as I know, itäs all standard. Relevant parts of Dockerfile:

RUN apk add --no-cache \
    bash curl \
    libreoffice \
    ghostscript \
    ffmpeg \
    imagemagick \
    python3 py3-pip 

    # https://github.com/unoconv/unoserver/
    RUN pip install -U unoserver unoconv
lfvjimisola commented 1 year ago

@regebro Any ideas from the above snippet? Perhaps I need to check with the alpine packages but I first want to confirm that I'm not missing out on something.

regebro commented 1 year ago

No, I can only guess that the alpine packages for libreoffice doesn't install uno, or installs it incorrectly.

On Mon, Nov 21, 2022 at 12:46 PM Jimisola Laursen @.***> wrote:

@regebro Any ideas from the above snippet? Perhaps I need to check with the alpine packages but I first want to confirm that I'm not missing out on something.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

lfvjimisola commented 1 year ago

I installed uno using pip but that gives the same error:

bash-5.1$ pip list
Package        Version
-------------- -------
appdirs        1.4.4
contextlib2    21.6.0
more-itertools 8.13.0
ordered-set    4.0.2
packaging      21.3
pep517         0.12.0
pip            22.1.1
py             1.4.22
pyparsing      2.4.7
pytest         2.6.0
retrying       1.3.3
setuptools     59.4.
six            1.16.0
tomli          2.0.1
uno            0.3.3
unoconv        0.9.0
unoserver      1.2
wheel          0.38.4

So, just to confirm. LibreOffice should install a uno library that is compatible with that version of LibreOffice? It is not a solution to install uno separately using e.g. pip install uno?

regebro commented 1 year ago

The uno library on pypi confusingly has nothing to do with LibreOffice, so yeah, that doesn't help.

LibreOffice should install a uno library that is compatible with that version of LibreOffice?

Yes, exactly.

lfvjimisola commented 1 year ago

Below is a list what is available in the alpine container now.

I noticed four (4) files that seems to be relevant. From our discussion above I believe that we are interested in the uno

However, find_uno.py shows:

bash-5.1$ python3 find_uno.py
Trying python found at /usr/bin/python3... Failed
Found 0 Pythons with Libreoffice libraries:

I'm not great with python so I'm suspecting that the correct files are installed (e.g. /usr/lib/libreoffice/program/uno.py) but not available as python libraries. E.g. /usr/lib/libreoffice/program/pythonloader.py imports uno and unohelper.

Any ideas?

PS. I've checked on my local Ubuntu 22.04 LTS and it works out of the box. DS.

bash-5.1$ du -a /usr|grep uno|cut -f2
/usr/share/man/man1/unopkg.1.gz
/usr/share/man/man3/isunordered.3.gz
/usr/share/man/man2/seccomp_unotify.2.gz
/usr/share/mime/application/x-font-sunos-news.xml
/usr/bin/unoserver
/usr/bin/unoconvert
/usr/bin/unopkg
/usr/lib/python3.10/site-packages/unoserver/__pycache__/converter.cpython-310.pyc
/usr/lib/python3.10/site-packages/unoserver/__pycache__/__init__.cpython-310.pyc
/usr/lib/python3.10/site-packages/unoserver/__pycache__/server.cpython-310.pyc
/usr/lib/python3.10/site-packages/unoserver/__pycache__
/usr/lib/python3.10/site-packages/unoserver/__init__.py
/usr/lib/python3.10/site-packages/unoserver/server.py
/usr/lib/python3.10/site-packages/unoserver/converter.py
/usr/lib/python3.10/site-packages/unoserver
/usr/lib/python3.10/site-packages/unoserver-1.2.dist-info/LICENSE
/usr/lib/python3.10/site-packages/unoserver-1.2.dist-info/RECORD
/usr/lib/python3.10/site-packages/unoserver-1.2.dist-info/top_level.txt
/usr/lib/python3.10/site-packages/unoserver-1.2.dist-info/WHEEL
/usr/lib/python3.10/site-packages/unoserver-1.2.dist-info/INSTALLER
/usr/lib/python3.10/site-packages/unoserver-1.2.dist-info/REQUESTED
/usr/lib/python3.10/site-packages/unoserver-1.2.dist-info/entry_points.txt
/usr/lib/python3.10/site-packages/unoserver-1.2.dist-info/METADATA
/usr/lib/python3.10/site-packages/unoserver-1.2.dist-info
/usr/lib/libreoffice/share/registry/pyuno.xcd
/usr/lib/libreoffice/program/uno.py
/usr/lib/libreoffice/program/liblog_uno_uno.so
/usr/lib/libreoffice/program/libjava_uno.so
/usr/lib/libreoffice/program/pyuno.so
/usr/lib/libreoffice/program/libunopkgapp.so
/usr/lib/libreoffice/program/services/pyuno.rdb
/usr/lib/libreoffice/program/libuno_cppuhelpergcc3.so.3
/usr/lib/libreoffice/program/unorc
/usr/lib/libreoffice/program/libuno_salhelpergcc3.so.3
/usr/lib/libreoffice/program/libuno_purpenvhelpergcc3.so.3
/usr/lib/libreoffice/program/libunordflo.so
/usr/lib/libreoffice/program/libgcc3_uno.so
/usr/lib/libreoffice/program/classes/java_uno.jar
/usr/lib/libreoffice/program/classes/unoil.jar
/usr/lib/libreoffice/program/classes/unoloader.jar
/usr/lib/libreoffice/program/uno.bin
/usr/lib/libreoffice/program/unopkg
/usr/lib/libreoffice/program/libaffine_uno_uno.so
/usr/lib/libreoffice/program/libuno_cppu.so.3
/usr/lib/libreoffice/program/libuno_sal.so.3
/usr/lib/libreoffice/program/unoinfo
/usr/lib/libreoffice/program/unohelper.py
/usr/lib/libreoffice/program/libunoxmllo.so
/usr/lib/libreoffice/program/libpyuno.so
/usr/lib/libreoffice/program/unopkg.bin
/usr/lib/libreoffice/program/pythonloader.unorc
/usr/lib/libreoffice/program/libunoidllo.so
/usr/lib/libreoffice/program/libunsafe_uno_uno.so
/usr/lib/libreoffice/program/lounorc
/usr/lib/libreoffice/program/uno
lfvjimisola commented 1 year ago

Seems to be known and reported: https://gitlab.alpinelinux.org/alpine/aports/-/issues/13359

lfvjimisola commented 1 year ago

Got it to work now w/ the fix mentioned here

RUN apk add --no-cache libreoffice py3-pip 

# install Eclipse Temurin JDK
RUN curl https://packages.adoptium.net/artifactory/api/security/keypair/public/repositories/apk -o /etc/apk/keys/adoptium.rsa.pub && \
    echo 'https://packages.adoptium.net/artifactory/apk/alpine/main' >> /etc/apk/repositories && \
    apk update && apk add temurin-17-jdk

# https://github.com/unoconv/unoserver/
RUN pip install -U unoserver

# define path
ENV PATH_LO=/usr/lib/libreoffice/program
ENV PATH_SP=/usr/lib/python3.10/site-packages

RUN \
    # copy unohelper.py
    cp "$PATH_LO"/unohelper.py "$PATH_SP"/  && \

    # prefix path to uno.py
    echo -e "\
import sys, os \n\
sys.path.append('/usr/lib/libreoffice/program') \n\
os.putenv('URE_BOOTSTRAP', 'vnd.sun.star.pathname:/usr/lib/libreoffice/program/fundamentalrc')\
" > "$PATH_SP"/uno.py  && \

    # copy the original's content
    cat "$PATH_LO"/uno.py >> "$PATH_SP"/uno.py
regebro commented 1 year ago

Great! Yes, indeed, either Libreoffice should use it's own Python installation, or add the uno library to the OS Python libraries. Seems it did neither of those.

lfvjimisola commented 1 year ago

So, since unoserver is service I've used supervisor to handle it. In addition, I needed to add an entrypoint that waits for unoserver to start listen on default port 2002.

Need to make sure that the container works as rootless, adjust logging etc. My intention is to provide a PR for container build after that if it is of interest.

regebro commented 1 year ago

It could be useful, but since I can't maintain it, and since it's not a part of the Python package per se, perhaps it could be in another repository? I could make a unoserver-contribs, or something?

lfvjimisola commented 1 year ago

@regebro Hej! (misstänker att du är svensk)

Another repo sounds good. contribs is quite generic. I think that this contrib could use it's own repo such as docker-unoserver, unoserver-docker or similar.

I'll PR from my private github account @jimisola

lfvjimisola commented 1 year ago

@regebro The Dockerfile is ready when you are.

lfvjimisola commented 1 year ago

@regebro Are you still interested?

regebro commented 1 year ago

Ja, tack!

I finally created the repo: https://github.com/unoconv/unoserver-docker/

I added both of your accounts as maintainer, if you only want one of them to have access, I can remove one.

jimisola commented 1 year ago

These is a docker image available as PR now for those of you that want to test it: https://github.com/unoconv/unoserver-docker/pull/3

jimisola commented 1 year ago

@regebro I thought have permissions to close this issue. But, I think we can close this issue now as the Dockerfile is available (although publishing to GitHub Packages is wip): https://github.com/unoconv/unoserver-docker

jimisola commented 1 year ago

For those ending up here, version 0.1.0-rc1 has been released and is available on GitHub Packages (similar to Docker Hub).