Skip to content
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

Add Puppeteer Support (for Spatie/BrowserShot) #3245

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Expand Up @@ -223,6 +223,7 @@ WORKSPACE_INSTALL_DNSUTILS=true
WORKSPACE_XDEBUG_PORT=9000
WORKSPACE_VITE_PORT=5173
WORKSPACE_INSTALL_JDK=true
WORKSPACE_INSTALL_PUPPETEER=false

### PHP_FPM ###############################################

Expand Down Expand Up @@ -298,6 +299,7 @@ PHP_FPM_XDEBUG_PORT=9000
PHP_FPM_INSTALL_EVENT=false
PHP_FPM_INSTALL_DNSUTILS=true
PHP_FPM_INSTALL_POPPLER_UTILS=false
PHP_FPM_INSTALL_PUPPETEER=false

PHP_FPM_PUID=1000
PHP_FPM_PGID=1000
Expand Down
20 changes: 19 additions & 1 deletion DOCUMENTATION/content/documentation/index.md
Expand Up @@ -2096,7 +2096,7 @@ To install BBC Audio Waveform Image Generator in the Workspace container
<a name="Install-wkhtmltopdf"></a>
## Install wkhtmltopdf

[wkhtmltopdf](https://wkhtmltopdf.org/) is a utility for outputting a PDF from HTML
[wkhtmltopdf](https://wkhtmltopdf.org/) is a utility for outputting a PDF from HTML, but with limited support for modern CSS.

To install wkhtmltopdf in the Workspace container

Expand All @@ -2109,6 +2109,24 @@ To install wkhtmltopdf in the Workspace container
**PS** Don't forget to install the binary in the `php-fpm` container too by applying the same steps above to its container, otherwise the you'll get an error when running the `wkhtmltopdf` binary.


<br>
<a name="Install-puppeteer"></a>
## Install Puppeteer (for Browsershot)

[Browsershot](https://spatie.be/docs/browsershot/v2/introduction) is a utility for outputting a PDF from HTML, using Puppeteer to control a headless version of Google Chrome (hence it fully supports modern CSS).

To install Puppeteer (required for Browsershot) in the Workspace and PHP-FPM containers

1 - Open the `.env` file

2 - Search for the `WORKSPACE_INSTALL_PUPPETEER` and `PHP_FPM_INSTALL_PUPPETEER` arguments under their respective Container sections and set them to `true`

3 - Re-build the containers `docker-compose build workspace php-fpm`

You can now [install Browsershot](https://spatie.be/docs/browsershot/v2/installation-setup) in your application via `composer install spatie/browsershot`

**NB:** you will also need to [disable sandboxing](https://spatie.be/docs/browsershot/v2/miscellaneous-options/disable-sandboxing) to get it to work without error.


<br>
<a name="Install-GNU-Parallel"></a>
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Expand Up @@ -179,6 +179,7 @@ services:
- INSTALL_DNSUTILS=${WORKSPACE_INSTALL_DNSUTILS}
- INSTALL_POPPLER_UTILS=${WORKSPACE_INSTALL_POPPLER_UTILS}
- INSTALL_JDK=${WORKSPACE_INSTALL_JDK}
- INSTALL_PUPPETEER=${WORKSPACE_INSTALL_PUPPETEER}
- http_proxy
- https_proxy
- no_proxy
Expand Down Expand Up @@ -286,6 +287,7 @@ services:
- INSTALL_SSDB=${PHP_FPM_INSTALL_SSDB}
- INSTALL_TRADER=${PHP_FPM_INSTALL_TRADER}
- INSTALL_EVENT=${PHP_FPM_INSTALL_EVENT}
- INSTALL_PUPPETEER=${PHP_FPM_INSTALL_PUPPETEER}
- LEGACY_OPENSSL=${PHP_LEGACY_OPENSSL}
- DOWNGRADE_OPENSSL_TLS_AND_SECLEVEL=${PHP_DOWNGRADE_OPENSSL_TLS_AND_SECLEVEL}
- DOWNGRADE_OPENSSL_TLS_VERSION=${PHP_DOWNGRADE_OPENSSL_TLS_VERSION}
Expand Down
20 changes: 20 additions & 0 deletions php-fpm/Dockerfile
Expand Up @@ -1359,6 +1359,26 @@ RUN if [ ${INSTALL_DNSUTILS} = true ]; then \
apt-get update && apt-get install -y dnsutils \
;fi


###########################################################################
# PUPPETEER:
###########################################################################
USER root

ARG INSTALL_PUPPETEER=false
ARG NODE_MAJOR=20

RUN if [ ${INSTALL_PUPPETEER} = true ]; then \
apt-get update && apt-get install -y ca-certificates curl gnupg \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
&& apt-get update && apt-get install -y nodejs \
&& npm install --global puppeteer \
&& chmod -R o+rx ~/.cache/puppeteer \
;fi


###########################################################################
# Check PHP version:
###########################################################################
Expand Down
13 changes: 13 additions & 0 deletions workspace/Dockerfile
Expand Up @@ -1866,6 +1866,19 @@ RUN if [ ${INSTALL_JDK} = true ]; then \
&& update-ca-certificates -f \
;fi

###########################################################################
# PUPPETEER:
###########################################################################
USER laradock

ARG INSTALL_PUPPETEER=false
# Assumes Node is installed

RUN if [ ${INSTALL_PUPPETEER} = true ]; then \
npm install --global puppeteer \
&& chmod -R o+rx ~/.cache/puppeteer \
;fi

#
#--------------------------------------------------------------------------
# Final Touch
Expand Down