Error when calling executing Puppeteer

i have this bookmarking app running on rails 7 ruby 3.1.2 and i want to take screenshots. i have added puppeteer to my package.json with grover to my Gemfile and it is working just fine locally but when i deploy to fly i get this error

Could not find Chromium (rev. 1083080). This can occur if either 1. you did not perform an installation before running the script (e.g. npm install) or 2. your cache path is incorrectly configured (which is: /root/.cache/puppeteer). For (2), check out our guide on configuring puppeteer at Configuration | Puppeteer.

following instructions from other posts in the forum i updated my Dockerfile but i am still getting errors

FROM zenika/alpine-chrome:with-node

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 1
ENV PUPPETEER_EXECUTABLE_PATH /usr/bin/chromium-browser
WORKDIR /usr/src/app
COPY --chown=chrome package.json package-lock.json ./
RUN npm install
COPY --chown=chrome . ./
ENTRYPOINT ["tini", "--"]
CMD ["node", "/usr/src/app/src/pdf"]

before the # install deployment packages section gives me the same error as above

adding this

# install deployment packages

FROM base

FROM node:slim

# Install Google Chrome Stable and fonts
# Note: this installs the necessary libs to make the browser work with Puppeteer.
RUN apt-get update && apt-get install gnupg wget -y && \
  wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
  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 google-chrome-stable -y --no-install-recommends && \
  rm -rf /var/lib/apt/lists/*

and
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
at the top of Dockerfile gives me

 => ERROR [stage-5  9/10] RUN chmod +x /app/bin/* &&     sed -i 's/ruby.exe\r*/ruby/' /app/bin/* &&     sed -i 's/ruby\r*/ruby/' /app/bin/* &&     sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*    0.3s
------
 > [stage-5  9/10] RUN chmod +x /app/bin/* &&     sed -i 's/ruby.exe\r*/ruby/' /app/bin/* &&     sed -i 's/ruby\r*/ruby/' /app/bin/* &&     sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*:
#27 0.276 chmod: cannot access '/app/bin/*': No such file or directory
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c chmod +x /app/bin/* &&     sed -i 's/ruby.exe\r*/ruby/' /app/bin/* &&     sed -i 's/ruby\r*/ruby/' /app/bin/* &&     sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*]: exit code: 1

thanks
alex

I’ve opened Add support for Grover · Issue #9 · rubys/dockerfile-rails · GitHub

My goal is to get bringing a Rails project that depends only on reasonably popular gems to becoming a matter of:

fly launch
fly deploy

See Cut over to Rails Dockerfile Generator on Sunday 29 Jan 2023 for more details.

If there is some reason that gem won’t work for you, I’d like to hear why to see if there is something more I need to support. But even if that gem isn’t of interest of you, a byproduct of my work will be a demo that you can run and steal from.

I expect to get to that issue Monday or Tuesday.

thank you for taking the time to look into my issue :slight_smile:

the way i see it this is a problem with puppeteer not being present. as far as i understood grover gem uses puppeteer to generate screenshots.

Rails deciding to generate a Dockerfile as well must be like throwing a major spanner into the fly cogs :frowning:

The setup with puppeteer and grover is working just fine locally but at the same time it doesn’t have to be those exact tools so if you are aware of a way to get screenshots that is already supported by fly i would love to hear about it.
also there is no time pressure, i am happy waiting couple of weeks for a resolution

i have previously used watir on VPS where installed literally every package imaginable but with the same disappointing outcome. the underlying problem is the same, in order to grab a screenshot those gems need to start up an actual browser session that will visit a given url.

As the saying goes, Good artists copy, Great artists steal :wink:

Here’s a demo you can run: dockerfile-rails/DEMO.md at main · rubys/dockerfile-rails · GitHub

Copy/paste that into a terminal where the current working directory is empty.

Steal from that Dockerfile or let the dockerfile-rails gem rewrite your Dockerfile; the call is yours.

thanks for putting the demo together! it works great :tada:
i ended up coping the commands for google-chrome and the ENVs for now :slight_smile:
i don’t really plan to use the Dockerfile from rails anyway. as you might have figured out by now i am not a big fan of Docker :slight_smile:

i am now able to get screenshot in my app for the first time since i first deployed it :champagne: