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 5 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
18 changes: 16 additions & 2 deletions jupyter/minimal/ubi9-python-3.11/Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ 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



####################
# jupyter-minimal #
####################
Expand All @@ -45,6 +47,16 @@ WORKDIR /opt/app-root/bin

COPY ${JUPYTER_REUSABLE_UTILS} utils/

USER 0

# TexLive dependency for PDF export
RUN ./utils/install_tex_live.sh

ENV PATH="/usr/local/texlive/2025/bin/x86_64-linux:$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 +67,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"]
8 changes: 8 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

# TexLive dependency for PDF export
RUN ./utils/install_tex_live.sh
ENV PATH="/usr/local/texlive/2025/bin/x86_64-linux:$PATH"

USER 1001

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

# Install Python dependencies from Pipfile.lock file
Expand Down
8 changes: 8 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

# TexLive dependency for PDF export
RUN ./utils/install_tex_live.sh
ENV PATH="/usr/local/texlive/2025/bin/x86_64-linux:$PATH"

USER 1001

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

# Install Python dependencies from Pipfile.lock file
Expand Down
7 changes: 7 additions & 0 deletions jupyter/utils/install_tex_live.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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 && \
cd /usr/local/texlive/2025/bin/x86_64-linux && \
./tlmgr install tcolorbox pdfcol adjustbox titling enumitem soul ucs collection-fontsrecommended
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
107 changes: 107 additions & 0 deletions logs/pytest-logs.txt

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions tests/containers/workbenches/jupyterlab/jupyterlab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import allure
import requests
import tempfile
import pathlib

from tests.containers import docker_utils
from tests.containers.workbenches.workbench_image_test import WorkbenchContainer
Expand Down Expand Up @@ -54,3 +56,20 @@ def test_spinner_html_loaded(self, jupyterlab_image: docker.models.images.Image)
assert 'class="pf-v6-c-spinner"' in response.text
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: docker.models.images.Image) -> None:
container = WorkbenchContainer(image=jupyterlab_image, user=4321, group_add=[0])
test_file_name = "test.ipybn"
try:
container.start(wait_for_readiness=True)
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = pathlib.Path(tmpdir)
(tmpdir / test_file_name).write_text("{\"cells\": []}")
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)
Loading