Skip to content
Open
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
3 changes: 3 additions & 0 deletions examples/httpserver-java25-base/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Makefile.uk
/.unikraft/
/.config*
3 changes: 3 additions & 0 deletions examples/httpserver-java25-base/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Makefile.uk
/.unikraft/
/.config*
27 changes: 27 additions & 0 deletions examples/httpserver-java25-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM openjdk:25-rc-oraclelinux9 AS build

ENV JAVA_HOME=/usr/java/openjdk-25

RUN ldconfig $JAVA_HOME/lib/server/

WORKDIR /src

COPY ./SimpleHttpServer.java /src/SimpleHttpServer.java

RUN javac SimpleHttpServer.java

FROM alpine:3 AS sys

FROM scratch

COPY --from=build /usr/lib64/libc.so.6 /usr/lib64/
COPY --from=build /usr/lib64/libstdc++.so.6 /usr/lib64/
COPY --from=build /usr/lib64/libm.so.6 /usr/lib64/
COPY --from=build /usr/lib64/libz.so.1 /usr/lib64/
COPY --from=build /usr/lib64/libgcc_s.so.1 /usr/lib64/
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/
COPY --from=build /etc/ld.so.cache /etc/ld.so.cache

COPY --from=build $JAVA_HOME/ /usr/lib/jvm/java-25-runtime/

COPY --from=build /src/SimpleHttpServer.class /usr/src/SimpleHttpServer.class
9 changes: 9 additions & 0 deletions examples/httpserver-java25-base/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec: v0.6

name: httpserver-java25-base

rootfs: ./Dockerfile

cmd: ["/usr/lib/jvm/java-25-runtime/bin/java", "-classpath", "/usr/src/", "SimpleHttpServer"]

runtime: base:latest
83 changes: 83 additions & 0 deletions examples/httpserver-java25-base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Java 25 HTTP Server

This directory contains the [Java](https://www.java.com/en/) runtime on Unikraft, in binary compatibility mode.
It implements a simple HTTP server running on Unikraft that provides a simple response to each request.

## Run and Use

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

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

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 "Hello, World!" message.

## Inspect and Close

To list information about the Unikraft instance, use:

```bash
kraft ps -a
```

```text
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
upbeat_jenny project://httpserver-java25:qemu/x86_64 /usr/lib/jvm/java-25-runtime[...] 5 seconds ago running 2048M 0.0.0.0:8080->8080/tcp qemu/x86_64
```

The instance name is `upbeat_jenny`.
To close the Unikraft instance, use:

```bash
kraft rm upbeat_jenny
```

Note that closing the `kraft run` command (e.g., via `Ctrl+c`) does not kill the Unikraft instance.
If you want the Unikraft instance closed when closing the `kraft run` command, use the `--rm` option:

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

## Build and Run Locally

The commands so far used the pre-build Java image available in the Unikraft registry.

In oder to to build a local Java image, clone this repository and `cd` into this directory.
Then use `kraft` to build an image locally:

```bash
kraft build --no-cache --no-update --plat qemu --arch x86_64
```

Similar to the `kraft run` command, 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.

In order to run the locally built image, use `.` (_dot_, the current directory) as the final argument to the `kraft run` command:

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

Same as above, it will open port `8080` and wait for connections.

## `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)
- [How to build `Dockerfile` root filesystems with BuildKit](https://unikraft.org/docs/getting-started/integrations/buildkit)
29 changes: 29 additions & 0 deletions examples/httpserver-java25-base/SimpleHttpServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// https://www.logicbig.com/tutorials/core-java-tutorial/http-server/http-server-basic.html

import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;

public class SimpleHttpServer {
private static final int listenPort = 8080;

public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(listenPort), 0);
HttpContext context = server.createContext("/");
context.setHandler(SimpleHttpServer::handleRequest);
System.out.println("Waiting for HTTP connections on port " + listenPort + " ...");
server.start();
}

private static void handleRequest(HttpExchange exchange) throws IOException {
String response = "Hello, World!\n";
exchange.sendResponseHeaders(200, response.getBytes().length); // response code and length
OutputStream os = exchange.getResponseBody();
os.write(response.getBytes());
os.close();
}

}
3 changes: 3 additions & 0 deletions examples/httpserver-java25/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Makefile.uk
/.unikraft/
/.config*
3 changes: 3 additions & 0 deletions examples/httpserver-java25/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Makefile.uk
/.unikraft/
/.config*
27 changes: 27 additions & 0 deletions examples/httpserver-java25/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM openjdk:25-rc-oraclelinux9 AS build

ENV JAVA_HOME=/usr/java/openjdk-25

RUN ldconfig $JAVA_HOME/lib/server/

WORKDIR /src

COPY ./SimpleHttpServer.java /src/SimpleHttpServer.java

RUN javac SimpleHttpServer.java

FROM alpine:3 AS sys

FROM scratch

