You can use GraalVM Enterprise Native Image to generate a native executable for this app. We have a shell script that uses multistage Docker build to build the app JAR, generate the app native executable and ship the native executable in a separate runtime docker image.
./scripts/build-native-exec-ee.sh
If you are prompted to docker login
to OCR, enter your OCR user and password.
Run this command to see the new docker image:
docker images -a
The output is similar to:
REPOSITORY TAG IMAGE ID CREATED SIZE
jibber-ni-gvmee22-jdk17 0.0.1 daa1a94f4104 24 seconds ago 75.9MB
You may see this error while generating the native executable.
Image build request failed with exit status 137
Exit status 137 indicates an out of memory error. Try increasing the memory for Docker resource. On Mac, go to Docker Desktop >> Settings >> Resources. Increase the memory to 8 GB or higher.
Credits: https://stackoverflow.com/questions/68148868/micronaut-cannot-build-native-image-graalvm
A Docker Compose file has ben provided that will start the container. Most sections have been commented out. Feel free to uncomment sections, as needed.
Go to docker-compose.yml, comment the jibber-jar-gvmee-jdk17:
section. Uncomment the jibber-ni-gvmee-jdk17:
section and run the following command to run the app native executable.
docker compose up --remove-orphans
This will start the app native executable on port 8082. Go to http://localhost:8082/jibber in a browser and you should see a nonsense verse.
From another terminal window, run the following command:
docker compose stop