From e18c5ac6eb1eaa2fa22cb5a87aa0124d46f5940b Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 19 Jun 2024 09:06:01 +0200 Subject: [PATCH 01/15] feat: add dependabot config --- .github/dependabot.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..4a12c46 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,18 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "daily" + time: "00:00" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + time: "00:00" \ No newline at end of file From c0075bb585748e7876826eb1954942de0241df91 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 19 Jun 2024 09:07:17 +0200 Subject: [PATCH 02/15] test: converter with absolute path #01 --- .github/workflows/md-to-pdf.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/md-to-pdf.yml b/.github/workflows/md-to-pdf.yml index 49f299e..1160646 100644 --- a/.github/workflows/md-to-pdf.yml +++ b/.github/workflows/md-to-pdf.yml @@ -39,7 +39,7 @@ jobs: - name: Run pypandoc run: | - python converter.py ${{ inputs.markdown-source-dir }} + python converter.py ${{ github.workspace }}/${{ inputs.markdown-source-dir }} - name: Run pandoc run: | From a094040d59ab77ec8e3d3523192bf2a2e1bae2eb Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 19 Jun 2024 09:12:36 +0200 Subject: [PATCH 03/15] test: converter with absolute path #02 --- .github/workflows/md-to-pdf.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/md-to-pdf.yml b/.github/workflows/md-to-pdf.yml index 1160646..1ed3b21 100644 --- a/.github/workflows/md-to-pdf.yml +++ b/.github/workflows/md-to-pdf.yml @@ -11,6 +11,10 @@ on: description: upload artifact required: false type: boolean + run-script: + description: test converter script + required: true + type: boolean defaults: run: @@ -38,9 +42,14 @@ jobs: python -m pip install pypandoc pypandoc-binary - name: Run pypandoc + if: inputs.run-script run: | python converter.py ${{ github.workspace }}/${{ inputs.markdown-source-dir }} + - name: Debug + run: | + ls -lthr ${{ github.workspace }}/${{ inputs.markdown-source-dir }} + - name: Run pandoc run: | pandoc README.md --from markdown --to html -o README.html From 71a54ae15351978fe93176087337002ac9f7e6eb Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 19 Jun 2024 09:13:48 +0200 Subject: [PATCH 04/15] test: converter with absolute path #03 --- .github/workflows/md-to-pdf.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/md-to-pdf.yml b/.github/workflows/md-to-pdf.yml index 1ed3b21..d6b979d 100644 --- a/.github/workflows/md-to-pdf.yml +++ b/.github/workflows/md-to-pdf.yml @@ -48,7 +48,7 @@ jobs: - name: Debug run: | - ls -lthr ${{ github.workspace }}/${{ inputs.markdown-source-dir }} + ls -lthr ${{ github.workspace }} - name: Run pandoc run: | From c46b7063df5042e55c4b31a77a71fa9f3a1c7f5f Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 19 Jun 2024 09:15:33 +0200 Subject: [PATCH 05/15] test: converter with absolute path #04 --- .github/workflows/md-to-pdf.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/md-to-pdf.yml b/.github/workflows/md-to-pdf.yml index d6b979d..c0793b3 100644 --- a/.github/workflows/md-to-pdf.yml +++ b/.github/workflows/md-to-pdf.yml @@ -48,7 +48,8 @@ jobs: - name: Debug run: | - ls -lthr ${{ github.workspace }} + ls -lthr + echo "${{ github.workspace }}" - name: Run pandoc run: | From 5684565e061309c472033961d8561859056d1c11 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 19 Jun 2024 09:16:51 +0200 Subject: [PATCH 06/15] test: converter with absolute path #05 --- .github/workflows/md-to-pdf.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/md-to-pdf.yml b/.github/workflows/md-to-pdf.yml index c0793b3..44a3960 100644 --- a/.github/workflows/md-to-pdf.yml +++ b/.github/workflows/md-to-pdf.yml @@ -49,6 +49,7 @@ jobs: - name: Debug run: | ls -lthr + pwd echo "${{ github.workspace }}" - name: Run pandoc From 39cd01d32fc4ccea184e9a9e9b14079860fbc1a9 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 19 Jun 2024 09:22:48 +0200 Subject: [PATCH 07/15] test: converter with absolute path #06 --- .github/workflows/md-to-pdf.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/md-to-pdf.yml b/.github/workflows/md-to-pdf.yml index 44a3960..1540947 100644 --- a/.github/workflows/md-to-pdf.yml +++ b/.github/workflows/md-to-pdf.yml @@ -51,6 +51,7 @@ jobs: ls -lthr pwd echo "${{ github.workspace }}" + echo "$GITHUB_WORKSPACE" - name: Run pandoc run: | From 6ba438e1056f0c16c9ab1a9ec5eb745021f82d14 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 19 Jun 2024 09:27:31 +0200 Subject: [PATCH 08/15] test: converter with absolute path #07 --- .github/workflows/md-to-pdf.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/md-to-pdf.yml b/.github/workflows/md-to-pdf.yml index 1540947..00b6101 100644 --- a/.github/workflows/md-to-pdf.yml +++ b/.github/workflows/md-to-pdf.yml @@ -44,14 +44,12 @@ jobs: - name: Run pypandoc if: inputs.run-script run: | - python converter.py ${{ github.workspace }}/${{ inputs.markdown-source-dir }} + python converter.py $GITHUB_WORKSPACE/${{ inputs.markdown-source-dir }} - - name: Debug - run: | - ls -lthr - pwd - echo "${{ github.workspace }}" - echo "$GITHUB_WORKSPACE" + #- name: Debug + # run: | + # echo "${{ github.workspace }}" + # echo "$GITHUB_WORKSPACE" - name: Run pandoc run: | From 382c9b7afe5a716740ac4848bac4a6cd57bfa584 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Wed, 19 Jun 2024 23:28:08 +0200 Subject: [PATCH 09/15] feat: update script message --- converter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/converter.py b/converter.py index c568182..3473560 100644 --- a/converter.py +++ b/converter.py @@ -27,7 +27,7 @@ source_md_files = [] output_pdf_files = [] -print("Convert MD to PDF:\n") +print("converter from markdown to PDF\n") for markdown_file in markdown_files: relative_path = markdown_file.relative_to(SOURCE_PATH_TO_MD) pdf_output_path = DESTINATION_PATH_TO_PDF / relative_path.with_suffix(".pdf") From 8430a927815b577ceca0afa4d511f72945475ca1 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Thu, 20 Jun 2024 00:14:06 +0200 Subject: [PATCH 10/15] feat: add pandoc docker image --- image/Dockerfile | 18 ++++++++++++++++++ image/entrypoint.sh | 5 +++++ 2 files changed, 23 insertions(+) create mode 100644 image/Dockerfile create mode 100644 image/entrypoint.sh diff --git a/image/Dockerfile b/image/Dockerfile new file mode 100644 index 0000000..d3b74a5 --- /dev/null +++ b/image/Dockerfile @@ -0,0 +1,18 @@ +ARG PANDOC_IMAGE_NAME=pandoc/latex +ARG PANDOC_IMAGE_TAG=edge-ubuntu + +FROM ${PANDOC_IMAGE_NAME}:${PANDOC_IMAGE_TAG} AS pypandoc + +RUN apt-get update && \ + apt-get install -y \ + unzip python3 python3.12-venv python3-pip -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +RUN mkdir /app && \ + pip3 install pypandoc pypandoc-binary --break-system-packages + +COPY ./entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT [ "/bin/bash", "-c", "bash /entrypoint.sh" ] diff --git a/image/entrypoint.sh b/image/entrypoint.sh new file mode 100644 index 0000000..d0bfc85 --- /dev/null +++ b/image/entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# shellcheck source=/dev/null +source /data/venv/bin/activate +exec "$@" From 4921ff0212cc744195085a347b747371ae7c8219 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Thu, 20 Jun 2024 00:31:18 +0200 Subject: [PATCH 11/15] feat: set python3 as docker entrypoint --- image/Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/image/Dockerfile b/image/Dockerfile index d3b74a5..68c2fbf 100644 --- a/image/Dockerfile +++ b/image/Dockerfile @@ -12,7 +12,4 @@ RUN apt-get update && \ RUN mkdir /app && \ pip3 install pypandoc pypandoc-binary --break-system-packages -COPY ./entrypoint.sh /entrypoint.sh -RUN chmod +x /entrypoint.sh - -ENTRYPOINT [ "/bin/bash", "-c", "bash /entrypoint.sh" ] +ENTRYPOINT ["/usr/bin/python3"] From 9144153f8056aa85bb898813aa7aac8692f67d13 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Thu, 20 Jun 2024 00:42:25 +0200 Subject: [PATCH 12/15] fix: handler error exit script --- converter.py | 1 + 1 file changed, 1 insertion(+) diff --git a/converter.py b/converter.py index 3473560..0adbcb1 100644 --- a/converter.py +++ b/converter.py @@ -23,6 +23,7 @@ if not markdown_files: print(f"No markdown files found in {SOURCE_PATH_TO_MD}") + sys.exit(1) source_md_files = [] output_pdf_files = [] From cbba7bc8af3c458e184eed4c08644ae9ca6479d4 Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Thu, 20 Jun 2024 01:07:06 +0200 Subject: [PATCH 13/15] feat: docker image improvements --- image/Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/image/Dockerfile b/image/Dockerfile index 68c2fbf..43f785f 100644 --- a/image/Dockerfile +++ b/image/Dockerfile @@ -9,7 +9,7 @@ RUN apt-get update && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -RUN mkdir /app && \ - pip3 install pypandoc pypandoc-binary --break-system-packages +RUN pip3 install pypandoc pypandoc-binary \ + --break-system-packages -ENTRYPOINT ["/usr/bin/python3"] +ENTRYPOINT ["python3"] From 06c404047221e8f8de6af1f3c04ca9b60fff028d Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Thu, 20 Jun 2024 02:02:19 +0200 Subject: [PATCH 14/15] feat: converter script improvements and absolute paths --- converter.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/converter.py b/converter.py index 0adbcb1..c638c50 100644 --- a/converter.py +++ b/converter.py @@ -16,19 +16,21 @@ print("Invalid path to markdown directory!") sys.exit(1) -if not DESTINATION_PATH_TO_PDF.exists(): - DESTINATION_PATH_TO_PDF.mkdir() - markdown_files = list(SOURCE_PATH_TO_MD.rglob("*.md")) if not markdown_files: print(f"No markdown files found in {SOURCE_PATH_TO_MD}") sys.exit(1) +if not DESTINATION_PATH_TO_PDF.exists(): + DESTINATION_PATH_TO_PDF.mkdir() + source_md_files = [] output_pdf_files = [] -print("converter from markdown to PDF\n") +print("Converter from markdown to PDF\n") +print(f"Input directory: {SOURCE_PATH_TO_MD.absolute()}") +print(f"Output directory: {DESTINATION_PATH_TO_PDF.absolute()}\n") for markdown_file in markdown_files: relative_path = markdown_file.relative_to(SOURCE_PATH_TO_MD) pdf_output_path = DESTINATION_PATH_TO_PDF / relative_path.with_suffix(".pdf") @@ -41,12 +43,12 @@ try: pypandoc.convert_file( str(markdown_file), - 'pdf', + "pdf", outputfile=str(pdf_output_path), extra_args=[ - '--pdf-engine=pdflatex', - '--from=markdown+rebase_relative_paths' - ] + "--pdf-engine=pdflatex", + "--from=markdown+rebase_relative_paths", + ], ) except Exception as e: print(f"Error converting {markdown_file}: {e}") @@ -54,8 +56,8 @@ print("Source markdown files:") for input_md in source_md_files: - print(input_md) + print(input_md.absolute()) print("\nOutput PDF files:") for output_pdf in output_pdf_files: - print(output_pdf) + print(output_pdf.absolute()) From f5d9aa6c0d9acd30d3ac650af7ce74382cb6f14b Mon Sep 17 00:00:00 2001 From: lbrealdev Date: Thu, 20 Jun 2024 02:18:09 +0200 Subject: [PATCH 15/15] feat: add docker images converter/pypandoc --- .gitignore | 1 - images/converter-python/Dockerfile | 21 +++++++++++++++++++ {image => images/pypandoc-python}/Dockerfile | 0 .../pypandoc-python}/entrypoint.sh | 0 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 images/converter-python/Dockerfile rename {image => images/pypandoc-python}/Dockerfile (100%) rename {image => images/pypandoc-python}/entrypoint.sh (100%) diff --git a/.gitignore b/.gitignore index 53100f9..39b7120 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ venv/ # Output PDF path directory _output/ - diff --git a/images/converter-python/Dockerfile b/images/converter-python/Dockerfile new file mode 100644 index 0000000..c9f03eb --- /dev/null +++ b/images/converter-python/Dockerfile @@ -0,0 +1,21 @@ +ARG PANDOC_IMAGE_NAME=pandoc/latex +ARG PANDOC_IMAGE_TAG=edge-ubuntu + +FROM ${PANDOC_IMAGE_NAME}:${PANDOC_IMAGE_TAG} AS pypandoc + +RUN apt-get update && \ + apt-get install -y \ + unzip python3 python3.12-venv python3-pip -y && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +RUN pip3 install pypandoc pypandoc-binary \ + --break-system-packages + +RUN mkdir /app + +COPY converter.py /app/converter.py + +ENTRYPOINT ["python3", "/app/converter.py"] +CMD [] + diff --git a/image/Dockerfile b/images/pypandoc-python/Dockerfile similarity index 100% rename from image/Dockerfile rename to images/pypandoc-python/Dockerfile diff --git a/image/entrypoint.sh b/images/pypandoc-python/entrypoint.sh similarity index 100% rename from image/entrypoint.sh rename to images/pypandoc-python/entrypoint.sh