Skip to content

Commit

Permalink
feat(examples): Add Redis example
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Huici <[email protected]>
  • Loading branch information
felipehuici authored and razvand committed Mar 9, 2024
1 parent 10bd3ab commit 5a4b181
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/redis/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.unikraft/
1 change: 1 addition & 0 deletions examples/redis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.unikraft/
9 changes: 9 additions & 0 deletions examples/redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM debian:bookworm AS build

RUN set -xe; \
echo "Your code here";

FROM scratch

# Copy your files here
# COPY --from=build / /
7 changes: 7 additions & 0 deletions examples/redis/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
spec: v0.6

runtime: redis:7.2

rootfs: ./Dockerfile

cmd: ["/usr/bin/redis-server", "/etc/redis/redis.conf"]
61 changes: 61 additions & 0 deletions examples/redis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 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 -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` or `redis-benchmark` to test the connection:

```console
redis-benchmark -t ping,set,get -n 10000 -h localhost
```

## Inspect and Close

To list information about the Unikraft instance, use:

```bash
kraft ps
```

```text
NAME KERNEL ARGS CREATED STATUS MEM PLAT
admiring_ndakasi oci://unikraft.org/base:latest /etc/redis/redis.conf 1 minute ago running 64MiB 0.0.0.0:8080->8080/tcp qemu/x86_64
```

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

```bash
kraft rm nostalgic_snowflake
```

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 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)

0 comments on commit 5a4b181

Please sign in to comment.