Skip to content

Commit ac3209c

Browse files
authored
feat(examples): Add Playwright (Chromium) on Node example (#122)
Reviewed-by: Cezar Craciunoiu <[email protected]> Approved-by: Cezar Craciunoiu <[email protected]>
2 parents a8260e8 + edea098 commit ac3209c

File tree

12 files changed

+577
-0
lines changed

12 files changed

+577
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: examples/node-playwright-chromium (stable)
2+
3+
on:
4+
workflow_dispatch:
5+
6+
push:
7+
branches: [main]
8+
paths:
9+
- '.github/workflows/example-node-playwright-chromium-stable.yaml'
10+
- 'node-playwright-chromium/**'
11+
- '!node-playwright-chromium/README.md'
12+
13+
pull_request:
14+
types: [opened, synchronize, reopened]
15+
branches: [main]
16+
paths:
17+
- '.github/workflows/example-node-playwright-chromium-stable.yaml'
18+
- 'node-playwright-chromium/**'
19+
- '!node-playwright-chromium/README.md'
20+
21+
schedule:
22+
- cron: '0 4 * * 1-6' # Every work day at 4AM
23+
24+
# Automatically cancel in-progress actions on the same branch
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
27+
cancel-in-progress: true
28+
29+
env:
30+
UKC_METRO: ${{ vars.UKC_METRO }}
31+
UKC_TOKEN: ${{ secrets.UKC_TOKEN }}
32+
KRAFTKIT_NO_CHECK_UPDATES: true
33+
KRAFTKIT_LOG_LEVEL: debug
34+
35+
jobs:
36+
integration:
37+
timeout-minutes: 60
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Test
44+
id: test
45+
uses: unikraft/kraftkit@staging
46+
continue-on-error: true
47+
with:
48+
run: |
49+
set -xe;
50+
51+
sudo apt-get -y update;
52+
sudo apt-get install -y --no-install-recommends file grep;
53+
54+
cd node-playwright-chromium;
55+
56+
kraft cloud deploy \
57+
--no-start \
58+
--memory 4096 \
59+
--name node-playwright-chromium-${GITHUB_RUN_ID} \
60+
--runtime index.unikraft.io/official-testing/base-compat:latest \
61+
--subdomain node-playwright-chromium-${GITHUB_RUN_ID} \
62+
-p 443:8080 \
63+
.;
64+
65+
# wait for the instance to start
66+
kraft cloud vm start -w 60s node-playwright-chromium-${GITHUB_RUN_ID};
67+
sleep 5;
68+
69+
curl -Lv --fail-with-body --max-time 10 --output screenshot.png "https://node-playwright-chromium-${GITHUB_RUN_ID}.${UKC_METRO}.kraft.host/?page=https://google.com"
70+
file screenshot.png | grep -q PNG
71+
72+
- name: Cleanup
73+
uses: unikraft/kraftkit@staging
74+
if: always()
75+
with:
76+
run: |
77+
set -xe;
78+
79+
kraft cloud vm stop node-playwright-chromium-${GITHUB_RUN_ID} || true;
80+
kraft cloud vm logs node-playwright-chromium-${GITHUB_RUN_ID} || true;
81+
kraft cloud vm rm node-playwright-chromium-${GITHUB_RUN_ID} || true;
82+
kraft cloud img rm index.unikraft.io/test/node-playwright-chromium-${GITHUB_RUN_ID} || true;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: examples/node-playwright-chromium (staging)
2+
3+
on:
4+
workflow_dispatch:
5+
6+
push:
7+
branches: [main]
8+
paths:
9+
- '.github/workflows/example-node-playwright-chromium-staging.yaml'
10+
- 'node-playwright-chromium/**'
11+
- '!node-playwright-chromium/README.md'
12+
13+
pull_request:
14+
types: [opened, synchronize, reopened]
15+
branches: [main]
16+
paths:
17+
- '.github/workflows/example-node-playwright-chromium-staging.yaml'
18+
- 'node-playwright-chromium/**'
19+
- '!node-playwright-chromium/README.md'
20+
21+
schedule:
22+
- cron: '0 4 * * 1-6' # Every work day at 4AM
23+
24+
# Automatically cancel in-progress actions on the same branch
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.ref }}
27+
cancel-in-progress: true
28+
29+
env:
30+
UKC_METRO: ${{ vars.UKC_METRO }}
31+
UKC_TOKEN: ${{ secrets.UKC_TOKEN }}
32+
KRAFTKIT_NO_CHECK_UPDATES: true
33+
KRAFTKIT_LOG_LEVEL: debug
34+
35+
jobs:
36+
integration:
37+
timeout-minutes: 60
38+
runs-on: ubuntu-latest
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Test
44+
id: test
45+
uses: unikraft/kraftkit@staging
46+
continue-on-error: true
47+
with:
48+
run: |
49+
set -xe;
50+
51+
sudo apt-get -y update;
52+
sudo apt-get install -y --no-install-recommends file grep;
53+
54+
cd node-playwright-chromium;
55+
56+
kraft cloud deploy \
57+
--no-start \
58+
--memory 4096 \
59+
--name node-playwright-chromium-${GITHUB_RUN_ID} \
60+
--runtime index.unikraft.io/official-testing/base-compat:latest \
61+
--subdomain node-playwright-chromium-${GITHUB_RUN_ID} \
62+
-p 443:8080 \
63+
.;
64+
65+
# wait for the instance to start
66+
kraft cloud vm start -w 60s node-playwright-chromium-${GITHUB_RUN_ID};
67+
sleep 5;
68+
69+
curl -Lv --fail-with-body --max-time 10 --output screenshot.png "https://node-playwright-chromium-${GITHUB_RUN_ID}.${UKC_METRO}.kraft.host/?page=https://google.com"
70+
file screenshot.png | grep -q PNG
71+
72+
- name: Cleanup
73+
uses: unikraft/kraftkit@staging
74+
if: always()
75+
with:
76+
run: |
77+
set -xe;
78+
79+
kraft cloud vm stop node-playwright-chromium-${GITHUB_RUN_ID} || true;
80+
kraft cloud vm logs node-playwright-chromium-${GITHUB_RUN_ID} || true;
81+
kraft cloud vm rm node-playwright-chromium-${GITHUB_RUN_ID} || true;
82+
kraft cloud img rm index.unikraft.io/test/node-playwright-chromium-${GITHUB_RUN_ID} || true;

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Example | Unikraft Cloud <br /> `stable` | Unikraft Cloud <br /> `staging` |
3434
[`node21-solidstart`](https://github.com/unikraft-cloud/examples/tree/main/node21-solid-start) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-node21-solidstart-stable.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-node21-solidstart-stable.yaml) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-node21-solidstart-staging.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-node21-solidstart-staging.yaml) |
3535
[`node21-remix`](https://github.com/unikraft-cloud/examples/tree/main/node21-remix) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-node21-remix-stable.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-node21-remix-stable.yaml) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-node21-remix-staging.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-node21-remix-staging.yaml) |
3636
[`node18-prisma`](https://github.com/unikraft-cloud/examples/tree/main/node18-prisma-rest-express) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-node18-prisma-stable.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-node18-prisma-stable.yaml) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-node18-prisma-staging.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-node18-prisma-staging.yaml) |
37+
[`node-playwright-chromium`](https://github.com/unikraft-cloud/examples/tree/main/node-playwright-chromium) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-node-playwright-chromium-stable.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-node-playwright-chromium-stable.yaml) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-node-playwright-chromium-staging.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-node-playwright-chromium-staging.yaml) |
3738
[`node-playwright-firefox`](https://github.com/unikraft-cloud/examples/tree/main/node-playwright-firefox) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-node-playwright-firefox-stable.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-node-playwright-firefox-stable.yaml) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-node-playwright-firefox-staging.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-node-playwright-firefox-staging.yaml) |
3839
[`postgres`](https://github.com/unikraft-cloud/examples/tree/main/postgres) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-postgres-stable.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-postgres-stable.yaml) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-postgres-staging.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-postgres-staging.yaml) |
3940
[`ruby3.2-rails`](https://github.com/unikraft-cloud/examples/tree/main/ruby3.2-rails) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-ruby3.2-rails-stable.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-ruby3.2-rails-stable.yaml) | [![](https://github.com/unikraft-cloud/examples/actions/workflows/example-ruby3.2-rails-staging.yaml/badge.svg)](https://github.com/unikraft-cloud/examples/actions/workflows/example-ruby3.2-rails-staging.yaml) |
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

0 commit comments

Comments
 (0)