Skip to content

RHOAIENG-16568: [Bug] Unable to download notebook as a PDF from JupyterLab Workbenches #1030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ MANIFEST
pip-log.txt
pip-delete-this-directory.txt

# Test logs
logs/pytest-logs.txt

# Unit test / coverage reports
htmlcov/
.tox/
Expand Down
10 changes: 10 additions & 0 deletions jupyter/datascience/ubi9-python-3.11/Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ WORKDIR /opt/app-root/bin
COPY ${JUPYTER_REUSABLE_UTILS} utils/
COPY ${MINIMAL_SOURCE_CODE}/start-notebook.sh ./

USER 0

# Dependencies for PDF export
RUN ./utils/install_pdf_deps.sh
ENV PATH="/usr/local/texlive/bin/x86_64-linux:/usr/local/pandoc/bin:$PATH"

USER 1001

WORKDIR /opt/app-root/src

ENTRYPOINT ["start-notebook.sh"]
Expand Down Expand Up @@ -107,6 +115,8 @@ RUN echo "Installing softwares and packages" && \
rm /opt/app-root/share/jupyter/metadata/runtime-images/*.json && \
# Replace Notebook's launcher, "(ipykernel)" with Python's version 3.x.y \
sed -i -e "s/Python.*/$(python --version | cut -d '.' -f-2)\",/" /opt/app-root/share/jupyter/kernels/python3/kernel.json && \
# copy jupyter configuration
cp /opt/app-root/bin/utils/jupyter_server_config.py /opt/app-root/etc/jupyter && \
# Disable announcement plugin of jupyterlab \
jupyter labextension disable "@jupyterlab/apputils-extension:announcements" && \
# Apply JupyterLab addons \
Expand Down
14 changes: 12 additions & 2 deletions jupyter/minimal/ubi9-python-3.11/Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN pip install --no-cache-dir -U "micropipenv[toml]"

# Install the oc client
RUN curl -L https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/clients/ocp/stable/openshift-client-linux.tar.gz \
-o /tmp/openshift-client-linux.tar.gz && \
-o /tmp/openshift-client-linux.tar.gz && \
tar -xzvf /tmp/openshift-client-linux.tar.gz oc && \
rm -f /tmp/openshift-client-linux.tar.gz

Expand All @@ -45,6 +45,14 @@ WORKDIR /opt/app-root/bin

COPY ${JUPYTER_REUSABLE_UTILS} utils/

USER 0

# Dependencies for PDF export
RUN ./utils/install_pdf_deps.sh
ENV PATH="/usr/local/texlive/bin/x86_64-linux:/usr/local/pandoc/bin:$PATH"

USER 1001

COPY ${MINIMAL_SOURCE_CODE}/Pipfile.lock ${MINIMAL_SOURCE_CODE}/start-notebook.sh ./

# Install Python dependencies from Pipfile.lock file
Expand All @@ -55,12 +63,14 @@ RUN echo "Installing softwares and packages" && \
jupyter labextension disable "@jupyterlab/apputils-extension:announcements" && \
# Replace Notebook's launcher, "(ipykernel)" with Python's version 3.x.y \
sed -i -e "s/Python.*/$(python --version | cut -d '.' -f-2)\",/" /opt/app-root/share/jupyter/kernels/python3/kernel.json && \
# copy jupyter configuration
cp /opt/app-root/bin/utils/jupyter_server_config.py /opt/app-root/etc/jupyter && \
# Fix permissions to support pip in Openshift environments \
chmod -R g+w /opt/app-root/lib/python3.11/site-packages && \
fix-permissions /opt/app-root -P && \
# Apply JupyterLab addons \
/opt/app-root/bin/utils/addons/apply.sh

WORKDIR /opt/app-root/src

ENTRYPOINT ["start-notebook.sh"]
10 changes: 10 additions & 0 deletions jupyter/minimal/ubi9-python-3.11/Dockerfile.cuda
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ WORKDIR /opt/app-root/bin

COPY ${JUPYTER_REUSABLE_UTILS} utils/

USER 0

# Dependencies for PDF export
RUN ./utils/install_pdf_deps.sh
ENV PATH="/usr/local/texlive/bin/x86_64-linux:/usr/local/pandoc/bin:$PATH"

USER 1001