COPY --from=build /usr/lib64/libc.so.6 /usr/lib64/
COPY --from=build /usr/lib64/libstdc++.so.6 /usr/lib64/
COPY --from=build /usr/lib64/libm.so.6 /usr/lib64/
COPY --from=build /usr/lib64/libz.so.1 /usr/lib64/
COPY --from=build /usr/lib64/libgcc_s.so.1 /usr/lib64/
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/
COPY --from=build /etc/ld.so.cache /etc/ld.so.cache

COPY --from=build $JAVA_HOME/ /usr/lib/jvm/java-25-runtime/

COPY --from=build /src/SimpleHttpServer.class /usr/src/SimpleHttpServer.class
9 changes: 9 additions & 0 deletions examples/httpserver-java25/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec: v0.6

name: httpserver-java25-base

rootfs: ./Dockerfile

cmd: ["/usr/lib/jvm/java-25-runtime/bin/java", "-classpath", "/usr/src/", "SimpleHttpServer"]

runtime: java:25
83 changes: 83 additions & 0 deletions examples/httpserver-java25/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Java 25 HTTP Server

This directory contains the [Java](https://www.java.com/en/) runtime on Unikraft, in binary compatibility mode.
It implements a simple HTTP server running on Unikraft that provides a simple response to each request.

## Run and Use

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

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

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 "Hello, World!" message.

## Inspect and Close

To list information about the Unikraft instance, use:

```bash
kraft ps -a
```

```text
NAME KERNEL ARGS CREATED STATUS MEM PORTS PLAT
upbeat_jenny project://httpserver-java25:qemu/x86_64 /usr/lib/jvm/java-25-runtime[...] 5 seconds ago running 2048M 0.0.0.0:8080->8080/tcp qemu/x86_64
```

The instance name is `upbeat_jenny`.
To close the Unikraft instance, use:

```bash
kraft rm upbeat_jenny
```

Note that closing the `kraft run` command (e.g., via `Ctrl+c`) does not kill the Unikraft instance.
If you want the Unikraft instance closed when closing the `kraft run` command, use the `--rm` option:

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

## Build and Run Locally

The commands so far used the pre-build Java image available in the Unikraft registry.

In oder to to build a local Java image, clone this repository and `cd` into this directory.
Then use `kraft` to build an image locally:

```bash
kraft build --no-cache --no-update --plat qemu --arch x86_64
```

Similar to the `kraft run` command, 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.

In order to run the locally built image, use `.` (_dot_, the current directory) as the final argument to the `kraft run` command:

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

Same as above, it will open port `8080` and wait for connections.

## `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)
- [How to build `Dockerfile` root filesystems with BuildKit](https://unikraft.org/docs/getting-started/integrations/buildkit)
29 changes: 29 additions & 0 deletions examples/httpserver-java25/SimpleHttpServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// https://www.logicbig.com/tutorials/core-java-tutorial/http-server/http-server-basic.html

import com.sun.net.httpserver.HttpContext;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;

public class SimpleHttpServer {
private static final int listenPort = 8080;

public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(listenPort), 0);
HttpContext context = server.createContext("/");
context.setHandler(SimpleHttpServer::handleRequest);
System.out.println("Waiting for HTTP connections on port " + listenPort + " ...");
server.start();
}

private static void handleRequest(HttpExchange exchange) throws IOException {
String response = "Hello, World!\n";
exchange.sendResponseHeaders(200, response.getBytes().length); // response code and length
OutputStream os = exchange.getResponseBody();
os.write(response.getBytes());
os.close();
}

}
3 changes: 3 additions & 0 deletions library/java/25/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Makefile.uk
/.unikraft/
/.config*
3 changes: 3 additions & 0 deletions library/java/25/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/Makefile.uk
/.unikraft/
/.config*
27 changes: 27 additions & 0 deletions library/java/25/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM openjdk:25-rc-oraclelinux9 AS build

ENV JAVA_HOME=/usr/java/openjdk-25

RUN ldconfig $JAVA_HOME/lib/server/

WORKDIR /src

COPY ./SimpleHttpServer.java /src/SimpleHttpServer.java

RUN javac SimpleHttpServer.java

FROM alpine:3 AS sys

FROM scratch

COPY --from=build /usr/lib64/libc.so.6 /usr/lib64/
COPY --from=build /usr/lib64/libstdc++.so.6 /usr/lib64/
COPY --from=build /usr/lib64/libm.so.6 /usr/lib64/
COPY --from=build /usr/lib64/libz.so.1 /usr/lib64/
COPY --from=build /usr/lib64/libgcc_s.so.1 /usr/lib64/
COPY --from=build /lib64/ld-linux-x86-64.so.2 /lib64/
COPY --from=build /etc/ld.so.cache /etc/ld.so.cache

COPY --from=build $JAVA_HOME/ /usr/lib/jvm/java-25-runtime/

COPY --from=build /src/SimpleHttpServer.class /usr/src/SimpleHttpServer.class
Loading