From 591ee26df09c17b4420aa874b2e25b99521185b8 Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Fri, 28 Aug 2026 11:21:11 -0400 Subject: [PATCH 1/7] feat: add docker environment to run the checks locally Signed-off-by: YvesCesar --- Dockerfile | 14 ++++++++++++++ README.md | 33 +++++++++++++++++++++++++++++++++ compose.yml | 9 +++++++++ 3 files changed, 56 insertions(+) create mode 100644 Dockerfile create mode 100644 compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2b22a0a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM php:8.4-cli + +# zip: ZipArchive in JSignPdfRuntimeService | sockets: donatj/mock-webserver in the tests +RUN apt-get update \ + && apt-get install -y --no-install-recommends libzip-dev unzip \ + && docker-php-ext-install zip sockets \ + && rm -rf /var/lib/apt/lists/* + +# PharData exceeds the default 128M just to open the JRE tarball +RUN echo 'memory_limit=512M' > /usr/local/etc/php/conf.d/app.ini + +COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer + +WORKDIR /app diff --git a/README.md b/README.md index 68dc638..522eb5f 100644 --- a/README.md +++ b/README.md @@ -64,5 +64,38 @@ Change parameters of JSignPDF: $param->setJSignParameters("-a -kst PKCS12 -ts https://freetsa.org/tsr"); ``` +## Docker Environment + +The repository ships a minimal Docker setup (`Dockerfile` and `compose.yml`) with PHP 8.4 and the +extensions the test suite needs. Adjust the `user:` line in `compose.yml` to your own `id -u`/`id -g` +so the files it writes are not owned by root. + +```bash +docker compose build +docker compose run --rm php composer install +``` + +Checks, the same ones the CI runs: + +```bash +docker compose run --rm php composer run test:unit +docker compose run --rm php composer run cs:check # cs:fix to apply the formatting +docker compose run --rm php composer run psalm +``` + +To sign a PDF end to end. It downloads the JRE and the JSignPdf jar into `tmp/` on the first run: + +```bash +docker compose run --rm php php example/index.php +``` + +The cached runtime left in `tmp/` makes `JavaRuntimeServiceTest` fail. Remove the whole directory +before running the suite again, not only the version marker, otherwise the next download cannot +overwrite the extracted JRE: + +```bash +rm -rf tmp/java tmp/jsignpdf +``` + ## Credits - [Jeidison Farias](https://github.com/jeidison) diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..f4c23c3 --- /dev/null +++ b/compose.yml @@ -0,0 +1,9 @@ +services: + php: + build: . + # your own uid:gid, so vendor/ is not written as root (see: id -u; id -g) + user: "1000:1000" + environment: + COMPOSER_HOME: /tmp/composer + volumes: + - .:/app From 50cf1f56d17c1a2082f6365b433e6135df6801ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yves=20C=C3=A9sar=20Amorim=20de=20Azevedo?= <48072419+YvesCesar@users.noreply.github.com> Date: Mon, 31 Aug 2026 09:27:15 -0400 Subject: [PATCH 2/7] Update compose.yml Co-authored-by: Vitor Mattos --- compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose.yml b/compose.yml index f4c23c3..310e470 100644 --- a/compose.yml +++ b/compose.yml @@ -4,6 +4,6 @@ services: # your own uid:gid, so vendor/ is not written as root (see: id -u; id -g) user: "1000:1000" environment: - COMPOSER_HOME: /tmp/composer + COMPOSER_HOME: ${COMPOSER_HOME:-/tmp/composer} volumes: - .:/app From d9dca95d6da693eb2a219f832b908655160208ff Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Mon, 31 Aug 2026 09:37:21 -0400 Subject: [PATCH 3/7] refactor: use install-php-extensions in the docker image Signed-off-by: YvesCesar --- Dockerfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2b22a0a..8ed46e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,15 @@ FROM php:8.4-cli # zip: ZipArchive in JSignPdfRuntimeService | sockets: donatj/mock-webserver in the tests -RUN apt-get update \ - && apt-get install -y --no-install-recommends libzip-dev unzip \ - && docker-php-ext-install zip sockets \ - && rm -rf /var/lib/apt/lists/* +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ +RUN chmod uga+x /usr/local/bin/install-php-extensions && sync \ + && install-php-extensions \ + sockets \ + zip \ + @composer \ + && rm /usr/local/bin/install-php-extensions # PharData exceeds the default 128M just to open the JRE tarball RUN echo 'memory_limit=512M' > /usr/local/etc/php/conf.d/app.ini -COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer - WORKDIR /app From 913e63667ff0b23e3dd78df6638e7de465cb1ccb Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Mon, 31 Aug 2026 10:05:00 -0400 Subject: [PATCH 4/7] refactor: set the container user from HOST_UID/HOST_GID with default values Signed-off-by: YvesCesar --- README.md | 5 ++--- compose.yml | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 522eb5f..11bbb71 100644 --- a/README.md +++ b/README.md @@ -66,9 +66,8 @@ $param->setJSignParameters("-a -kst PKCS12 -ts https://freetsa.org/tsr"); ## Docker Environment -The repository ships a minimal Docker setup (`Dockerfile` and `compose.yml`) with PHP 8.4 and the -extensions the test suite needs. Adjust the `user:` line in `compose.yml` to your own `id -u`/`id -g` -so the files it writes are not owned by root. +The repository ships a minimal Docker setup (`Dockerfile` and `compose.yml`) with the extensions +the test suite needs. ```bash docker compose build diff --git a/compose.yml b/compose.yml index 310e470..82c0200 100644 --- a/compose.yml +++ b/compose.yml @@ -1,8 +1,8 @@ services: php: build: . - # your own uid:gid, so vendor/ is not written as root (see: id -u; id -g) - user: "1000:1000" + # export HOST_UID/HOST_GID if yours are not 1000, so the files it writes are yours (see: id -u; id -g) + user: "${HOST_UID:-1000}:${HOST_GID:-1000}" environment: COMPOSER_HOME: ${COMPOSER_HOME:-/tmp/composer} volumes: From 53b11a2b25c0b1810c5ff3b1656177843c90a014 Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Mon, 31 Aug 2026 11:20:45 -0400 Subject: [PATCH 5/7] fix: isolate JavaRuntimeServiceTest from the repository tmp directory Signed-off-by: YvesCesar --- tests/Runtime/JavaRuntimeServiceTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Runtime/JavaRuntimeServiceTest.php b/tests/Runtime/JavaRuntimeServiceTest.php index 8f16ba0..a86e88f 100644 --- a/tests/Runtime/JavaRuntimeServiceTest.php +++ b/tests/Runtime/JavaRuntimeServiceTest.php @@ -170,6 +170,7 @@ public function testGetPathWithDownloadUrlWithInvalidVersion(): void $baseUrl = $server->getServerRoot(); $url = $baseUrl . '/OpenJDK21U-jre_x64_linux_hotspot_21.0.8_9.tar.gz'; $jsignParam->setJavaDownloadUrl($url); + $jsignParam->setJavaPath($this->testTmpDir . '/bin/java'); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessageMatches('/cannot be extracted/'); From c21868080bca749ffc12b494be2d0bf2caa57072 Mon Sep 17 00:00:00 2001 From: YvesCesar Date: Mon, 31 Aug 2026 11:21:33 -0400 Subject: [PATCH 6/7] docs: drop the tmp cleanup note from the docker section Signed-off-by: YvesCesar --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 11bbb71..8bd94f9 100644 --- a/README.md +++ b/README.md @@ -88,13 +88,5 @@ To sign a PDF end to end. It downloads the JRE and the JSignPdf jar into `tmp/` docker compose run --rm php php example/index.php ``` -The cached runtime left in `tmp/` makes `JavaRuntimeServiceTest` fail. Remove the whole directory -before running the suite again, not only the version marker, otherwise the next download cannot -overwrite the extracted JRE: - -```bash -rm -rf tmp/java tmp/jsignpdf -``` - ## Credits - [Jeidison Farias](https://github.com/jeidison) From 7ad3c915468eb99dbad51275bc9cad39874cc6cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yves=20C=C3=A9sar=20Amorim=20de=20Azevedo?= <48072419+YvesCesar@users.noreply.github.com> Date: Tue, 1 Sep 2026 14:30:59 -0400 Subject: [PATCH 7/7] Update README.md Co-authored-by: Vitor Mattos --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8bd94f9..76338a9 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ docker compose run --rm php composer run cs:check # cs:fix to apply the format docker compose run --rm php composer run psalm ``` +### Usage example + To sign a PDF end to end. It downloads the JRE and the JSignPdf jar into `tmp/` on the first run: ```bash