Skip to content

Commit

Permalink
Add Puppeteer Support (for Spatie/BrowserShot)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamShady committed Jul 22, 2022
1 parent a4c79b5 commit dc2dec7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.example
Expand Up @@ -204,6 +204,7 @@ WORKSPACE_INSTALL_TRADER=false
WORKSPACE_PROTOC_VERSION=latest
WORKSPACE_INSTALL_MEMCACHED=true
WORKSPACE_INSTALL_EVENT=false
WORKSPACE_INSTALL_PUPPETEER=false

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

Expand Down Expand Up @@ -276,6 +277,7 @@ PHP_FPM_INSTALL_DOCKER_CLIENT=false
PHP_FPM_DEFAULT_LOCALE=POSIX
PHP_FPM_XDEBUG_PORT=9003
PHP_FPM_INSTALL_EVENT=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 @@ -2003,7 +2003,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 @@ -2016,6 +2016,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 @@ -173,6 +173,7 @@ services:
- INSTALL_DOCKER_CLIENT=${WORKSPACE_INSTALL_DOCKER_CLIENT}
- INSTALL_MEMCACHED=${WORKSPACE_INSTALL_MEMCACHED}
- INSTALL_EVENT=${WORKSPACE_INSTALL_EVENT}
- INSTALL_PUPPETEER=${WORKSPACE_INSTALL_PUPPETEER}
- http_proxy
- https_proxy
- no_proxy
Expand Down Expand Up @@ -276,6 +277,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}
- DOWNGRADE_OPENSSL_TLS_AND_SECLEVEL=${PHP_DOWNGRADE_OPENSSL_TLS_AND_SECLEVEL}
- PUID=${PHP_FPM_PUID}
- PGID=${PHP_FPM_PGID}
Expand Down
15 changes: 15 additions & 0 deletions php-fpm/Dockerfile
Expand Up @@ -1268,6 +1268,21 @@ RUN set -eux; \
php -m | grep -q 'event' \
;fi

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

ARG INSTALL_PUPPETEER=false

RUN if [ ${INSTALL_PUPPETEER} = true ]; then \
curl -sL https://deb.nodesource.com/setup_current.x | bash \
&& apt-get install -y nodejs gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm-dev libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libnss3 xdg-utils wget \
&& npm install --global --unsafe-perm puppeteer \
&& chmod -R o+rx /usr/lib/node_modules/puppeteer/.local-chromium \
;fi


###########################################################################
# Check PHP version:
###########################################################################
Expand Down
15 changes: 15 additions & 0 deletions workspace/Dockerfile
Expand Up @@ -1771,6 +1771,21 @@ RUN set -eux; \
php -m | grep -q 'event' \
;fi

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

ARG INSTALL_PUPPETEER=false

RUN if [ ${INSTALL_PUPPETEER} = true ]; then \
apt-get update \
&& apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget \
&& npm install --global --unsafe-perm puppeteer \
&& find $NVM_DIR -type f -name node -exec ln -s {} /usr/local/bin/node \; \
&& NODE_MODS_DIR="$NVM_DIR/versions/node/$(node -v)/lib/node_modules" \
&& chmod -R o+rx $NODE_MODS_DIR/puppeteer/.local-chromium \
;fi


#
Expand Down

0 comments on commit dc2dec7

Please sign in to comment.