pwa-asset-generator icon indicating copy to clipboard operation
pwa-asset-generator copied to clipboard

Run in serverless environment

Open damianfrizzi opened this issue 4 years ago • 5 comments

Is your feature request related to a problem? Please describe. I would like to run pwa-asset-generator in a serverless environment. IIRC the current code does download the desired Chrome revision at run time. In order to work in a serverless environment the Chrome binary needs to be provided at build time.

Right now I get the following error message when trying to execute it on a AWS lambda (Vercel):

WARN	11:06:09 AM installer Chromium is not found in module folder, gonna have to download r818858 for you once 🤔
[Error: EROFS: read-only file system, mkdir '/var/task/node_modules/puppeteer-core/.local-chromium'] {
  errno: -30,
  code: 'EROFS',
  syscall: 'mkdir',
  path: '/var/task/node_modules/puppeteer-core/.local-chromium'
}

Describe the solution you'd like A way to provide the Chrome binary to the module without triggering the revision download:

import chrome from 'chrome-aws-lambda'

const launchOptions= {
  args: chrome.args,
  executablePath: await chrome.executablePath,
  headless: chrome.headless
}

await pwaAssetGenerator.generateImages(
  "https://raw.githubusercontent.com/onderceylan/pwa-asset-generator/HEAD/static/logo.png",
  "./tmp",
  {
    scrape: false,
    puppeteer: {
      launchOptions
    }
  }
)

Describe alternatives you've considered An alternative would be to use chrome-aws-lambda directly in the module. I think this isn't an option because of the built-in dynamic revision fetching.

damianfrizzi avatar May 19 '21 11:05 damianfrizzi

Thanks for your request @damianfrizzi. It would be nice to have this capability, I haven't tested it on serverless functions yet. Let me have a look at this.

onderceylan avatar Jul 13 '21 15:07 onderceylan

same problem for me in a serverless cloud function on Google Cloud: image

muellerdberlin avatar Jan 26 '22 13:01 muellerdberlin

Have you found a solution to this? I'm facing a similar issue running on Alpine and the revisions from puppeteer aren't compatible, the executablePath is hard-coded to point to one in node_modules/puppeteer I'm wondering if it would make sense to have an option for this

michaeltintiuc avatar Feb 17 '22 21:02 michaeltintiuc

No, didnt find a solution so far. @michaeltintiuc

muellerdberlin avatar Mar 29 '22 13:03 muellerdberlin

I've been able to fix this, albeit not in Google serverless env, but the basic idea might apply. Basically I've copied over the chromium binary into node_modules:

export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
export PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
export BROWSER=chromium
export PUPPETEER_CHROMIUM_REVISION=800071

yarn install

mkdir -p $PWD/node_modules/puppeteer-core/.local-chromium/linux-$PUPPETEER_CHROMIUM_REVISION/chrome-linux/
cp -rf $PUPPETEER_EXECUTABLE_PATH $PWD/node_modules/puppeteer-core/.local-chromium/linux-$PUPPETEER_CHROMIUM_REVISION/chrome-linux/chrome

michaeltintiuc avatar Mar 30 '22 15:03 michaeltintiuc