Skip to content

Commit b73bbe4

Browse files
committed
WIP
1 parent 3343e04 commit b73bbe4

10 files changed

Lines changed: 136 additions & 3 deletions

File tree

.github/workflows/docker.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: HTML2Print Docker CI
2+
3+
on:
4+
pull_request:
5+
branches: [ "**" ]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- name: Build Docker image with PR branch
15+
run: |
16+
docker build . \
17+
--build-arg HTML2PRINT_SOURCE=${{ github.event.pull_request.head.sha }} \
18+
-t html2print:pr-${{ github.event.pull_request.number }}
19+
20+
- name: Run container and test StrictDoc installation
21+
run: |
22+
docker run --name html2print --rm -v "$(pwd):/data" \
23+
--entrypoint="" \
24+
--user "$(id -u):$(id -g)" \
25+
html2print:pr-${{ github.event.pull_request.number }} \
26+
/bin/bash -c "cd tests/integration/01_hello_world && html2print print --cache-dir output/html2print index.html %S/output/index.pdf"
File renamed without changes.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# HTML2PDF JS file.
2-
html2print/html2pdf_js/
2+
# html2print/html2pdf_js/
33

44
.idea/
55
**/.wdm/

Dockerfile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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"]

html2print/html2pdf_js/html2pdf.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

html2print/html2print.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def create_webdriver(
320320
webdriver_options.add_argument("start-maximized")
321321
webdriver_options.add_argument("disable-infobars")
322322
webdriver_options.add_argument("--disable-extensions")
323-
webdriver_options.add_argument("--headless")
323+
webdriver_options.add_argument("--headless=new")
324324
# FIXME: This is not nice but otherwise it does not work in Ubuntu 24-based Docker image.
325325
# https://github.com/SeleniumHQ/selenium/issues/15327#issuecomment-2689287561
326326
webdriver_options.add_argument("--no-sandbox")

tasks.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def run_invoke(
3030
cmd,
3131
environment: Optional[dict] = None,
3232
warn: bool = False,
33+
pty: bool = False,
3334
) -> invoke.runners.Result:
3435
def one_line_command(string):
3536
return re.sub("\\s+", " ", string).strip()
@@ -39,7 +40,7 @@ def one_line_command(string):
3940
env=environment,
4041
hide=False,
4142
warn=warn,
42-
pty=False,
43+
pty=pty,
4344
echo=True,
4445
)
4546

@@ -267,3 +268,52 @@ def release(context, test_pypi=False, username=None, password=None):
267268
{user_password}
268269
""",
269270
)
271+
272+
273+
@task(aliases=["bd"])
274+
def build_docker(context, no_cache: bool = False, source="pypi"):
275+
no_cache_argument = "--no-cache" if no_cache else ""
276+
run_invoke(
277+
context,
278+
f"""
279+
docker build .
280+
--build-arg HTML2PRINT_SOURCE={source}
281+
-t html2print:latest
282+
{no_cache_argument}
283+
"""
284+
)
285+
286+
287+
@task(aliases=["td"])
288+
def test_docker(context):
289+
run_invoke(
290+
context,
291+
"""
292+
docker run
293+
--name html2print
294+
--rm
295+
-v "$(pwd):/data"
296+
--user "$(id -u):$(id -g)"
297+
--entrypoint=""
298+
html2print:latest
299+
/bin/bash -c
300+
"cd tests/integration/01_hello_world && html2pdf print index.html %S/output/index.pdf"
301+
"""
302+
)
303+
304+
305+
@task(aliases=["rd"])
306+
def run_docker(context):
307+
run_invoke(
308+
context,
309+
"""
310+
docker run
311+
--name html2print
312+
--rm
313+
-it
314+
-v "$(pwd):/data"
315+
--user "$(id -u):$(id -g)"
316+
html2print:latest
317+
""",
318+
pty=True
319+
)
7.32 KB
Binary file not shown.

0 commit comments

Comments
 (0)