Skip to content

Latest commit

Β 

History

History

README.md

Puppeteer HTTP Server

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 CLI. Use the unikraft CLI or the legacy kraft CLI. You need a BuildKit builder. The easiest way to get one is via Docker. Alternatively, you can also directly set up and use BuildKit, see the quick start.

    Note: The unikraft CLI is the current standard, while kraft is the legacy version. Choose one of the CLIs below and only run the commands associated with it for the rest of this guide.

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

    git clone https://github.com/unikraft-cloud/examples
    cd examples/httpserver-node-express-puppeteer/

Make sure to log into Unikraft Cloud and pick a metro close to you. This guide uses fra (Frankfurt, πŸ‡©πŸ‡ͺ):

Using the unikraft CLI (Recommended)

unikraft login

or

Using the legacy kraft CLI

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

The UKC_TOKEN and UKC_METRO environment variables are only supported by the legacy CLI.

Note: A Puppeteer instance on Unikraft Cloud requires 4GB to run. Request an increase in the instance memory quota when you need more memory.

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

Using the unikraft CLI (Recommended)

unikraft build . --output <my-org>/httpserver-node-express-puppeteer:latest
unikraft run --metro fra \
  -m 4G \
  -p 443:3000/tls+http \
  --scale-to-zero policy=idle,cooldown-time=1000,stateful=true \
  --image <my-org>/httpserver-node-express-puppeteer:latest

or

Using the legacy kraft CLI

kraft cloud deploy \
  -M 4Gi \
  -p 443:3000/tls+http \
  --scale-to-zero idle \
  --scale-to-zero-stateful \
  --scale-to-zero-cooldown 1s \
  .

The output shows the instance address and other details:

Using the unikraft CLI (Recommended)

metro:        fra
name:         httpserver-node-express-puppeteer-7afg3
uuid:         7bb479d7-5b3e-444f-b07c-eae4da6f57cc
state:        starting
image:        <my-org>/httpserver-node-express-puppeteer
resources:
  memory:     4096MiB
  vcpus:      1
service:
  uuid:       996b9cc1-5a51-e707-d443-5c98ea86ded8
  name:       little-snow-7qwu6vv5
  domains:
  - fqdn:     little-snow-7qwu6vv5.fra.unikraft.app
networks:
- uuid:       034fa25e-9154-7842-ccdd-289256cc7a17
  private-ip: 10.0.3.1
  mac:        12:b0:8f:3c:f5:16
timestamps:
  created:    just now

or

Using the legacy kraft CLI

[●] Deployed successfully!
 β”‚
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ name: httpserver-node-express-puppeteer-7afg3
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ uuid: 7bb479d7-5b3e-444f-b07c-eae4da6f57cc
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€ metro: https://api.fra.unikraft.cloud/v1
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€ state: starting
 β”œβ”€β”€β”€β”€β”€β”€β”€ domain: https://nameless-fog-0tvh1uov.fra.unikraft.app
 β”œβ”€β”€β”€β”€β”€β”€β”€β”€ image: oci://unikraft.io/<my-org>/httpserver-node-express-puppeteer@sha256:78d0b180161c876f17d05116b93011ddcd44c76758d6fa0359f05938e67cea65
 β”œβ”€β”€β”€β”€β”€β”€β”€ memory: 4096 MiB
 β”œβ”€β”€β”€β”€β”€β”€ service: little-snow-7qwu6vv5
 β”œβ”€ private fqdn: httpserver-node-express-puppeteer-7afg3.internal
 └─── private ip: 10.0.3.1

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

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

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

You can list information about the instance by running:

Using the unikraft CLI (Recommended)

unikraft instances list
METRO  NAME                                     STATE    IMAGE                                       ARGS  MEMORY   VCPUS  FQDN                                    CREATED
fra    httpserver-node-express-puppeteer-7afg3  running  <my-org>/httpserver-node-express-puppeteer        4096MiB  1      nameless-fog-0tvh1uov.fra.unikraft.app  2 minutes ago

or

Using the legacy kraft CLI

kraft cloud instance list
NAME                                     FQDN                                    STATE    STATUS       IMAGE                                                              MEMORY   VCPUS  ARGS  BOOT TIME
httpserver-node-express-puppeteer-7afg3  nameless-fog-0tvh1uov.fra.unikraft.app  running  since 6mins  oci://unikraft.io/<my-org>/httpserver-node-express-puppeteer@s...  4.0 GiB  1            15.27 ms

When done, you can remove the instance:

Using the unikraft CLI (Recommended)

unikraft instances delete httpserver-node-express-puppeteer-7afg3

or

Using the legacy kraft CLI

kraft cloud instance remove httpserver-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 means updating the service, such as adding new functionalities provided by Puppeteer. You can update the service to provide a REST-like interface.

Learn more

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

kraft cloud --help

Or visit the CLI Reference or the legacy CLI Reference.