[Bug]: (Docker) Missing /opt/venv/bin in PATH and OpenCV Unavailability in Virtual Environment
Installation Method
Docker
The Problem
When running Stirling-PDF v0.44.0 in a Docker container built from the provided Dockerfile, two issues occur:
- The application logs warnings about missing weasyprint and unoconvert dependencies, disabling features like "Markdown to PDF" and "File to PDF":
WARN s.s.SPDF.config.ExternalAppDepConfig - Missing dependency: weasyprint - Disabling group: Weasyprint
WARN s.s.SPDF.config.ExternalAppDepConfig - Missing dependency: unoconvert - Disabling group: Unoconvert
- OpenCV is reported as unavailable, disabling the "Extract Image Scans" feature:
WARN s.s.SPDF.config.ExternalAppDepConfig - OpenCV not available in Python - Disabling OpenCV features: Extract Image Scans
I was trying to run the container and use these features, but they were disabled due to these dependency issues.
Version of Stirling-PDF
v0.44.0
Last Working Version of Stirling-PDF
No response
Page Where the Problem Occurred
No response
Docker Configuration
Relevant Log Output
WARN s.s.SPDF.config.ExternalAppDepConfig - Missing dependency: weasyprint - Disabling group: Weasyprint
WARN s.s.SPDF.config.ExternalAppDepConfig - Missing dependency: unoconvert - Disabling group: Unoconvert
WARN s.s.SPDF.config.ExternalAppDepConfig - OpenCV not available in Python - Disabling OpenCV features: Extract Image Scans
Additional Information
My Proposed Solution
- Fix missing
weasyprintandunoconvert: Add/opt/venv/binto the $PATH
ENV
...
+ PATH=/opt/venv/bin:$PATH
Remove the export command
RUN
...
- export PATH="/opt/venv/bin:$PATH" && \
- Fix openCV issue:
I just added the
--system-site-packagesflag
- python3 -m venv /opt/venv && \
+ python3 -m venv /opt/venv --system-site-packages && \
With those changes all of the warnings in the logs were removed.
These really only apply to the Dockerfile, and Dockerfile.fat. The other two Docker files are too different, I did not test those personally.
Browsers Affected
No response
No Duplicate of the Issue
- [x] I have verified that there are no existing issues raised related to my problem.
Which image is this? Lite or latest etc?
Also are you running docker in any certain way Is your /.dockerenv file visable?
It's interesting these show for you, your builds did not see the issue Although the changes are still valid
Which image is this? Lite or latest etc?
I first saw the issue in my Kubernetes Helm deployment using:
repository: ghcr.io/stirling-tools/s-pdf
tag: 0.44.0@sha256:d315d6fcc03da60e939d4924335fa7fa8ad6b990bac99a7a17ebfacc37f6a88f
Locally on NixOS, I built from the main Dockerfile (commit b6b49762f6c8116bc70179b2026a4c360b2d9a2a) with:
docker build -t stirling-pdf:0.44.0 --build-arg VERSION_TAG=0.44.0 .
Are you running docker in any certain way? Is your /.dockerenv file visible?
- Kubernetes: Standard Helm deployment (containerd runtime). No /.dockerenv exists:
kubectl exec stirling-pdf-785db986c6-fqjg2 -- ls -l /.dockerenv
# ls: /.dockerenv: No such file or directory
- Local Docker: Ran
docker run -d -p 8080:8080 --name stirling-pdf-container stirling-pdf:0.44.0. /.dockerenv is present:
docker exec stirling-pdf-container ls -l /.dockerenv
# -rwxr-xr-x 1 root root 0 Mar 8 21:57 /.dockerenv
Both showed the same weasyprint, unoconvert, and OpenCV warnings until I fixed them with ENV PATH=/opt/venv/bin:$PATH and python3 -m venv /opt/venv --system-site-packages.
ahh this is a config issue, we have the pathing defaulted to opt/venv if .dockerenv exists else it defaults to PATH In both cases a user can change the path used in settings.yml
regardless the change to add PATH correctly in dockerfile should be done
I agree, since the Dockerfile should be setup in a way that handles the paths, since its what is installing everything needed to run. I can open a PR with those exact changes in my first comment if you wish, or leave it up to your team. Does not matter to me.
I am in no rush, I appreciate your time!
I use Podman to create containers and encounter the same issue. Following the instructions above, I now also resolve it by modifying the customPaths in settings.yml.
Setting
SYSTEM_CUSTOMPATHS_OPERATIONS_WEASYPRINT: "/opt/venv/bin/"
SYSTEM_CUSTOMPATHS_OPERATIONS_UNOCONVERT: "/opt/venv/bin/unoconvert"
Within the Environment also seemed to have solved the issues. Including the OpenCV error. Not sure why it would fix that error as well.
If this is seen as user error then this can be closed. I believe the dockerfile would benefit with adding those two env vars, but happy with the project either way.