[BUG] WebP support is not installed in Docker production setup (inventree:latest)

This issue has been tracked since 2023-01-27.

Please verify that this bug has NOT been raised before.

  • I checked and didn't find a similar issue

Describe the bug*

I am running a production docker setup right now - freshly installed from inventree:latest. When uploading a WebP image file to a part, I get an Error (loosely translated back to english):

Lade ein gültiges Bild hoch. Die hochgeladene Datei ist entweder kein Bild oder ein beschädigtes Bild.
EN: upload a valid image file. The uploaded file is either not an image or damaged

Steps to Reproduce

  1. open a part view
  2. upload new image file in .webp format

Expected behaviour

As discussed in #2993 the necessary dependencies should already be part of the docker install - has anything changed here? what package should I check for on my system?

Deployment Method

  • Docker
  • Bare metal

Version Information

Version Information:

InvenTree-Version: 0.10.0 dev
Django Version: 3.2.16
Commit Hash: 26f71b3
Commit Date: 2023-01-26
Database: postgresql
Debug-Mode: False
Deployed using Docker: True
Active plugins: [{'name': 'IPNAutoGenerator', 'slug': 'ipnautogenerator', 'version': None}, {'name': 'Brother Labels', 'slug': 'brother', 'version': '0.6.0'}]

Relevant log output

No response

SchrodingersGat wrote this answer on 2023-01-30

@simonkuehling can you provide an example image file that is failing for you?

And, are you uploading the file from your computer, or "downloading" via URL?

simonkuehling wrote this answer on 2023-01-30

@SchrodingersGat I am uploading the file from my computer and tried a variety of different .webp files to be sure.

Just tested against this example image from the Google WebP site as well: https://www.gstatic.com/webp/gallery/1.webp

SchrodingersGat wrote this answer on 2023-01-30

@simonkuehling seems to be working on the demo server:

image

Can you provide any further information?

simonkuehling wrote this answer on 2023-01-30

@SchrodingersGat whatever is needed, sure!

I tried looking at the console via docker attach inventree-server, but could not get any error output more than Bad Request: /api/part/171/ when upoading a local file from my computer.

When loading from a URL I see a slightly more useful message:

/root/.local/lib/python3.9/site-packages/PIL/Image.py:3281: UserWarning: image file could not be identified because WEBP support not installed
  warnings.warn(message)
Bad Request: /api/part/171/

This is what is installed inside the inventree-server docker:

$ docker exec inventree-server pip show Pillow
Name: Pillow
Version: 9.4.0
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Alex Clark (PIL Fork Author)
Author-email: [email protected]
License: HPND
Location: /root/.local/lib/python3.9/site-packages
Requires: 
Required-by: brother-ql-inventree, django-stdimage, pdf2image, weasyprint

Does this help?

SchrodingersGat wrote this answer on 2023-01-30

That's the "correct" version of Pillow. And fundamentally, the demo server is running from the latest production docker image (pulled from dockerhub)

Are you building the image yourself, or pulling it from docker hub inside a compose file?

simonkuehling wrote this answer on 2023-01-30

I installed strictly following the installation instructions form https://docs.inventree.org/en/latest/start/docker_prod/ - so it is running the image from docker hub... The system is a Raspbian GNU/Linux 11 (bullseye) (on a Raspberry Pi 3B+).

Further digging shows:

$ docker exec inventree-server apt list webp
Listing...
webp/stable,now 0.6.1-2.1 armhf [installed]

$ docker exec inventree-server apt list libwebp-dev
Listing...
libwebp-dev/stable 0.6.1-2.1 armhf

I see on some other projects that the libwebp-dev package is mentioned as a dependency for Pillow (rather than webp) - could this be something?

[EDIT]
In the Pillow docs I found libwebp-dev as a requirement as well:
https://pillow.readthedocs.io/en/stable/installation.html
Their reference Dockerfile for Debian 11 includes it as well:
https://github.com/python-pillow/docker-images/blob/main/debian-11-bullseye-x86/Dockerfile

SchrodingersGat wrote this answer on 2023-01-30

I get the same output:

(env) [email protected]:/home/inventree# apt list webp
Listing... Done
webp/stable,now 0.6.1-2.1 amd64 [installed]

The only major difference I can see is that you're running on rasbian?

simonkuehling wrote this answer on 2023-01-30

The only major difference I can see is that you're running on rasbian?

Thats correct
(I just added a note on libwebp-dev requirements in an edit to my last note above as well)

SchrodingersGat wrote this answer on 2023-02-12

@simonkuehling as I cannot replicate and don't have a rasbian setup to replicate on, if you can have a poke around and try to work out why this is failing, that'd be great.

simonkuehling wrote this answer on 2023-02-12

@SchrodingersGat I have been digging a bit and had some success so far:

First, to validate I checked for webp support in the Pillow features inside the inventree-server container:

$ docker exec -it inventree-server /bin/bash
[email protected]:/home/inventree/InvenTree# python
[...]
>>> from PIL import features
>>> print (features.check_module('webp'))
False

Then I installed the libwebp-dev package via apt (still inside the container bash) and reinstalled Pillow

[email protected]:/home/inventree/InvenTree# apt install libwebp-dev
[email protected]:/home/inventree/InvenTree# pip install --upgrade --force-reinstall --no-cache-dir Pillow

Now I get a True for the feature:

[email protected]:/home/inventree/InvenTree# python
[...]
>>> from PIL import features
>>> print (features.check_module('webp'))
True

I do not know how to restart the InvenTree server from within the container right now - I guess the changes I just made won't be persistent when I restart the whole container, right? Can you give me a hint for this?

SchrodingersGat wrote this answer on 2023-02-12

Very interesting...

My suggestion for how to test the server with the correct pillow setup: Stay in the bash session (after you have installed libwebp-dev as above) and then run the following command to start the web server:

gunicorn -c ./gunicorn.conf.py InvenTree.wsgi -b 0.0.0.0:8000 --chdir ./InvenTree
simonkuehling wrote this answer on 2023-02-12

Ok, looks like i need to kill the currently running server first - but I don't have ps to get the PID of it... Is there a command for it?

simonkuehling wrote this answer on 2023-02-12

Got it! Killing the gunicorn master process initiated a server restart. Now WebP Images totally work in InvenTree!

I guess we need libwebp-dev at least for Raspberry Pi OS then...?

SchrodingersGat wrote this answer on 2023-02-12

@simonkuehling looks like it for sure. Can you submit a PR for adding this to the dockerfile? Nice work figuring this out :)

simonkuehling wrote this answer on 2023-02-12

Sure, the pull request is submitted at #4335

More Details About Repo
Owner Name inventree
Repo Name InvenTree
Full Name inventree/InvenTree
Language Python
Created Date 2017-03-23
Updated Date 2023-03-31
Star Count 2586
Watcher Count 61
Fork Count 411
Issue Count 141

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date