How to run Playwright in a Dockerized Node Azure Functions App locally? [WSL2]

Brandon 1 Reputation point
2021-11-02T03:06:02.85+00:00

Is there an example Dockerfile of how to run Playwright inside of a node(typescript) functions app on WSL2?
I've got it working on Azure using remote build and locally without using Docker.

System: Win 11, WSL2, Ubuntu-20.04

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Pramod Valavala 20,656 Reputation points Microsoft Employee Moderator
    2021-11-23T14:20:27.603+00:00

    @Brandon I'm unsure of a ready-to-use image for this. But building your own container shouldn't be that complex. You would just pick an Azure Functions Node Image that you need and extend it with playwright. You don't have to add NodeJS again since it would already be available in the Azure Functions container. I haven't given it a go, but I suppose a dockerfile like the following should do

       FROM mcr.microsoft.com/azure-functions/node:3.0  
         
       # Add Playwright  
         
       ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright  
         
       # 1. Add tip-of-tree Playwright package to install its browsers.  
       #    The package should be built beforehand from tip-of-tree Playwright.  
       COPY ./playwright-core.tar.gz /tmp/playwright-core.tar.gz  
         
       # 2. Bake in browsers & deps.  
       #    Browsers will be downloaded in `/ms-playwright`.  
       #    Note: make sure to set 777 to the registry so that any user can access  
       #    registry.  
       RUN mkdir /ms-playwright && \  
           mkdir /ms-playwright-agent && \  
           cd /ms-playwright-agent && npm init -y && \  
           npm i /tmp/playwright-core.tar.gz && \  
           npx playwright install --with-deps && rm -rf /var/lib/apt/lists/* && \  
           rm /tmp/playwright-core.tar.gz && \  
           rm -rf /ms-playwright-agent && \  
           chmod -R 777 /ms-playwright  
    

    The container built from the above dockerfile would be the one you use instead of the official container in the dockerfile that you use to build your azure function project.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.