From c961cb95684f5dac8351497e412bbdf457b2a8a8 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Sun, 17 Dec 2023 17:33:16 +0200 Subject: [PATCH] feat(examples): Introduce Hello in Java as example 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 --- examples/hello-java17/.gitignore | 6 ++++++ examples/hello-java17/Dockerfile | 26 ++++++++++++++++++++++++++ examples/hello-java17/Hello.java | 5 +++++ examples/hello-java17/Kraftfile | 9 +++++++++ examples/hello-java17/Makefile | 4 ++++ examples/hello-java17/README.md | 20 ++++++++++++++++++++ examples/hello-java17/config.yaml | 4 ++++ 7 files changed, 74 insertions(+) create mode 100644 examples/hello-java17/.gitignore create mode 100644 examples/hello-java17/Dockerfile create mode 100644 examples/hello-java17/Hello.java create mode 100644 examples/hello-java17/Kraftfile create mode 100644 examples/hello-java17/Makefile create mode 100644 examples/hello-java17/README.md create mode 100644 examples/hello-java17/config.yaml diff --git a/examples/hello-java17/.gitignore b/examples/hello-java17/.gitignore new file mode 100644 index 00000000..40b3ca8b --- /dev/null +++ b/examples/hello-java17/.gitignore @@ -0,0 +1,6 @@ +/rootfs/ +/rootfs.cpio +/run-qemu* +/run-fc* +/kraft-run-* +/fc*.json diff --git a/examples/hello-java17/Dockerfile b/examples/hello-java17/Dockerfile new file mode 100644 index 00000000..976ad485 --- /dev/null +++ b/examples/hello-java17/Dockerfile @@ -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 diff --git a/examples/hello-java17/Hello.java b/examples/hello-java17/Hello.java new file mode 100644 index 00000000..b77c3975 --- /dev/null +++ b/examples/hello-java17/Hello.java @@ -0,0 +1,5 @@ +public class Hello { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} diff --git a/examples/hello-java17/Kraftfile b/examples/hello-java17/Kraftfile new file mode 100644 index 00000000..75f47a15 --- /dev/null +++ b/examples/hello-java17/Kraftfile @@ -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"] diff --git a/examples/hello-java17/Makefile b/examples/hello-java17/Makefile new file mode 100644 index 00000000..55511be8 --- /dev/null +++ b/examples/hello-java17/Makefile @@ -0,0 +1,4 @@ +IMAGE_NAME = unikraft-java +CMD = /usr/lib/jvm/java-17-openjdk-amd64/bin/java Hello + +include ../../utils/bincompat/docker.Makefile diff --git a/examples/hello-java17/README.md b/examples/hello-java17/README.md new file mode 100644 index 00000000..75f9c56a --- /dev/null +++ b/examples/hello-java17/README.md @@ -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!". diff --git a/examples/hello-java17/config.yaml b/examples/hello-java17/config.yaml new file mode 100644 index 00000000..61f170fb --- /dev/null +++ b/examples/hello-java17/config.yaml @@ -0,0 +1,4 @@ +networking: False +accel: True +memory: 1048 +kerneldir: ../../kernels