COPY ${MINIMAL_SOURCE_CODE}/Pipfile.lock ${MINIMAL_SOURCE_CODE}/start-notebook.sh ./

# Install Python dependencies from Pipfile.lock file
Expand All @@ -175,6 +183,8 @@ RUN echo "Installing softwares and packages" && \
jupyter labextension disable "@jupyterlab/apputils-extension:announcements" && \
# Replace Notebook's launcher, "(ipykernel)" with Python's version 3.x.y \
sed -i -e "s/Python.*/$(python --version | cut -d '.' -f-2)\",/" /opt/app-root/share/jupyter/kernels/python3/kernel.json && \
# copy jupyter configuration
cp /opt/app-root/bin/utils/jupyter_server_config.py /opt/app-root/etc/jupyter && \
# Fix permissions to support pip in Openshift environments \
chmod -R g+w /opt/app-root/lib/python3.11/site-packages && \
fix-permissions /opt/app-root -P && \
Expand Down
10 changes: 10 additions & 0 deletions jupyter/minimal/ubi9-python-3.11/Dockerfile.rocm
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ WORKDIR /opt/app-root/bin

COPY ${JUPYTER_REUSABLE_UTILS} utils/

USER 0

# Dependencies for PDF export
RUN ./utils/install_pdf_deps.sh
ENV PATH="/usr/local/texlive/bin/x86_64-linux:/usr/local/pandoc/bin:$PATH"

USER 1001

COPY ${MINIMAL_SOURCE_CODE}/Pipfile.lock ${MINIMAL_SOURCE_CODE}/start-notebook.sh ./

# Install Python dependencies from Pipfile.lock file
Expand All @@ -89,6 +97,8 @@ RUN echo "Installing softwares and packages" && \
jupyter labextension disable "@jupyterlab/apputils-extension:announcements" && \
# Replace Notebook's launcher, "(ipykernel)" with Python's version 3.x.y \
sed -i -e "s/Python.*/$(python --version | cut -d '.' -f-2)\",/" /opt/app-root/share/jupyter/kernels/python3/kernel.json && \
# copy jupyter configuration
cp /opt/app-root/bin/utils/jupyter_server_config.py /opt/app-root/etc/jupyter && \
# Fix permissions to support pip in Openshift environments \
chmod -R g+w /opt/app-root/lib/python3.11/site-packages && \
fix-permissions /opt/app-root -P && \
Expand Down
10 changes: 10 additions & 0 deletions jupyter/pytorch/ubi9-python-3.11/Dockerfile.cuda
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ COPY ${JUPYTER_REUSABLE_UTILS} utils/

COPY ${MINIMAL_SOURCE_CODE}/start-notebook.sh ./

USER 0

# Dependencies for PDF export
RUN ./utils/install_pdf_deps.sh
ENV PATH="/usr/local/texlive/bin/x86_64-linux:/usr/local/pandoc/bin:$PATH"

USER 1001

WORKDIR /opt/app-root/src

ENTRYPOINT ["start-notebook.sh"]
Expand Down Expand Up @@ -239,6 +247,8 @@ RUN echo "Installing softwares and packages" && \
rm /opt/app-root/share/jupyter/metadata/runtime-images/*.json && \
# Replace Notebook's launcher, "(ipykernel)" with Python's version 3.x.y \
sed -i -e "s/Python.*/$(python --version | cut -d '.' -f-2)\",/" /opt/app-root/share/jupyter/kernels/python3/kernel.json && \
# copy jupyter configuration
cp /opt/app-root/bin/utils/jupyter_server_config.py /opt/app-root/etc/jupyter && \
# Disable announcement plugin of jupyterlab \
jupyter labextension disable "@jupyterlab/apputils-extension:announcements" && \
# Apply JupyterLab addons \
Expand Down
10 changes: 10 additions & 0 deletions jupyter/rocm/pytorch/ubi9-python-3.11/Dockerfile.rocm
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ COPY ${JUPYTER_REUSABLE_UTILS} utils/

COPY ${MINIMAL_SOURCE_CODE}/start-notebook.sh ./

USER 0

# Dependencies for PDF export
RUN ./utils/install_pdf_deps.sh
ENV PATH="/usr/local/texlive/bin/x86_64-linux:/usr/local/pandoc/bin:$PATH"

USER 1001

WORKDIR /opt/app-root/src

