Skip to content

Commit

Permalink
feat(examples): Introduce Hello in Java as example
Browse files Browse the repository at this point in the history
Introduce a Hello Java program as binary compatibility run. Install Java
and build program using `Dockerfile`. Then run it with the `base` kernel
images from `../../kernels/`.

Add typical files for a bincompat app:

* `Kraftfile`: build / run rules, including pulling the `base` image
* `Dockerfile`: filesystem, including binary and libraries
* `Makefile`: used to generate the root filesystem from the `Dockerfile`
  rules
* `README.md`: instructions to set up, build and run the application
* `config.yaml`: configuration file to generate scripts to the
  application
* `Hello.java`: the Java program

`config.yaml` is used to generate run scripts using the
`../../utils/bincompat/generate.py` script.

The kernels in `../../kernels` are generated by running the
`../../utils/bincompat/base-build-all.sh` script while inside the
`../../library/base/` directory.

Signed-off-by: Razvan Deaconescu <[email protected]>
  • Loading branch information
razvand committed Dec 17, 2023
1 parent c393b64 commit bdc739d
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/hello-java17/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/rootfs/
/rootfs.cpio
/run-qemu*
/run-fc*
/kraft-run-*
/fc*.json
26 changes: 26 additions & 0 deletions examples/hello-java17/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM --platform=linux/x86_64 debian:bookworm AS build

RUN set -xe ; \
apt -yqq update ; \
apt -yqq install default-jre ; \
apt -yqq install default-jdk

WORKDIR /src

COPY ./Hello.java /src/Hello.java

RUN javac Hello.java

FROM scratch

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

COPY --from=build /usr/lib/jvm/java-17-openjdk-amd64 /usr/lib/jvm/java-17-openjdk-amd64
COPY --from=build /usr/lib/jvm/java-17-openjdk-amd64/lib/libjli.so /lib/x86_64-linux-gnu/libjli.so

COPY --from=build /src/Hello.class /Hello.class
5 changes: 5 additions & 0 deletions examples/hello-java17/Hello.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
9 changes: 9 additions & 0 deletions examples/hello-java17/Kraftfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec: v0.6

name: hello-java

runtime: index.unikraft.io/unikraft.org/base:latest

rootfs: ./Dockerfile

cmd: ["/usr/lib/jvm/java-17-openjdk-amd64/bin/java", "Hello"]
4 changes: 4 additions & 0 deletions examples/hello-java17/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
IMAGE_NAME = unikraft-java
CMD = /usr/lib/jvm/java-17-openjdk-amd64/bin/java Hello

include ../../utils/bincompat/docker.Makefile
20 changes: 20 additions & 0 deletions examples/hello-java17/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Hello World on Java

This directory contains the definition to run a helloworld program with [Python3](https://www.python.org/) on Unikraft in binary compatibility mode.

Follow the instructions in the common `README.maintainers.md` file in the root of the repository to set up and configure the application.

## Quick Run

Use `kraft` to run the image:

```console
kraft run -M 512M
```

Once executed, it will run the `helloworld.py` script and print "Hello, World!".

## Scripted Run

Use the scripted runs, detailed in the `README.maintainers.md` file.
Once executed, scripts will run the `helloworld.py` script and print "Hello, World!".
4 changes: 4 additions & 0 deletions examples/hello-java17/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
networking: False
accel: True
memory: 1048
kerneldir: ../../kernels

0 comments on commit bdc739d

Please sign in to comment.