@salvuccicarlos Finally got around to trying puppeteer in Docker, and I was able to get it to work easily.
Here are the steps that might help others too. You will still have to run npm install pup...
in terminal or add in packages and re-install packages from bottom toolbar first.
Although you can move that step to Dockerfile described below, I have not done that to keep the first part same as other Wappler NodeJS Extension installations.
- There is a file called
Dockerfile
for each Docker based target. This file can be found in.wappler/targets/{{target_name}}/web/Dockerfile
- This file usually looks like this for a local development server:
FROM wapplerio/node-14
ENV NODE_ENV development
WORKDIR /opt/node_app
COPY package.json .
RUN npm install --no-optional
CMD [ "nodemon", "--legacy-watch", "./index.js" ]
- To allow puppeteer to find Chromium, we need to install it at the time of Docker image creation, which is done using the file above. As per the library's documentation, I add a few lines of code and this is what my Dockerfile looks like now:
FROM wapplerio/node-14
ENV NODE_ENV development
WORKDIR /opt/node_app
COPY package.json .
RUN npm install --no-optional
RUN apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
CMD [ "nodemon", "--legacy-watch", "./index.js" ]
- Save this, and click DEPLOY in the bottom toolbar to re-deploy the image.
- In the logs, you should see that it will take a bit more time than usual during deployment, since it now also runs additional RUN command for Chromium.
You will have to modify this Dockerfile file for each Docker-type target in Wappler.
I have tested this on Digital Ocean based setup Wappler provides. So I can now generate PDFs on local as well as remote dockers.