8000 Add new examples that use base runtime by V1ad8 · Pull Request #184 · unikraft/catalog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add new examples that use base runtime #184

8000
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
May 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/database-redis7.2-base/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.unikraft/
1 change: 1 addition & 0 deletions examples/database-redis7.2-base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.unikraft/
16 changes: 16 additions & 0 deletions examples/database-redis7.2-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM redis:7.2.2-bookworm AS build

FROM scratch

# Redis binaries, modules, configuration, log and runtime files
COPY --from=build /usr/local/bin/redis-server /usr/bin/redis-server

# Libraries
COPY --from=build /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
COPY --from=build /lib/x86_64-linux-gnu/libssl.so.3 /lib/x86_64-linux-gnu/libssl.so.3
COPY --from=build /lib/x86_64-linux-gnu/libcrypto.so.3 /lib/x86_64-linux-gnu/libcrypto.so.3
COPY --from=build /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2

# Custom configuration files, including using a single process for Redis
COPY ./redis.conf /etc/redis/redis.conf
9 changes: 9 additions & 0 deletions examples/database-redis7.2-base/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec: v0.6

name: database-redis7.2-base

runtime: base:latest

rootfs: ./Dockerfile

cmd: ["/usr/bin/redis-server", "/etc/redis/redis.conf"]
62 changes: 62 additions & 0 deletions examples/database-redis7.2-base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Redis

This examples demonstrates how to use [`Redis`](https://redis.io), an open-source in-memory storage, used as a distributed, in-memory key–value database, cache and message broker, with optional durability.

## Set Up

To run this example, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli), clone this repository and `cd` into this directory.

## Run and Use

Use `kraft` to run the image and start a Unikraft instance:

```bash
kraft run --rm -p 6379:6379 --plat qemu --arch x86_64 -M 512M .
```

If the `--plat` argument is left out, it defaults to `qemu`.
If the `--arch` argument is left out, it defaults to your system's CPU architecture.

Then use `redis-cli` to test the connection:

```console
redis-cli set a 1
redis-cli get a
```

## Inspect and Close

To list information about the Unikraft instance, use:

```bash
kraft ps
```

```text
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
upbeat_abang oci://unikraft.org/redis:7.2 /usr/bin/redis-server /etc/redis/redis.conf 53 seconds ago running 488M 0.0.0.0:6379->6379/tcp qemu/x86_64
```

The instance name is `upbeat_abang`.
To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run:

```bash
kraft rm upbeat_abang
```

Note that depending on how you modify this example your instance **may** need more memory to run.
To do so, use the `kraft run`'s `-M` flag, for example:

```bash
kraft run --rm -p 6379:6379 --plat qemu --arch x86_64 -M 1024M .
```

## `kraft` and `sudo`

Mixing invocations of `kraft` and `sudo` can lead to unexpected behavior.
Read more about how to start `kraft` without `sudo` at [https://unikraft.org/sudoless](https://unikraft.org/sudoless).

## Learn More

- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
- [Building `Dockerfile` Images with `BuildKit`](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)
6 changes: 6 additions & 0 deletions examples/database-redis7.2-base/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bind 0.0.0.0
port 6379
tcp-backlog 511
daemonize no
timeout 0
tcp-keepalive 300
6 changes: 6 additions & 0 deletions examples/expressjs4.18-node21-base/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist/
node_modules/
/.unikraft/
/Dockerfile
/Kraftfile
/README.md
2 changes: 2 additions & 0 deletions examples/expressjs4.18-node21-base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/.unikraft/
43 changes: 43 additions & 0 deletions examples/expressjs4.18-node21-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM node:21-alpine AS node

WORKDIR /usr/src

COPY . /usr/src/

RUN npm install


FROM alpine:3 AS sys

RUN set -xe; \
mkdir -p /target/etc; \
mkdir -p /blank; \
apk --no-cache add \
ca-certificates \
tzdata \
; \
update-ca-certificates; \
ln -sf ../usr/share/zoneinfo/Etc/UTC /target/etc/localtime; \
echo "Etc/UTC" > /target/etc/timezone;

FROM scratch

COPY --from=sys /target/etc /etc
COPY --from=sys /usr/share/zoneinfo/Etc/UTC /usr/share/zoneinfo/Etc/UTC
COPY --from=sys /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=sys /blank /tmp

# Node binary
COPY --from=node /usr/local/bin/node /usr/bin/node

# System libraries
COPY --from=node /lib/ld-musl-x86_64.so.1 /lib/ld-musl-x86_64.so.1
COPY --from=node /usr/lib/libgcc_s.so.1 /usr/lib/libgcc_s.so.1
COPY --from=node /usr/lib/libstdc++.so.6 /usr/lib/libstdc++.so.6

# Distribution configuration
COPY --from=node /etc/os-release /etc/os-release

# Express.js
10000 COPY --from=node /usr/src/node_modules /usr/src/node_modules
COPY --from=node /usr/src/app/index.js /usr/src/server.js
9 changes: 9 additions & 0 deletions examples/expressjs4.18-node21-base/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec: v0.6

name: expressjs4.18-node21-base

runtime: base:latest

rootfs: ./Dockerfile

cmd: ["/usr/bin/node", "/usr/src/server.js"]
64 changes: 64 additions & 0 deletions examples/expressjs4.18-node21-base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Node ExpressJS

This directory contains a Node [`ExpressJS`](https://expressjs.com/) implementation running on Unikraft.

## Set Up

To run this example, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli), clone this repository and `cd` into this directory.

## Run and Use

Use `kraft` to run the image and start a Unikraft instance:

```bash
kraft run --rm -p 3000:3000 --plat qemu --arch x86_64 -M 512M .
```

If the `--plat` argument is left out, it defaults to `qemu`.
If the `--arch` argument is left out, it defaults to your system's CPU architecture.

Once executed, it will open port `3000` and wait for connections.
To test it, you can use `curl`:

```bash
curl localhost
```

You should see a "Bye, World!" message.

## Inspect and Close

To list information about the Unikraft instance, use:

```bash
kraft ps
```

```text
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
agitated_davidgreybeard oci://unikraft.org/node:21 /usr/bin/node /usr/src/server.js 10 seconds ago running 488M 0.0.0.0:3000->3000/tcp qemu/x86_64
```

The instance name is `agitated_davidgreybeard`.
To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run:

```bash
kraft rm agitated_davidgreybeard
```

Note that depending on how you modify this example your instance **may** need more memory to run.
To do so, use the `kraft run`'s `-M` flag, for example:

```bash
kraft run -p 3000:3000 --plat qemu --arch x86_64 -M 1024M .
```

## `kraft` and `sudo`

Mixing invocations of `kraft` and `sudo` can lead to unexpected behavior.
Read more about how to start `kraft` without `sudo` at [https://unikraft.org/sudoless](https://unikraft.org/sudoless).

## Learn More

- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
- [Building `Dockerfile` Images with `BuildKit`](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)
11 changes: 11 additions & 0 deletions examples/expressjs4.18-node21-base/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
res.send('Bye, World!\n')
})

