From 0f6cdd91a918fee456cfe3a931ccc8c77197f5f7 Mon Sep 17 00:00:00 2001 From: TheOnlyWayUp Date: Fri, 6 Dec 2024 07:20:21 +0000 Subject: [PATCH] feat(api): Add pdfkit to requirements, wkhtml2pdf to Dockerfile --- Dockerfile | 16 +++++++++++++--- src/api/pyproject.toml | 1 + src/api/uv.lock | 11 +++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 89f28f2..df4f7aa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,13 +13,23 @@ FROM python:3.10-slim WORKDIR /app -# Install git -RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* +# Install git, wkhtmltopdf (https://raw.githubusercontent.com/JazzCore/python-pdfkit/b7bf798b946fa5655f8e82f0d80dec6b6b13d414/ci/before-script.sh) +RUN apt update + +RUN apt install -y git + +ENV WKHTML2PDF_VERSION='0.12.6-1' +RUN apt install -y build-essential xorg libssl-dev libxrender-dev wget +RUN wget "https://github.com/wkhtmltopdf/packaging/releases/download/${WKHTML2PDF_VERSION}/wkhtmltox_${WKHTML2PDF_VERSION}.bionic_amd64.deb" +RUN sudo apt install -y ./wkhtmltox_${WKHTML2PDF_VERSION}.bionic_amd64.deb + +RUN rm -rf /var/lib/apt/lists/* + +# --- # COPY src/api/requirements.txt requirements.txt RUN pip3 install -r requirements.txt COPY --from=0 /build/build /app/build -# COPY src/api/src/.env .env COPY src/api/src . EXPOSE 80 diff --git a/src/api/pyproject.toml b/src/api/pyproject.toml index f6f16e5..8160e1d 100644 --- a/src/api/pyproject.toml +++ b/src/api/pyproject.toml @@ -17,6 +17,7 @@ dependencies = [ "aiohttp-client-cache[all]", "bs4>=0.0.2", "uvicorn>=0.32.1", + "pdfkit>=1.0.0", ] [tool.ruff.lint] diff --git a/src/api/uv.lock b/src/api/uv.lock index b97c4da..0927fd7 100644 --- a/src/api/uv.lock +++ b/src/api/uv.lock @@ -220,6 +220,7 @@ dependencies = [ { name = "ebooklib" }, { name = "eliot" }, { name = "fastapi" }, + { name = "pdfkit" }, { name = "pydantic-settings" }, { name = "python-dotenv" }, { name = "rich" }, @@ -236,6 +237,7 @@ requires-dist = [ { name = "ebooklib", specifier = ">=0.18" }, { name = "eliot", specifier = ">=1.16.0" }, { name = "fastapi", specifier = ">=0.115.5" }, + { name = "pdfkit", specifier = ">=1.0.0" }, { name = "pydantic-settings", specifier = ">=2.6.1" }, { name = "python-dotenv", specifier = ">=1.0.1" }, { name = "rich", specifier = ">=13.9.4" }, @@ -708,6 +710,15 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/6a/05/7d768fa3ca23c9b3e1e09117abeded1501119f1d8de0ab722938c91ab25d/orjson-3.10.12-cp313-none-win_amd64.whl", hash = "sha256:229994d0c376d5bdc91d92b3c9e6be2f1fbabd4cc1b59daae1443a46ee5e9825", size = 134944 }, ] +[[package]] +name = "pdfkit" +version = "1.0.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/58/bb/6ddc62b4622776a6514fd749041c2b4bccd343e006d00de590f8090ac8b1/pdfkit-1.0.0.tar.gz", hash = "sha256:992f821e1e18fc8a0e701ecae24b51a2d598296a180caee0a24c0af181da02a9", size = 13288 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/64/1b/26c080096dd93936dccfd32c682bed3d5630a84aae9d493ff68afb2ae0fb/pdfkit-1.0.0-py3-none-any.whl", hash = "sha256:a7a4ca0d978e44fa8310c4909f087052430a6e8e0b1dd7ceef657f139789f96f", size = 12099 }, +] + [[package]] name = "propcache" version = "0.2.1"