Azure-Functions icon indicating copy to clipboard operation
Azure-Functions copied to clipboard

[Premium] NodeJS Azure Function works in Serverless/Consumption but not Premium

Open implodingduck opened this issue 3 years ago • 6 comments

Describe the bug When trying to use the NodeJS Playwright library in a Linux Premium Function the code fails with:

╔════════════════════════════════════════════════════════════╗
║ Host system is missing a few dependencies to run browsers. ║
║ Please install them with the following command:            ║
║                                                            ║
║     npx playwright install-deps                            ║
║                                                            ║
║ <3 Playwright Team                                         ║
╚════════════════════════════════════════════════════════════╝

Please note this works in a Serverless/Consumption Function just fine.

To Reproduce Steps to reproduce the behavior:

  1. Create a new Premium Linux NodeJS Function with a HttpTrigger
  2. Add the following dependencies { "playwright": "^1.17.1", "playwright-chromium": "^1.17.1" },
  3. Have code that uses playwright
const { chromium } = require('playwright-chromium');

module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    const browser = await chromium.launch();
    const page = await browser.newPage();
    await page.goto('http://whatsmyuseragent.org/');
    const screenshot = await page.screenshot({ fullPage: true });

    await browser.close();

    context.res = {
        headers: {
            "Content-Type": "image/png"
        },
        body: screenshot
    };
}
  1. See error

Expected behavior The expected behavior is that a screenshot will be returned like it does when using a Serverless/Consumption Function.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context It seems that there are some missing OS level dependencies that are preventing this from working: apt-get install -y
libasound2>=1.0.16
libatk-bridge2.0-0>=2.5.3
libatk1.0-0>=2.2.0
libatomic1>=4.8
libatspi2.0-0>=2.9.90
libavcodec58>=7:4.2
libavformat58>=7:4.1
libavutil56>=7:4.0
libcairo2>=1.6.0
libcups2>=1.7.0
libdbus-1-3>=1.9.14
libdrm2>=2.4.38
libevent-2.1-7>=2.1.8-stable
libflac8>=1.3.0
libgbm1>=17.1.0~rc2
libglib2.0-0>=2.39.4
libgtk-3-0>=3.19.12
libharfbuzz0b>=2.2.0
libjsoncpp24>=1.9.4
liblcms2-2>=2.2+git20110628
libminizip1>=1.1
libnspr4>=2:4.9-2~
libnss3>=2:3.22
libopenjp2-7>=2.2.0
libopus0>=1.1
libpango-1.0-0>=1.14.0
libpulse0>=0.99.1
libre2-9>=20201101+dfsg
libsnappy1v5>=1.1.8
libvpx6>=1.7.0
libwebpdemux2>=0.5.1
libwebpmux3>=0.6.1-2+b1
libxcomposite1>=1:0.4.5
libxdamage1>=1:1.1
libxext6
libxfixes3
libxml2>=2.7.4
libxrandr2
libxshmfence1
libxslt1.1>=1.1.25

implodingduck avatar Jan 11 '22 17:01 implodingduck

Hi @pragnagopa , Could you please look into this issue.

v-bbalaiagar avatar Feb 22 '22 10:02 v-bbalaiagar

@v-bbalaiagar @pragnagopa Do you have any update on this issue? We also run into that problem when trying to upgrade to premium plan.

lukasz-zoglowek avatar May 05 '22 12:05 lukasz-zoglowek

Hi @v-bbalaiagar @pragnagopa I am having the same issue. I initially deployed my function with playwright using the consumption plan and it works fine, but when I change the plan to Premium it stops working and says there are some missing dependencies. Will try using docker!

ManuelaGar avatar Jun 30 '22 15:06 ManuelaGar

Here is the docker file that works for my needs with azure premium plan and playwright chromium.

# To enable ssh & remote debugging on app service change the base image to the one below
FROM mcr.microsoft.com/azure-functions/node:4-node16-appservice

ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true \
    PLAYWRIGHT_BROWSERS_PATH=0

# Base list from https://github.com/ahmelsayed/chrome-headless-func-test/blob/master/Dockerfile
RUN apt-get update && \
    apt-get install -y gconf-service libasound2 libatk1.0-0 libatk-bridge2.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 \
    libnss3 lsb-release xdg-utils wget libgbm-dev

COPY . /home/site/wwwroot

RUN cd /home/site/wwwroot && \
    npm install  && \
    npx playwright install chromium && \
    npm run build

lukasz-zoglowek avatar Jun 30 '22 19:06 lukasz-zoglowek

Hi @lukasz-zoglowek, wow! Thanks for the file, I will try using it and let you know how it goes :)

ManuelaGar avatar Jun 30 '22 19:06 ManuelaGar

Hey @lukasz-zoglowek I just wanted to thank you for the Dockerfile. I just had to do some small changes and it worked perfectly. I also created a docker-compose.yaml to read all my environment variables. You helped a lot, thank you :)

I also used this tutorial: Create a function on Linux using a custom container and it helped a lot. Here is the docker-compose.yaml in case anyone in the future needs it.

version: '3.9'
services:
  <NAME_OF_YOUR_SERVICE>:
    container_name: <NAME_OF_YOUR_CONTAINER>
    image: <NAME_OF_YOUR_IMAGE>
    ports:
      - 7071:80
    env_file:
      - .env
    restart: always

ManuelaGar avatar Jul 01 '22 21:07 ManuelaGar