app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
5 changes: 5 additions & 0 deletions examples/expressjs4.18-node21-base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"express": "^4.18.2"
}
}
26 changes: 26 additions & 0 deletions examples/flask3.0-python3.10-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:3.10.11 AS base

WORKDIR /app

COPY requirements.txt /app

RUN pip3 install -r requirements.txt --no-cache-dir

FROM scratch

# System libraries
COPY --from=base /usr/local/lib/python3.10 /usr/local/lib/python3.10
COPY --from=base /usr/local/bin/../lib/libpython3.10.so.1.0 /usr/local/bin/../lib/libpython3.10.so.1.0
COPY --from=base /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
COPY --from=base /lib/x86_64-linux-gnu/libpthread.so.0 /lib/x86_64-linux-gnu/libpthread.so.0
COPY --from=base /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libdl.so.2
COPY --from=base /lib/x86_64-linux-gnu/libutil.so.1 /lib/x86_64-linux-gnu/libutil.so.1
COPY --from=base /lib/x86_64-linux-gnu/libm.so.6 /lib/x86_64-linux-gnu/libm.so.6
COPY --from=base /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
COPY --from=base /lib/x86_64-linux-gnu/libz.so.1 /lib/x86_64-linux-gnu/libz.so.1

# Python executable
COPY --from=base /usr/local/bin/python3 /usr/local/bin/python3

# Python files
COPY ./server.py /app/server.py
9 changes: 9 additions & 0 deletions examples/flask3.0-python3.10-base/Kraftfile
10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec: v0.6

name: flask3.0-python3.10-base

runtime: base:latest

rootfs: ./Dockerfile

cmd: ["/usr/local/bin/python3", "/app/server.py"]
64 changes: 64 additions & 0 deletions examples/flask3.0-python3.10-base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Flask 3.0 Web Server on Unikraft

This directory contains an example [Flask 3.0](https://flask.palletsprojects.com/en/3.0.x/) HTTP server.

## Set Up

To run this example, [install Unikraft's companion command-line toolchain `kraft`](https://unikraft.org/docs/cli), clone this repository and `cd` into this directory.

## Run and Use

Use `kraft` to run the image and start a Unikraft instance:

```bash
kraft run --rm -p 8080:8080 --plat qemu --arch x86_64 -M 512M .
```

If the `--plat` argument is left out, it defaults to `qemu`.
If the `--arch` argument is left out, it defaults to your system's CPU architecture.

Once executed, it will open port `8080` and wait for connections.
To test it, you can use `curl`:

```bash
curl localhost:8080
```

You should see a "Bye, World!" message.

## Inspect and Close

To list information about the Unikraft instance, use:

```bash
kraft ps
```

```text
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
strange_harambe oci://unikraft.org/python:3.10 /app/server.py 11 seconds ago running 488M 0.0.0.0:8080->8080/tcp qemu/x86_64
```

The instance name is `strange_harambe`.
To close the Unikraft instance, close the `kraft` process (e.g., via `Ctrl+c`) or run:

```bash
kraft rm strange_harambe
```

Note that depending on how you modify this example your instance **may** need more memory to run.
To do so, use the `kraft run`'s `-M` flag, for example:

```bash
kraft run --rm -p 8080:8080 --plat qemu --arch x86_64 -M 1024M .
```

## `kraft` and `sudo`

Mixing invocations of `kraft` and `sudo` can lead to unexpected behavior.
Read more about how to start `kraft` without `sudo` at [https://unikraft.org/sudoless](https://unikraft.org/sudoless).

## Learn More

- [How to run unikernels locally](https://unikraft.org/docs/cli/running)
- [Building `Dockerfile` Images with `BuildKit`](https://unikraft.org/guides/building-dockerfile-images-with-buildkit)
1 change: 1 addition & 0 deletions examples/flask3.0-python3.10-base/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask
12 changes: 12 additions & 0 deletions examples/flask3.0-python3.10-base/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from flask import Flask

app = Flask(__name__)


@app.route("/")
def hello():
return "Bye, World!\n"


if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
1 change: 1 addition & 0 deletions examples/flask3.0-python3.12-base/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.unikraft/
1 change: 1 addition & 0 deletions examples/flask3.0-python3.12-base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.unikraft/
Loading
0