|
| 1 | +FROM ubuntu:24.04 |
| 2 | + |
| 3 | +# Install dependencies |
| 4 | +RUN apt-get update && apt-get install -y \ |
| 5 | + curl \ |
| 6 | + git \ |
| 7 | + python3 \ |
| 8 | + python3-pip \ |
| 9 | + python3-venv \ |
| 10 | + sudo \ |
| 11 | + vim \ |
| 12 | + wget \ |
| 13 | + && rm -rf /var/lib/apt/lists/* |
| 14 | + |
| 15 | +# Download and install Google Chrome |
| 16 | +RUN wget -q -O google-chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \ |
| 17 | + && apt-get update \ |
| 18 | + && apt-get install -y ./google-chrome.deb \ |
| 19 | + && rm google-chrome.deb |
| 20 | + |
| 21 | +# Create a new non-root user and group. |
| 22 | +# NOTE: It is important that a non-root user is used because otherwise the |
| 23 | +# Chrome Driver fails with: "User data directory is already in use" |
| 24 | +# https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2688613182 |
| 25 | +RUN groupadd -r html2print && useradd -r -m -g html2print html2print |
| 26 | + |
| 27 | +# Grant the new user sudo privileges. |
| 28 | +RUN echo "html2print ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/html2print |
| 29 | + |
| 30 | +# Create a virtual environment in the user's home directory. |
| 31 | +RUN python3 -m venv /opt/venv |
| 32 | + |
| 33 | +# Ensure the virtual environment is used by modifying the PATH. |
| 34 | +ENV PATH="/opt/venv/bin:$PATH" |
| 35 | + |
| 36 | +# Install StrictDoc. Set default StrictDoc installation from PyPI but allow |
| 37 | +# overriding it with an environment variable. |
| 38 | +ARG HTML2PRINT_SOURCE="pypi" |
| 39 | +ENV HTML2PRINT_SOURCE=${HTML2PRINT_SOURCE} |
| 40 | + |
| 41 | +RUN if [ "$HTML2PRINT_SOURCE" = "pypi" ]; then \ |
| 42 | + pip install --no-cache-dir --upgrade pip && \ |
| 43 | + pip install --no-cache-dir html2print; \ |
| 44 | + else \ |
| 45 | + pip install --no-cache-dir --upgrade pip && \ |
| 46 | + pip install --no-cache-dir git+https://github.com/mettta/html2pdf_python.git@${HTML2PRINT_SOURCE}; \ |
| 47 | + fi; \ |
| 48 | + chmod -R 777 /opt/venv; |
| 49 | + |
| 50 | +USER html2print |
| 51 | + |
| 52 | +# Set the working directory to the user's home directory. |
| 53 | +WORKDIR /data |
| 54 | + |
| 55 | +ENTRYPOINT ["/bin/bash"] |
0 commit comments