Zudoku
Guides

Puppeteer

This guide shows you how to use Puppeteer, a Node.js library which provides a high-level API to control browsers, including the option to run them headless (no UI).

To run it, follow these steps:

  1. Install the kraft CLI tool and a container runtime engine, e.g. Docker.

  2. Clone the examples repository and cd into the examples/node-express-puppeteer/ directory:

TerminalCode
git clone https://github.com/kraftcloud/examples cd examples/node-express-puppeteer/

Make sure to log into Unikraft Cloud by setting your token and a metro close to you. We use fra0 (Frankfurt, ๐Ÿ‡ฉ๐Ÿ‡ช) in this guide:

TerminalCode
# Set Unikraft Cloud access token export UKC_TOKEN=token # Set metro to Frankfurt, DE export UKC_METRO=fra0

A Puppeteer instance on Unikraft Cloud requires 4GB to run. You may be required to request increasing the instance memory quota.

When done, invoke the following command to deploy this application on Unikraft Cloud:

TerminalCode
kraft cloud deploy -p 443:3000 -M 4096 .

The output shows the instance URL and other details:

TerminalCode
[โ—] Deployed successfully! โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ name: node-express-puppeteer-7afg3 โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ uuid: 7bb479d7-5b3e-444f-b07c-eae4da6f57cc โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ state: starting โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ domain: https://nameless-fog-0tvh1uov.fra0.kraft.host โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ image: node-express-puppeteer@sha256:78d0b180161c876f17d05116b93011ddcd44c76758d6fa0359f05938e67cea65 โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ memory: 4096 MiB โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€ service: little-snow-7qwu6vv5 โ”œโ”€โ”€ private fqdn: node-express-puppeteer-7afg3.internal โ”œโ”€โ”€โ”€โ”€ private ip: 172.16.3.1 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ args: /usr/bin/wrapper.sh /usr/bin/node /app/bin/www

In this case, the instance name is node-express-puppeteer-7afg3. They are different for each run.

Use a browser to access the landing page of the Puppeteer (that uses ExpressJS). The application and the landing page are part of this repository.

In the example run above the landing page is at https://nameless-fog-0tvh1uov.fra0.kraft.host You can use the landing page to generate the PDF version of a remote page.

At any point in time, you can list information about the instance:

TerminalCode
kraft cloud instance list node-express-puppeteer-7afg3
Code
NAME FQDN STATE STATUS IMAGE MEMORY ARGS BOOT TIME node-express-puppeteer-7afg3 node-express-puppeteer-7afg3.fra0.kraft.host running since 6mins node-express-puppeteer-7afg3@s... 4.0 GiB /usr/bin/wrapper.sh /usr/bin/n... 15.27 ms

When done, you can remove the instance:

TerminalCode
kraft cloud instance remove node-express-puppeteer-7afg3

Customize Your Deployment

The current deployment uses an ExpressJS service that uses the PDF generating functionality of Puppeteer. Customizing the deployment generally means updating the service, such as adding new functionalities provided by Puppeteer. The service itself can be updated to provided a REST-like interface.

Learn More

Use the --help option for detailed information on using Unikraft Cloud:

TerminalCode
kraft cloud --help

Or visit the CLI Reference.

Last modified on