ENTRYPOINT ["start-notebook.sh"]
Expand Down Expand Up @@ -153,6 +161,8 @@ RUN echo "Installing softwares and packages" && \
rm /opt/app-root/share/jupyter/metadata/runtime-images/*.json && \
# Replace Notebook's launcher, "(ipykernel)" with Python's version 3.x.y \
sed -i -e "s/Python.*/$(python --version | cut -d '.' -f-2)\",/" /opt/app-root/share/jupyter/kernels/python3/kernel.json && \
# copy jupyter configuration
cp /opt/app-root/bin/utils/jupyter_server_config.py /opt/app-root/etc/jupyter && \
# Disable announcement plugin of jupyterlab \
jupyter labextension disable "@jupyterlab/apputils-extension:announcements" && \
# Apply JupyterLab addons \
Expand Down
10 changes: 10 additions & 0 deletions jupyter/rocm/tensorflow/ubi9-python-3.11/Dockerfile.rocm
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ WORKDIR /opt/app-root/bin

COPY ${JUPYTER_REUSABLE_UTILS} utils/

USER 0

# Dependencies for PDF export
RUN ./utils/install_pdf_deps.sh
ENV PATH="/usr/local/texlive/bin/x86_64-linux:/usr/local/pandoc/bin:$PATH"

USER 1001

COPY ${MINIMAL_SOURCE_CODE}/start-notebook.sh ./

WORKDIR /opt/app-root/src
Expand Down Expand Up @@ -153,6 +161,8 @@ RUN echo "Installing softwares and packages" && \
rm /opt/app-root/share/jupyter/metadata/runtime-images/*.json && \
# Replace Notebook's launcher, "(ipykernel)" with Python's version 3.x.y \
sed -i -e "s/Python.*/$(python --version | cut -d '.' -f-2)\",/" /opt/app-root/share/jupyter/kernels/python3/kernel.json && \
# copy jupyter configuration
cp /opt/app-root/bin/utils/jupyter_server_config.py /opt/app-root/etc/jupyter && \
# Disable announcement plugin of jupyterlab \
jupyter labextension disable "@jupyterlab/apputils-extension:announcements" && \
# Apply JupyterLab addons \
Expand Down
10 changes: 10 additions & 0 deletions jupyter/tensorflow/ubi9-python-3.11/Dockerfile.cuda
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ COPY ${JUPYTER_REUSABLE_UTILS} utils/

COPY ${MINIMAL_SOURCE_CODE}/start-notebook.sh ./

USER 0

# Dependencies for PDF export
RUN ./utils/install_pdf_deps.sh
ENV PATH="/usr/local/texlive/bin/x86_64-linux:/usr/local/pandoc/bin:$PATH"

USER 1001

WORKDIR /opt/app-root/src

ENTRYPOINT ["start-notebook.sh"]
Expand Down Expand Up @@ -239,6 +247,8 @@ RUN echo "Installing softwares and packages" && \
rm /opt/app-root/share/jupyter/metadata/runtime-images/*.json && \
# Replace Notebook's launcher, "(ipykernel)" with Python's version 3.x.y \
sed -i -e "s/Python.*/$(python --version | cut -d '.' -f-2)\",/" /opt/app-root/share/jupyter/kernels/python3/kernel.json && \
# copy jupyter configuration
cp /opt/app-root/bin/utils/jupyter_server_config.py /opt/app-root/etc/jupyter && \
# Disable announcement plugin of jupyterlab \
jupyter labextension disable "@jupyterlab/apputils-extension:announcements" && \
# Apply JupyterLab addons \
Expand Down
10 changes: 10 additions & 0 deletions jupyter/trustyai/ubi9-python-3.11/Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ WORKDIR /opt/app-root/bin
COPY ${JUPYTER_REUSABLE_UTILS} utils/
COPY ${MINIMAL_SOURCE_CODE}/start-notebook.sh ./

USER 0

# Dependencies for PDF export
RUN ./utils/install_pdf_deps.sh
ENV PATH="/usr/local/texlive/bin/x86_64-linux:/usr/local/pandoc/bin:$PATH"

USER 1001

WORKDIR /opt/app-root/src

