Puppeteer-pdf running on Gigalixir - anyone?

Hi
I wonder if anyone has successfully deployed puppeteer-pdf to Gigalixir? I’m unable to understand how to make headless chrome available on the server.
The error I keep getting is :invalid_exec_path. I had a look at the elixir-pdf-generator and it looks like it’s a known trip hazard. But the discussions / solutions there didn’t help me :frowning:
I’ve progressed(?) to deploying the https://github.com/minted/heroku-buildpack-chrome-headless buildpack. This worked, to my great surprise (as in the deploy didn’t fall over), unlike https://github.com/heroku/heroku-buildpack-google-chrome, but I’m still facing the same error.
I feel sure someone has cracked this particular nut. I would really appreciate the recipe because I’ve come to a dead end and will have to use a different library for pdf conversion that doesn’t use chrome.
Thanks in advance,

remote: -----> Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
remote: Detected buildpacks: /tmp/buildpacks/000_buildpack-multi elixir
remote: -----> Multipack app detected
remote: =====> Downloading Buildpack: https://github.com/minted/heroku-buildpack-chrome-headless
remote: =====> Detected Framework: Headless Chrome
remote: -----> Fetching Chrome binaries at https://s3.amazonaws.com/minted-wedding-websites-deployment/chrome-headless
remote: -----> Moving Chrome binaries to /tmp/build/vendor/chrome/bin
remote: -----> exporting PATH

Just checking my emails and have had a reply from the folks at Gigalixir:
“Hey Jason, that’s a tough one. If it relies on global packages, maybe your best bet is to install them on startup with a .profile.d script. I’ve never tried this so I can’t say for sure if it’ll work, but aside from that the only other option is to basically not rely on global packages somehow.”

One thing you should try is going back to mix mode if you’re using releases. Most buildpacks were built with Heroku in mind, which is exactly what mix mode basically is. Releases are different because they don’t bundle up the entire /app folder and instead rely on you to specify exactly what you want bundle into the tarball.
See https://gigalixir.readthedocs.io/en/latest/modify-app/index.html#how-do-i-switch-to-mix-mode
Also, if you really want to stick with releases, you try and figure out which directories and files are required to be bundled and add them in with overlays. See https://hexdocs.pm/mix/Mix.Tasks.Release.html#module-overlays

Yes, I did that yesterday evening when reading about build packs in the Gigalixir manual.
Last night my bedtime research discovered ChromicPdf. This seems to have been built in response to these challenges. Today’s task is to switch to this package and go for a test drive.
Many thanks for the pointers :+1:

Hi, @shotleybuilder.

I know this thread is a little bit old, but I was having the same problem as you yesterday, and this is how I fixed it:

In rel/env.ssh.eex (if you don’t have it, run mix release.initon your project), add the following lines.

#!/bin/sh

apt-get update
apt-get install -y --fix-missing libxss1 lsof libasound2 libnss3 

curl -sL https://deb.nodesource.com/setup_current.x | bash -
apt-get install -y nodejs

npm i puppeteer@^1.7.0

export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true

npm i puppeteer-pdf -g

cp -R /app/node_modules/puppeteer/.local-chromium/ /usr/lib/node_modules/puppeteer-pdf/node_modules/puppeteer/

npm uninstall puppeteer@^1.7.0

The problem happens because the puppeteer_pdfneeds a global installation of puppeteer-pdf package. It attempts to download the Chromium on that installation, but there is an error regarding permission and everything fails.

The solution is to download the Chromium locally and then copy it to the global package folder. The export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD skips the Chromium download when installing puppeteer-pdf.

I hope it helps you.

2 Likes