Skip to content

Commit bd91f89

Browse files
committed
feat(examples): Introduce Playwright (Chromium) example with Node
Introduce a Playwright (Chromium) example to be deployed on Unikraft Cloud with Node. It uses the `base-compat:latest` image. Add: * `Kraftfile`: build / run rules * `Dockerfile`: placeholder to extract the filesystem * `package.json`: NPM configuration file * `server.js`: implementation of Node server * `wrapper.sh`: helper script to start the Node server * `README.md`: document how to use * `.dockerignore` / `.gitignore`: ignore generated files Signed-off-by: Razvan Deaconescu <[email protected]>
1 parent 51dd652 commit bd91f89

File tree

9 files changed

+412
-0
lines changed

9 files changed

+412
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules/
2+
/.unikraft/
3+
/*.png

node-playwright-chromium/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules/
2+
/.unikraft/
3+
/*.png

node-playwright-chromium/Dockerfile

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
FROM debian:bookworm AS build
2+
3+
ARG NODE_VERSION=22.8.0
4+
5+
RUN set -xe; \
6+
apt-get -yqq update; \
7+
apt-get -yqq install \
8+
libcups2 \
9+
libnss3 \
10+
libatk1.0-0 \
11+
libnspr4 \
12+
libpango1.0-0 \
13+
libasound2 \
14+
libatspi2.0-0 \
15+
libxdamage1 \
16+
libatk-bridge2.0-0 \
17+
libxkbcommon0 \
18+
libdrm2 \
19+
libxcomposite1 \
20+
libxfixes3 \
21+
libxrandr2 \
22+
libgbm1; \
23+
apt-get -yqq install \
24+
ca-certificates \
25+
curl \
26+
build-essential \
27+
libssl-dev \
28+
git \
29+
;
30+
31+
RUN set -xe; \
32+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash; \
33+
. ~/.bashrc; \
34+
nvm install ${NODE_VERSION} \
35+
;
36+
37+
WORKDIR /app
38+
COPY package* .
39+
40+
RUN set -xe; \
41+
. ~/.bashrc; \
42+
npm install \
43+
;
44+
45+
RUN mkdir /home/tmp
46+
47+
FROM scratch
48+
49+
ARG NODE_VERSION=22.8.0
50+
51+
# Create required directories.
52+
COPY --from=build /home/tmp /tmp
53+
54+
# Chrome binary
55+
COPY --from=build /root/.cache/ms-playwright /root/.cache/ms-playwright
56+
57+
# Chrome libraries
58+
COPY --from=build /lib/x86_64-linux-gnu/libdl.so.2 \
59+
/lib/x86_64-linux-gnu/libpthread.so.0 \
60+
/lib/x86_64-linux-gnu/libgobject-2.0.so.0 \
61+
/lib/x86_64-linux-gnu/libglib-2.0.so.0 \
62+
/lib/x86_64-linux-gnu/libnss3.so \
63+
/lib/x86_64-linux-gnu/libnssutil3.so \
64+
/lib/x86_64-linux-gnu/libsmime3.so \
65+
/lib/x86_64-linux-gnu/libnspr4.so \
66+
/lib/x86_64-linux-gnu/libatk-1.0.so.0 \
67+
/lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0 \
68+
/lib/x86_64-linux-gnu/libcups.so.2 \
69+
/lib/x86_64-linux-gnu/libgio-2.0.so.0 \
70+
/lib/x86_64-linux-gnu/libdrm.so.2 \
71+
/lib/x86_64-linux-gnu/libdbus-1.so.3 \
72+
/lib/x86_64-linux-gnu/libexpat.so.1 \
73+
/lib/x86_64-linux-gnu/libxcb.so.1 \
74+
/lib/x86_64-linux-gnu/libxkbcommon.so.0 \
75+
/lib/x86_64-linux-gnu/libatspi.so.0 \
76+
/lib/x86_64-linux-gnu/libm.so.6 \
77+
/lib/x86_64-linux-gnu/libX11.so.6 \
78+
/lib/x86_64-linux-gnu/libXcomposite.so.1 \
79+
/lib/x86_64-linux-gnu/libXdamage.so.1 \
80+
/lib/x86_64-linux-gnu/libXext.so.6 \
81+
/lib/x86_64-linux-gnu/libXfixes.so.3 \
82+
/lib/x86_64-linux-gnu/libXrandr.so.2 \
83+
/lib/x86_64-linux-gnu/libgbm.so.1 \
84+
/lib/x86_64-linux-gnu/libpango-1.0.so.0 \
85+
/lib/x86_64-linux-gnu/libcairo.so.2 \
86+
/lib/x86_64-linux-gnu/libasound.so.2 \
87+
/lib/x86_64-linux-gnu/libgcc_s.so.1 \
88+
/lib/x86_64-linux-gnu/libc.so.6 \
89+
/lib/x86_64-linux-gnu/libffi.so.8 \
90+
/lib/x86_64-linux-gnu/libpcre2-8.so.0 \
91+
/lib/x86_64-linux-gnu/libplc4.so \
92+
/lib/x86_64-linux-gnu/libplds4.so \
93+
/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 \
94+
/lib/x86_64-linux-gnu/libavahi-common.so.3 \
95+
/lib/x86_64-linux-gnu/libavahi-client.so.3 \
96+
/lib/x86_64-linux-gnu/libgnutls.so.30 \
97+
/lib/x86_64-linux-gnu/libz.so.1 \
98+
/lib/x86_64-linux-gnu/libgmodule-2.0.so.0 \
99+
/lib/x86_64-linux-gnu/libmount.so.1 \
100+
/lib/x86_64-linux-gnu/libselinux.so.1 \
101+
/lib/x86_64-linux-gnu/libsystemd.so.0 \
102+
/lib/x86_64-linux-gnu/libXau.so.6 \
103+
/lib/x86_64-linux-gnu/libXdmcp.so.6 \
104+
/lib/x86_64-linux-gnu/libXi.so.6 \
105+
/lib/x86_64-linux-gnu/libXrender.so.1 \
106+
/lib/x86_64-linux-gnu/libwayland-server.so.0 \
107+
/lib/x86_64-linux-gnu/libfribidi.so.0 \
108+
/lib/x86_64-linux-gnu/libthai.so.0 \
109+
/lib/x86_64-linux-gnu/libharfbuzz.so.0 \
110+
/lib/x86_64-linux-gnu/libpixman-1.so.0 \
111+
/lib/x86_64-linux-gnu/libfontconfig.so.1 \
112+
/lib/x86_64-linux-gnu/libfreetype.so.6 \
113+
/lib/x86_64-linux-gnu/libpng16.so.16 \
114+
/lib/x86_64-linux-gnu/libxcb-shm.so.0 \
115+
/lib/x86_64-linux-gnu/libxcb-render.so.0 \
116+
/lib/x86_64-linux-gnu/libkrb5.so.3 \
117+
/lib/x86_64-linux-gnu/libk5crypto.so.3 \
118+
/lib/x86_64-linux-gnu/libcom_err.so.2 \
119+
/lib/x86_64-linux-gnu/libkrb5support.so.0 \
120+
/lib/x86_64-linux-gnu/libp11-kit.so.0 \
121+
/lib/x86_64-linux-gnu/libidn2.so.0 \
122+
/lib/x86_64-linux-gnu/libunistring.so.2 \
123+
/lib/x86_64-linux-gnu/libtasn1.so.6 \
124+
/lib/x86_64-linux-gnu/libnettle.so.8 \
125+
/lib/x86_64-linux-gnu/libhogweed.so.6 \
126+
/lib/x86_64-linux-gnu/libgmp.so.10 \
127+
/lib/x86_64-linux-gnu/libblkid.so.1 \
128+
/lib/x86_64-linux-gnu/libcap.so.2 \
129+
/lib/x86_64-linux-gnu/libgcrypt.so.20 \
130+
/lib/x86_64-linux-gnu/liblzma.so.5 \
131+
/lib/x86_64-linux-gnu/libzstd.so.1 \
132+
/lib/x86_64-linux-gnu/liblz4.so.1 \
133+
/lib/x86_64-linux-gnu/libbsd.so.0 \
134+
/lib/x86_64-linux-gnu/libdatrie.so.1 \
135+
/lib/x86_64-linux-gnu/libgraphite2.so.3 \
136+
/lib/x86_64-linux-gnu/libbrotlidec.so.1 \
137+
/lib/x86_64-linux-gnu/libkeyutils.so.1 \
138+
/lib/x86_64-linux-gnu/libresolv.so.2 \
139+
/lib/x86_64-linux-gnu/libgpg-error.so.0 \
140+
/lib/x86_64-linux-gnu/libmd.so.0 \
141+
/lib/x86_64-linux-gnu/libbrotlicommon.so.1 \
142+
/lib/x86_64-linux-gnu/libXcomposite.so.1 \
143+
/lib/x86_64-linux-gnu/libXfixes.so.3 \
144+
/lib/x86_64-linux-gnu/libXrandr.so.2 \
145+
/lib/x86_64-linux-gnu/libgbm.so.1 \
146+
/lib/x86_64-linux-gnu/
147+
148+
# Other Chrome-related libraries
149+
COPY --from=build /usr/lib/x86_64-linux-gnu/libsoftokn3.so \
150+
/usr/lib/x86_64-linux-gnu/libsqlite3.so.0 \
151+
/usr/lib/x86_64-linux-gnu/libudev.so.1 \
152+
/usr/lib/x86_64-linux-gnu/libfreebl3.so \
153+
/usr/lib/x86_64-linux-gnu/libfreeblpriv3.so \
154+
/usr/lib/x86_64-linux-gnu/libudev.so.1.7.5 \
155+
/usr/lib/x86_64-linux-gnu/
156+
157+
# Node binary
158+
COPY --from=build /root/.nvm/versions/node/v${NODE_VERSION}/bin/node /usr/bin/node
159+
160+
# System libraries
161+
COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 \
162+
/lib/x86_64-linux-gnu/libz.so.1 \
163+
/lib/x86_64-linux-gnu/libbrotlidec.so.1 \
164+
/lib/x86_64-linux-gnu/libbrotlienc.so.1 \
165+
/lib/x86_64-linux-gnu/libnghttp2.so.14 \
166+
/lib/x86_64-linux-gnu/libcrypto.so.3 \
167+
/lib/x86_64-linux-gnu/libssl.so.3 \
168+
/lib/x86_64-linux-gnu/libicui18n.so.72 \
169+
/lib/x86_64-linux-gnu/libicuuc.so.72 \
170+
/lib/x86_64-linux-gnu/libstdc++.so.6 \
171+
/lib/x86_64-linux-gnu/libm.so.6 \
172+
/lib/x86_64-linux-gnu/libgcc_s.so.1 \
173+
/lib/x86_64-linux-gnu/libpthread.so.0 \
174+
/lib/x86_64-linux-gnu/libdl.so.2 \
175+
/lib/x86_64-linux-gnu/libbrotlicommon.so.1 \
176+
/lib/x86_64-linux-gnu/libicudata.so.72 \
177+
/lib/x86_64-linux-gnu/librt.so.1 \
178+
/lib/x86_64-linux-gnu/libtinfo.so.6 \
179+
/lib/x86_64-linux-gnu/libproc2.so.0 \
180+
/lib/x86_64-linux-gnu/
181+
182+
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
183+
COPY --from=build /etc/ld.so.cache /etc/ld.so.cache
184+
185+
# Dbus and system files
186+
COPY --from=build /usr/lib/dbus-1.0 /usr/lib/dbus-1.0
187+
COPY --from=build /usr/lib/systemd /usr/lib/systemd
188+
COPY --from=build /usr/lib/tmpfiles.d /usr/lib/tmpfiles.d
189+
COPY --from=build /usr/lib/sysusers.d /usr/lib/sysusers.d
190+
COPY --from=build /usr/lib/sysctl.d /usr/lib/sysctl.d
191+
192+
# Data files
193+
COPY --from=build /usr/share/fonts /usr/share/fonts
194+
195+
COPY --from=build /run /run
196+
197+
# Distro definition
198+
COPY --from=build /etc/os-release /etc/os-release
199+
COPY --from=build /usr/lib/os-release /usr/lib/os-release
200+
201+
# Configuration files
202+
COPY --from=build /etc /etc
203+
204+
# Node modules, including Puppeteer and application
205+
COPY --from=build /app /app
206+
207+
# Required by wrapper script
208+
COPY --from=build /bin/sh /bin/sh
209+
210+
# Required by Playwright / Chrome
211+
COPY --from=build /usr/bin/ps /usr/bin/ps
212+
213+
# Actual server implementation
214+
COPY ./server.js /app/server.js
215+
216+
# Wrapper script set environment
217+
COPY ./wrapper.sh /usr/bin/wrapper.sh

node-playwright-chromium/Kraftfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
spec: v0.6
2+
3+
runtime: base-compat:latest
4+
5+
labels:
6+
cloud.unikraft.v1.instances/scale_to_zero.policy: "idle"
7+
cloud.unikraft.v1.instances/scale_to_zero.stateful: "true"
8+
cloud.unikraft.v1.instances/scale_to_zero.cooldown_time_ms: 1000
9+
10+
rootfs: ./Dockerfile
11+
12+
cmd: ["/usr/bin/wrapper.sh", "/usr/bin/node", "/app/server.js"]

node-playwright-chromium/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Playwright (Chromium) with Node.js on Unikraft Cloud
2+
3+
[Playwright](https://playwright.dev/) is a framework for web testing and Automation.
4+
5+
To run Playwright (Chromium) with Node.js on Unikraft Cloud, first [install the `kraft` CLI tool](https://unikraft.org/docs/cli).
6+
Then clone this repository and `cd` into this directory, and invoke:
7+
8+
```console
9+
kraft cloud deploy -M 4096 -p 443:8080 .
10+
```
11+
12+
The command will deploy the files in the current directory.
13+
It results in the creation of a remote web-based service for creating PNG screenshots of remote pages.
14+
15+
Use the `?page=<REMOTE_URL>` to point the service to the remote page to screenshot.
16+
Query the service using commands such as:
17+
18+
```console
19+
curl https://<NAME>.<METRO>.kraft.host/?page=https://google.com -o ss-google.png
20+
curl https://<NAME>.<METRO>.kraft.host/?page=https://bing.com -o ss-bing.png
21+
```
22+
23+
## Learn more
24+
25+
- [Playwright's Documentation](https://playwright.dev/docs/intro)
26+
- [Unikraft Cloud's Documentation](https://unikraft.cloud/docs/)
27+
- [Building `Dockerfile` Images with `Buildkit`](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)

node-playwright-chromium/package-lock.json

Lines changed: 73 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node-playwright-chromium/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"playwright": "^1.47.0",
4+
"playwright-chromium": "^1.47.0"
5+
}
6+
}

0 commit comments

Comments
 (0)