Skip to content
Back

Chromium in Functions 1.4.3

  • 0
  • Functions
Kenny
20 Sep, 2023, 12:29

I've checked the openruntimes executor logs, appwrite worker function logs, and the appwrite logs but none give anything more detailed.

TL;DR
The user is discussing the installation of Chromium in the Functions 1.4.3 environment. They mention a route for keeping the function warm and inquire about the need to install Chrome for every cold start. The user later finds a solution by adding "--no-scripts" with npm install. They also encounter an issue when deploying to the cloud. Another user suggests adding an environment variable and provides a code snippet to install Chromium. There is a discussion about downloading and transferring the Chromium files. The user is able to download the APKs during the build but still needs to install them later. They are unsure if the download or installation is slow. The
Drake
28 Sep, 2023, 23:46

how'd you install chromium here?

Kenny
29 Sep, 2023, 00:22

I just installed it with node

Kenny
29 Sep, 2023, 00:23

It checks to see if it’s installed and if it isn’t it installs it.

Drake
29 Sep, 2023, 00:29

have you see this error?

qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or directory

Kenny
29 Sep, 2023, 00:35

I’ve not seen that with the way I’m currently installing chrome now. Seems to work pretty reliably. Though the first execution after deploying or after it’s gone to sleep takes about 20 seconds because it has to install chrome.

Drake
29 Sep, 2023, 00:36

so you were able to get it working?

Kenny
29 Sep, 2023, 00:36

Yes, not the way I’d like. I’d like to be able to get it installed in the build step but it just doesn’t seem possible for me to do.

Drake
29 Sep, 2023, 00:44

ya...do you know if it's the download that's slow or the install?

Drake
29 Sep, 2023, 00:58

ok...so i manged to download the apks during build...but they still need to be installed later

Kenny
29 Sep, 2023, 01:02

I can download the chromium files with apk add chromium but no matter what I do I can’t get them to move to the build folder. I have more luck locally where I can get it there but puppeteer and playwright cannot launch chrome successfully. On cloud I can’t even copy them over it just times out at around 50 seconds

Kenny
29 Sep, 2023, 01:02

I don’t think you can use the install command that comes with either playwright or puppeteer to install chrome. I think you have to use apk add

Drake
29 Sep, 2023, 01:04

add this as an env var:

TypeScript
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser

your build/install command will be:

TypeScript
apk update && apk fetch chromium nss freetype harfbuzz ca-certificates ttf-freefont && npm i

instead of just npm i

Then, you can do the same thing as you were doing, but use the downloaded apks:

TypeScript
import { execSync } from 'node:child_process';
import puppeteer from 'puppeteer';

let installed = false

export default async (context) => {
  try {

    if (installed) {
      context.log('already installed chromium');
    } else {
      execSync('apk add /usr/local/server/src/function/*.apk');
      context.log('installed chromium');
      installed = true;
    }


    const browser = await puppeteer.launch({
      headless: true,
      args: [
        "--no-sandbox",
        "--headless",
        "--disable-gpu",
        "--disable-dev-shm-usage",
      ],
    });
    return context.res.send("loaded puppeteer");
  } catch (e) {
    return context.res.send(e.message);
  }
};
Drake
29 Sep, 2023, 01:06

maybe this will speed things up for you

Kenny
29 Sep, 2023, 01:09

Awesome! I’ll check it out tomorrow and let you know.

Kenny
29 Sep, 2023, 01:11

So installing on the build container will go over to the function running container? The biggest issue I had at the beginning is that they wouldn’t transfer over

Drake
29 Sep, 2023, 01:22

cold start of 10s

Kenny
29 Sep, 2023, 01:35

Cool beans! Thanks for looking into it

Kenny
29 Sep, 2023, 13:12

When trying to deploy this to cloud I get this

"commands": "apk update && apk fetch chromium nss freetype harfbuzz ca-certificates ttf-freefont && npm i && npm run build",

Kenny
29 Sep, 2023, 13:17

Nevermind, I added --no-scripts with npm install and it works now.

Kenny
29 Sep, 2023, 13:18

So does this mean it will have to install chrome from the node function for every cold start?

Kenny
29 Sep, 2023, 13:25

I had setup a route for keeping the function warm, do you think that's alright to do or is there abverse effects to never letting the function sleep

Drake
30 Sep, 2023, 00:16

yes, it still needs to install chrome, but it should be faster since it doesn't need to download the packages.

Drake
30 Sep, 2023, 00:17

ya that's fine

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more