ENTRYPOINT ["start-notebook.sh"]
Expand Down Expand Up @@ -126,6 +134,8 @@ RUN echo "Installing softwares and packages" && \
rm /opt/app-root/share/jupyter/metadata/runtime-images/*.json && \
# Replace Notebook's launcher, "(ipykernel)" with Python's version 3.x.y \
sed -i -e "s/Python.*/$(python --version | cut -d '.' -f-2)\",/" /opt/app-root/share/jupyter/kernels/python3/kernel.json && \
# copy jupyter configuration
cp /opt/app-root/bin/utils/jupyter_server_config.py /opt/app-root/etc/jupyter && \
# Disable announcement plugin of jupyterlab \
jupyter labextension disable "@jupyterlab/apputils-extension:announcements" && \
# Apply JupyterLab addons \
Expand Down
18 changes: 18 additions & 0 deletions jupyter/utils/install_pdf_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Install dependencies required for Notebooks PDF exports

# tex live installation
echo "Installing TexLive to allow PDf export from Notebooks"
curl -L https://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz -o install-tl-unx.tar.gz
zcat < install-tl-unx.tar.gz | tar xf -
cd install-tl-2*
perl ./install-tl --no-interaction --scheme=scheme-small --texdir=/usr/local/texlive
cd /usr/local/texlive/bin/x86_64-linux
./tlmgr install tcolorbox pdfcol adjustbox titling enumitem soul ucs collection-fontsrecommended

# pandoc installation
curl -L https://github.com/jgm/pandoc/releases/download/3.6.4/pandoc-3.6.4-linux-amd64.tar.gz -o /tmp/pandoc.tar.gz
mkdir -p /usr/local/pandoc
tar xvzf /tmp/pandoc.tar.gz --strip-components 1 -C /usr/local/pandoc/
rm -f /tmp/pandoc.tar.gz
6 changes: 6 additions & 0 deletions jupyter/utils/jupyter_server_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://github.com/opendatahub-io-contrib/workbench-images/blob/main/snippets/ides/1-jupyter/files/etc/jupyter_notebook_config.py
c = get_config()
# Disable unsupported exporters
c.WebPDFExporter.enabled = False
c.QtPDFExporter.enabled = False
c.QtPNGExporter.enabled = False
50 changes: 49 additions & 1 deletion tests/containers/workbenches/jupyterlab/jupyterlab_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

import pathlib
import tempfile
import textwrap
import allure
import pytest
import requests
Expand Down Expand Up @@ -51,6 +54,51 @@ def test_spinner_html_loaded(self, jupyterlab_image: conftest.Image) -> None:
finally:
docker_utils.NotebookContainer(container).stop(timeout=0)

@allure.issue("RHOAIENG-16568")
@allure.description("Check that PDF export is working correctly")
def test_pdf_export(self, jupyterlab_image: conftest.Image) -> None:
container = WorkbenchContainer(image=jupyterlab_image.name, user=4321, group_add=[0])
test_file_name = "test.ipybn"
test_file_content = """{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [ "# Hello World" ]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [ "Hello World\n" ]
}
],
"source": [ "print('Hello World')" ]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
""".replace('\n', '')
try:
container.start(wait_for_readiness=True)
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = pathlib.Path(tmpdir)
(tmpdir / test_file_name).write_text(test_file_content)
docker_utils.container_cp(
container.get_wrapped_container(), src=str(tmpdir / test_file_name), dst=self.APP_ROOT_HOME
)
exit_code, convert_output = container.exec(["jupyter", "nbconvert", test_file_name, "--to", "pdf"])
assert "PDF successfully created" in convert_output.decode()
assert 0 == exit_code
finally:
docker_utils.NotebookContainer(container).stop(timeout=0)

@allure.issue("RHOAIENG-24348")
@allure.description("Check that custom-built (to be FIPS-compliant) mongocli binary runs.")
def test_mongocli_binary_runs(self, jupyterlab_image: conftest.Image) -> None:
Expand All @@ -65,4 +113,4 @@ def test_mongocli_binary_runs(self, jupyterlab_image: conftest.Image) -> None:
# we did not manage to get `mongocli --version` to work, so we'll run this instead
docker_utils.container_exec(container.get_wrapped_container(), "mongocli config --help")
finally:
docker_utils.NotebookContainer(container).stop(timeout=0) # if no env is specified, the image will run
docker_utils.NotebookContainer(container).stop(timeout=0) # if no env is specified, the image will run
Loading