0

Problem: My app is deployed to Fly.io . I use puppeteer to grab search results from a few different websites. It works fine on my local machine, I've done tests etc, so there's no issues as far as the code goes. The issue is that because puppeteer cannot a) find chrome/chromium, b) does not already have the OS level dependencies needed for chrome/chromium, so it crashes each time and gives me the following error log.

 ---

2022-10-05T22:01:57.951 app[e6e93c7a] lax [info] Server received: black

2022-10-05T22:02:00.663 app[e6e93c7a] lax [info] Method: GET

2022-10-05T22:02:00.663 app[e6e93c7a] lax [info] Path: /api/tea/Assam

2022-10-05T22:02:00.663 app[e6e93c7a] lax [info] Body: {}

2022-10-05T22:02:00.663 app[e6e93c7a] lax [info] ---

2022-10-05T22:02:00.663 app[e6e93c7a] lax [info] Searching for: Assam

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] /workspace/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:299

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] reject(new Error([

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] ^

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] Error: Failed to launch the browser process!

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] /workspace/node_modules/puppeteer/.local-chromium/linux-1036745/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] at onClose (/workspace/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:299:20)

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] at Interface.<anonymous> (/workspace/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:287:24)

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] at Interface.emit (node:events:525:35)

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] at Interface.close (node:internal/readline/interface:536:10)

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] at Socket.onend (node:internal/readline/interface:262:10)

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] at Socket.emit (node:events:525:35)

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] at endReadableNT (node:internal/streams/readable:1359:12)

2022-10-05T22:02:00.680 app[e6e93c7a] lax [info] at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

So my next step is to figure out how to make a dockerfile so that I can install the dependencies, and then push that image to fly io. Here's my docker file

FROM zenika/alpine-chrome:101-with-node-16

RUN echo "I am alive!"

RUN apt-get update
RUN apt-get install -y libgbm-dev
RUN apt 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 
RUN apt-get install chromium-browser

COPY package*.json ./

USER root
RUN npm install

COPY . .

ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD='true'
ENV PUPPETEER_EXECUTABLE_PATH='/usr/bin/chromium-browser'

EXPOSE 8080
ENV PORT 8080

CMD ["/bin/sh", "setup.sh"]

I have tried several other different combinations, including just straight up copy/pasting the sample dockerfile from the puppeteer docker troubleshooting docs https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-in-docker But no dice. Each thing I try either gives back an error saying 'libncss.so' could not be found, or 'chrome'/'chromium-browser'/'google-chrome-stable' could not be found. I've experimented with different docker images, such as node:slim but none of them seem to work.

Here's my fly io config file for reference.

# fly.toml file generated for chayou on 2022-10-04T19:56:16-07:00

app = "chayou"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  builder = "heroku/buildpacks:20"
  dockerfile = "dockerfile"

[env]
  PORT = "8080"
  NO_COLOR=1

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

Is there something wrong with my dockerfile config? Maybe it's that fly.io is ignoring my dockerfile altogether and using some kind of other docker image behind the scenes? I press ctrl + shift + m in vscode and there are no blatant errors with my dockerfile. Whenever I deploy, I use this command

fly deploy --dockerfile dockerfile

30 deploys later and I am no where closer to finding out what is up.

Here's my current puppeteer launch setup

  const browser = await puppeteer.launch({
    args: [
      '--disable-gpu',
      '--disable-dev-shm-usage',
      '--disable-setuid-sandbox',
      '--no-first-run',
      '--no-sandbox',
      '--no-zygote',
      '--single-process',
  ]
  });
bluenaxela
  • 23
  • 5

0 Answers0