From 70868eba2cf7b61641c8143f3fb9d3c2e8b6f56e Mon Sep 17 00:00:00 2001 From: Gabriel Cunha Date: Sat, 16 May 2026 16:23:35 -0300 Subject: [PATCH 1/2] using jlink and jdeps to build docker image --- ojp-server/README.md | 21 +++++++++++++++++++-- ojp-server/base.Dockerfile | 14 ++++++++++++++ ojp-server/pom.xml | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 ojp-server/base.Dockerfile diff --git a/ojp-server/README.md b/ojp-server/README.md index b4d370f61..7fdd3b716 100644 --- a/ojp-server/README.md +++ b/ojp-server/README.md @@ -1,8 +1,25 @@ ## Docker Image -### Build docker image locally +The base image is a custom Alpine JRE built with `jlink` (only the modules required by OJP), bringing the final image size to **68MB**. -> mvn compile jib:dockerBuild +### Build the base image (first time or when dependencies change) + +```bash +# From the repository root +docker build -f ojp-server/base.Dockerfile -t rrobetti/ojp-base:jre24-alpine . +``` + +### Build the app image locally + +```bash +mvn -pl ojp-server/ jib:dockerBuild -Djib.from.image=docker://rrobetti/ojp-base:jre24-alpine +``` + +### Run locally + +```bash +docker run -p 1059:1059 rrobetti/ojp:0.4.9-SNAPSHOT +``` ### Build and push to Docker Hub PS: Only authorized users. diff --git a/ojp-server/base.Dockerfile b/ojp-server/base.Dockerfile new file mode 100644 index 000000000..3ae647018 --- /dev/null +++ b/ojp-server/base.Dockerfile @@ -0,0 +1,14 @@ +FROM eclipse-temurin:24-jdk-alpine AS jre-build + +RUN jlink \ + --add-modules java.base,java.compiler,java.desktop,java.management,java.naming,java.rmi,java.scripting,java.security.jgss,java.sql,jdk.httpserver,jdk.unsupported \ + --strip-debug \ + --no-man-pages \ + --no-header-files \ + --compress=zip-6 \ + --output /custom-jre + +FROM alpine:3.21 +ENV JAVA_HOME=/opt/java +ENV PATH="${JAVA_HOME}/bin:${PATH}" +COPY --from=jre-build /custom-jre $JAVA_HOME diff --git a/ojp-server/pom.xml b/ojp-server/pom.xml index af0b24cdc..b37d3b002 100644 --- a/ojp-server/pom.xml +++ b/ojp-server/pom.xml @@ -308,7 +308,7 @@ ${jib.plugin.version} - eclipse-temurin:22-jre + rrobetti/ojp-base:jre24-alpine rrobetti/ojp:${project.version} From 1e54774e25bc156187142c1ae92a98fe6ff628f6 Mon Sep 17 00:00:00 2001 From: Gabriel Cunha Date: Sat, 16 May 2026 22:51:21 -0300 Subject: [PATCH 2/2] changing the image size, considering the image that runs the app --- ojp-server/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ojp-server/README.md b/ojp-server/README.md index 0c3258d97..c36756a30 100644 --- a/ojp-server/README.md +++ b/ojp-server/README.md @@ -1,6 +1,6 @@ ## Docker Image -The base image is a custom Alpine JRE built with `jlink` (only the modules required by OJP), bringing the final image size to **68MB**. +The base image is a custom Alpine JRE built with `jlink` (only the modules required by OJP), bringing the final image size to **128MB**. ### Build the base image (first time or when dependencies change)