Skip to content

Commit 130651e

Browse files
committed
feat(library): Introduce Bun as library
Introduce Bun image (ELF Loader) for bincompat runs. Add `Kraftfile` to build for QMEU and Firecracker on x86_64 using initrd for volume support. The current build uses embedded initrd to build a single image consisting of both the kernel and the initial ramdisk. Add GitHub workflow to build and deploy the image. Add success badge in `README.md`. Signed-off-by: Razvan Deaconescu <razvand@unikraft.io>
1 parent af01be3 commit 130651e

File tree

8 files changed

+339
-0
lines changed

8 files changed

+339
-0
lines changed

.github/workflows/library-bun1.1.yaml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: library/bun1.1
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # Everyday at 12AM
6+
7+
push:
8+
branches: [main]
9+
paths:
10+
- 'library/bun/1.1/**'
11+
- '.github/workflows/library-bun1.1.yaml'
12+
- '!library/bun/1.1/README.md'
13+
14+
pull_request:
15+
types: [opened, synchronize, reopened]
16+
branches: [main]
17+
paths:
18+
- 'library/bun/1.1/**'
19+
- '.github/workflows/library-bun1.1.yaml'
20+
- '!library/bun/1.1/README.md'
21+
22+
jobs:
23+
build:
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
include:
28+
- plat: qemu
29+
arch: x86_64
30+
- plat: fc
31+
arch: x86_64
32+
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- uses: actions/checkout@v3
37+
38+
- name: Build bun1.1
39+
uses: unikraft/kraftkit@staging
40+
with:
41+
loglevel: debug
42+
workdir: library/bun1.1
43+
runtimedir: /github/workspace/.kraftkit
44+
plat: ${{ matrix.plat }}
45+
arch: ${{ matrix.arch }}
46+
push: false
47+
output: oci://index.unikraft.io/unikraft.org/bun:1.1
48+
49+
- name: Archive OCI digests
50+
uses: actions/upload-artifact@v3
51+
with:
52+
name: oci-digests-${{ matrix.arch }}-${{ matrix.plat }}
53+
path: ${{ github.workspace }}/.kraftkit/oci/digests
54+
if-no-files-found: error
55+
56+
push:
57+
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }}
58+
needs: [ build ]
59+
runs-on: ubuntu-latest
60+
61+
steps:
62+
- uses: actions/checkout@v3
63+
64+
- name: Login to OCI registry
65+
uses: docker/login-action@v2
66+
with:
67+
registry: index.unikraft.io
68+
username: ${{ secrets.REG_USERNAME }}
69+
password: ${{ secrets.REG_TOKEN }}
70+
71+
- name: Retrieve, merge and push OCI digests
72+
uses: ./.github/actions/merge-oci-digests
73+
with:
74+
name: index.unikraft.io/unikraft.org/bun:1.1
75+
push: true

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ kraft pkg ls --apps --update
4040
| Status | Image |
4141
|-|-|
4242
| [![](https://github.com/unikraft/catalog/actions/workflows/library-base.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-base.yaml) | [`unikraft.org/base:latest`](library/base) |
43+
| [![](https://github.com/unikraft/catalog/actions/workflows/library-bun1.1.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-bun1.1.yaml) | [`unikraft.org/bun:1.1`](library/bun/1.1) |
4344
| [![](https://github.com/unikraft/catalog/actions/workflows/library-caddy2.7.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-caddy2.7.yaml) | [`unikraft.org/caddy:2.7`](library/caddy/2.7) |
4445
| [![](https://github.com/unikraft/catalog/actions/workflows/library-findtime.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-findtime.yaml) | [`unikraft.org/findtime`](library/findtime) |
4546
| [![](https://github.com/unikraft/catalog/actions/workflows/library-grafana10.2.yaml/badge.svg)](https://github.com/unikraft/catalog/actions/workflows/library-grafana10.2.yaml) | [`unikraft.org/grafana:10.2`](library/grafana/10.2) |

library/bun/1.1/.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/Makefile.uk
2+
/.unikraft/
3+
/.config*

library/bun/1.1/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/Makefile.uk
2+
/.unikraft/
3+
/.config*

library/bun/1.1/Dockerfile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FROM oven/bun:1.1.20-debian AS bun
2+
3+
RUN set -xe; \
4+
mv /usr/local/bin/bun /usr/bin/bun; \
5+
mkdir /self; \
6+
ln -sfn /usr/bin/bun /self/exe
7+
8+
FROM alpine:3 AS sys
9+
10+
RUN set -xe; \
11+
mkdir -p /target/etc; \
12+
mkdir -p /blank; \
13+
apk --no-cache add \
14+
ca-certificates \
15+
tzdata \
16+
; \
17+
update-ca-certificates; \
18+
ln -sf ../usr/share/zoneinfo/Etc/UTC /target/etc/localtime; \
19+
echo "Etc/UTC" > /target/etc/timezone;
20+
21+
FROM scratch
22+
23+
COPY --from=bun /self /proc/self
24+
COPY --from=bun /usr/bin/bun /usr/bin/bun
25+
26+
COPY --from=bun /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
27+
COPY --from=bun /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so.2
28+
COPY --from=bun /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
29+
COPY --from=bun /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libpthread.so.0
30+
COPY --from=bun /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
31+
32+
COPY --from=sys /target/etc /etc
33+
COPY --from=sys /usr/share/zoneinfo/Etc/UTC /usr/share/zoneinfo/Etc/UTC
34+
COPY --from=sys /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
35+
COPY --from=sys /blank /tmp
36+
37+
COPY ./server.ts /usr/src/server.ts

library/bun/1.1/Kraftfile

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
spec: v0.6
2+
3+
name: bun
4+
5+
rootfs: ./Dockerfile
6+
7+
cmd: ["/usr/bin/bun", "run", "/usr/src/server.ts"]
8+
9+
template:
10+
source: https://github.com/unikraft/app-elfloader.git
11+
version: staging
12+
13+
unikraft:
14+
source: https://github.com/unikraft/unikraft.git
15+
version: staging
16+
kconfig:
17+
# Configurations options for app-elfloader
18+
# (they can't be part of the template atm)
19+
CONFIG_APPELFLOADER_ARCH_PRCTL: 'y'
20+
CONFIG_APPELFLOADER_BRK: 'y'
21+
CONFIG_APPELFLOADER_CUSTOMAPPNAME: 'y'
22+
CONFIG_APPELFLOADER_STACK_NBPAGES: 128
23+
CONFIG_APPELFLOADER_VFSEXEC_EXECBIT: 'n'
24+
CONFIG_APPELFLOADER_VFSEXEC: 'y'
25+
CONFIG_APPELFLOADER_AUTOGEN_REPLACEEXIST: 'y'
26+
# Unikraft options
27+
CONFIG_HAVE_PAGING_DIRECTMAP: 'y'
28+
CONFIG_HAVE_PAGING: 'y'
29+
CONFIG_I8042: 'y'
30+
CONFIG_LIBDEVFS_AUTOMOUNT: 'y'
31+
CONFIG_LIBDEVFS_DEV_NULL: 'y'
32+
CONFIG_LIBDEVFS_DEV_STDOUT: 'y'
33+
CONFIG_LIBDEVFS_DEV_ZERO: 'y'
34+
CONFIG_LIBDEVFS: 'y'
35+
CONFIG_LIBPOSIX_ENVIRON_ENVP0: "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
36+
CONFIG_LIBPOSIX_ENVIRON_ENVP1: "LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib"
37+
CONFIG_LIBPOSIX_ENVIRON_ENVP2: "HOME=/"
38+
CONFIG_LIBPOSIX_ENVIRON: 'y'
39+
CONFIG_LIBPOSIX_ENVIRON_LIBPARAM: 'y'
40+
CONFIG_LIBPOSIX_ENVIRON_LIBPARAM_MAXCOUNT: '64'
41+
CONFIG_LIBPOSIX_EVENTFD: 'y'
42+
CONFIG_LIBPOSIX_FDIO: 'y'
43+
CONFIG_LIBPOSIX_FDTAB: 'y'
44+
CONFIG_LIBPOSIX_FUTEX: 'y'
45+
CONFIG_LIBPOSIX_MMAP: 'y'
46+
CONFIG_LIBPOSIX_PIPE: 'y'
47+
CONFIG_LIBPOSIX_POLL: 'y'
48+
CONFIG_LIBPOSIX_PROCESS_CLONE: 'y'
49+
CONFIG_LIBPOSIX_SOCKET: 'y'
50+
CONFIG_LIBPOSIX_SYSINFO: 'y'
51+
CONFIG_LIBPOSIX_TIME: 'y'
52+
CONFIG_LIBPOSIX_TIMERFD: 'y'
53+
CONFIG_LIBPOSIX_UNIXSOCKET: 'y'
54+
CONFIG_LIBPOSIX_USER_GID: 0
55+
CONFIG_LIBPOSIX_USER_GROUPNAME: "root"
56+
CONFIG_LIBPOSIX_USER_UID: 0
57+
CONFIG_LIBPOSIX_USER_USERNAME: "root"
58+
CONFIG_LIBPOSIX_USER: 'y'
59+
CONFIG_LIBRAMFS: 'y'
60+
CONFIG_LIBSYSCALL_SHIM_HANDLER_ULTLS: 'y'
61+
CONFIG_LIBSYSCALL_SHIM_HANDLER: 'y'
62+
CONFIG_LIBSYSCALL_SHIM_LEGACY_VERBOSE: 'y'
63+
CONFIG_LIBSYSCALL_SHIM: 'y'
64+
CONFIG_LIBUKALLOCPOOL: 'y'
65+
CONFIG_LIBUKBLKDEV_MAXNBQUEUES: '1'
66+
CONFIG_LIBUKBLKDEV_DISPATCHERTHREADS: 'y'
67+
CONFIG_LIBUKBLKDEV_SYNC_IO_BLOCKED_WAITING: 'y'
68+
CONFIG_LIBUKBLKDEV: 'y'
69+
CONFIG_LIBUKBOOT_BANNER_MINIMAL: 'y'
70+
CONFIG_LIBUKBOOT_HEAP_BASE: '0x400000000'
71+
CONFIG_LIBUKBOOT_MAINTHREAD: 'y'
72+
CONFIG_LIBUKBOOT_SHUTDOWNREQ_HANDLER: 'y'
73+
CONFIG_LIBUKCPIO: 'y'
74+
CONFIG_LIBUKDEBUG_CRASH_SCREEN: 'y'
75+
CONFIG_LIBUKDEBUG_ENABLE_ASSERT: 'y'
76+
CONFIG_LIBUKDEBUG_PRINT_SRCNAME: 'n'
77+
CONFIG_LIBUKDEBUG_PRINT_TIME: 'y'
78+
CONFIG_LIBUKDEBUG_PRINTK_ERR: 'y'
79+
CONFIG_LIBUKDEBUG_PRINTK: 'y'
80+
CONFIG_LIBUKDEBUG: 'y'
81+
CONFIG_LIBUKFALLOC: 'y'
82+
CONFIG_LIBUKMPI: 'n'
83+
CONFIG_LIBUKSIGNAL: 'y'
84+
CONFIG_LIBUKRANDOM_DEVFS: 'y'
85+
CONFIG_LIBUKRANDOM: 'y'
86+
CONFIG_LIBUKVMEM_DEFAULT_BASE: '0x0000001000000000'
87+
CONFIG_LIBUKVMEM_DEMAND_PAGE_IN_SIZE: 12
88+
CONFIG_LIBUKVMEM_PAGEFAULT_HANDLER_PRIO: 4
89+
CONFIG_LIBUKVMEM: 'y'
90+
CONFIG_LIBVFSCORE_AUTOMOUNT_CI: 'y'
91+
CONFIG_LIBVFSCORE_AUTOMOUNT_CI_EINITRD: 'y'
92+
CONFIG_LIBVFSCORE_NONLARGEFILE: 'y'
93+
CONFIG_LIBVFSCORE: 'y'
94+
CONFIG_OPTIMIZE_DEADELIM: 'y'
95+
CONFIG_OPTIMIZE_LTO: 'y'
96+
CONFIG_PAGING: 'y'
97+
CONFIG_STACK_SIZE_PAGE_ORDER: 4 # 128 * 4K = 512K
98+
CONFIG_UKPLAT_MEMREGION_MAX_COUNT: 64
99+
CONFIG_LIBUKNETDEV_EINFO_LIBPARAM: 'y'
100+
101+
# Debug options
102+
# CONFIG_LIBUKDEBUG_PRINTD: 'y'
103+
# CONFIG_LIBUKDEBUG_PRINTK_INFO: 'y'
104+
# CONFIG_LIBSYSCALL_SHIM_STRACE: 'y'
105+
# CONFIG_LIBSYSCALL_SHIM_DEBUG: 'y'
106+
107+
libraries:
108+
lwip:
109+
source: https://github.com/unikraft/lib-lwip.git
110+
version: staging
111+
kconfig:
112+
CONFIG_LWIP_TCP: 'y'
113+
CONFIG_LWIP_UDP: 'y'
114+
CONFIG_LWIP_RAW: 'y'
115+
CONFIG_LWIP_WND_SCALE: 'y'
116+
CONFIG_LWIP_TCP_KEEPALIVE: 'y'
117+
CONFIG_LWIP_THREADS: 'y'
118+
CONFIG_LWIP_HEAP: 'y'
119+
CONFIG_LWIP_SOCKET: 'y'
120+
CONFIG_LWIP_AUTOIFACE: 'y'
121+
CONFIG_LWIP_NUM_TCPCON: 64
122+
CONFIG_LWIP_NUM_TCPLISTENERS: 64
123+
CONFIG_LWIP_ICMP: 'y'
124+
CONFIG_LWIP_DHCP: 'y'
125+
CONFIG_LWIP_DNS: 'n'
126+
libelf:
127+
source: https://github.com/unikraft/lib-libelf.git
128+
version: staging
129+
130+
targets:
131+
- fc/x86_64
132+
- qemu/x86_64

library/bun/1.1/README.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Bun
2+
3+
This directory contains the [Bun](https://bun.sh/) runtime on Unikraft, in binary compatibility mode.
4+
It implements a simple server running on Unikraft that provides a simple response to each request.
5+
6+
## Run and Use
7+
8+
Use `kraft` to run the image and start a Unikraft instance:
9+
10+
```bash
11+
kraft run --rm -M 512M -p 3000:3000 --plat qemu --arch x86_64 unikraft.org/bun:1.1
12+
```
13+
14+
If the `--plat` argument is left out, it defaults to `qemu`.
15+
If the `--arch` argument is left out, it defaults to your system's CPU architecture.
16+
17+
Once executed, it will open port `3000` and wait for connections.
18+
To test it, you can use `curl`:
19+
20+
```bash
21+
curl localhost:3000
22+
```
23+
24+
You should see a "Hello, World!" message.
25+
26+
## Inspect and Close
27+
28+
To list information about the Unikraft instance, use:
29+
30+
```bash
31+
kraft ps
32+
```
33+
34+
```text
35+
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
36+
eloquent_nyota project://bun:qemu/x86_64 /usr/bin/bun run /usr/src/server.ts 8 seconds ago running 0MiB 0.0.0.0:3000->3000/tcp qemu/x86_64
37+
```
38+
39+
The instance name is `eloquent_nyota`.
40+
To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run:
41+
42+
```bash
43+
kraft rm eloquent_nyota
44+
```
45+
46+
## Build and Run Locally
47+
48+
The commands so far used the pre-build Bun image available in the Unikraft registry.
49+
50+
In oder to to build a local Bun image, clone this repository and `cd` into this directory.
51+
Then use `kraft` to build an image locally:
52+
53+
```bash
54+
kraft build --no-cache --no-update --plat qemu --arch x86_64
55+
```
56+
57+
Similar to the `kraft run` command, if the `--plat` argument is left out, it defaults to `qemu`.
58+
If the `--arch` argument is left out, it defaults to your system's CPU architecture.
59+
60+
In order to run the locally built image, use `.` (_dot_, the current directory) as the final argument to the `kraft run` command:
61+
62+
```bash
63+
kraft run --rm -M 512M -p 3000:3000 --plat qemu --arch x86_64 .
64+
```
65+
66+
Same as above, it will open port `3000` and wait for connections.
67+
68+
## `kraft` and `sudo`
69+
70+
Mixing invocations of `kraft` and `sudo` can lead to unexpected behavior.
71+
Read more about how to start `kraft` without `sudo` at [https://unikraft.org/sudoless](https://unikraft.org/sudoless).
72+
73+
## Learn More
74+
75+
- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
76+
- [How to build `Dockerfile` root filesystems with BuildKit](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)

library/bun/1.1/server.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const port = process.env.PORT || 3000;
2+
3+
console.log(
4+
`Launching Bun HTTP server on port: ${port}, url: http://0.0.0.0:${port} 🚀`
5+
);
6+
7+
Bun.serve({
8+
port: port,
9+
fetch(_request) {
10+
return new Response("Hello, World!");
11+
},
12+
});

0 commit comments

Comments
 (0)