From 10ec6807d3b615494b3f7b295a396de7db531a19 Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Tue, 27 Feb 2024 07:39:13 +0100 Subject: [PATCH 1/2] :dizzy: Adding support for OpenJDK-21 image Signed-off-by: Matthias Wessendorf --- README.md | 8 ++++---- generate.go | 3 +++ generate_test.go | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3b5a126..29ddd8c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ The Java Extension for [UBI](https://www.redhat.com/en/blog/introducing-red-hat-universal-base-image) allows builders to be created that can build Java applications on top of Red Hat's Java UBI containers. For example -[ubi8/openjdk-17-runtime](https://catalog.redhat.com/software/containers/ubi8/openjdk-17-runtime/618bdc5f843af1624c4e4ba8). +[ubi8/openjdk-21-runtime](https://catalog.redhat.com/software/containers/ubi8/openjdk-21-runtime/653fd184292263c0a2f14d69). ## Integration @@ -34,9 +34,9 @@ The extension will do the following if a JDK or JRE is requested: ## Configuration -| Environment Variable | Description | -| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `$BP_JVM_VERSION` | Configure the JVM version (e.g. `8`, `11`, `17`). The extension will install rpms that provide a level of Java that is compatible with this version of the JVM specification. UBI only provides a single version of each supported line, patch releases etc can change the exact version of the JDK or JRE. Builds will be performed with whatever the current version for the select specification is within the UBI release stream. | +| Environment Variable | Description | +| ----------------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `$BP_JVM_VERSION` | Configure the JVM version (e.g. `8`, `11`, `17`, `21`). The extension will install rpms that provide a level of Java that is compatible with this version of the JVM specification. UBI only provides a single version of each supported line, patch releases etc can change the exact version of the JDK or JRE. Builds will be performed with whatever the current version for the select specification is within the UBI release stream. | ## Limitations. diff --git a/generate.go b/generate.go index bcad133..6167618 100644 --- a/generate.go +++ b/generate.go @@ -148,6 +148,9 @@ func mapRequestedVersionToPackageAndRunImage(requestedVersion string) (packages case "17": buildver = "java-17-openjdk-devel" runver = "paketocommunity/run-java-17-ubi-base" + case "21": + buildver = "java-21-openjdk-devel" + runver = "paketocommunity/run-java-21-ubi-base" default: buildver = "" runver = "" diff --git a/generate_test.go b/generate_test.go index 3739e73..622ceae 100644 --- a/generate_test.go +++ b/generate_test.go @@ -112,6 +112,26 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) { os.Unsetenv("BP_UBI_RUN_IMAGE_OVERRIDE") }) + it("Java version 21 recognised", func() { + generateResult, err = ubijavaextension.Generate()(libjvm.GenerateContentContext{ + Logger: log.NewDiscardLogger(), + ConfigurationResolver: libpak.ConfigurationResolver{Configurations: []libpak.BuildModuleConfiguration{ + {Name: "BP_JVM_VERSION", Default: "21"}, + }}, + }) + Expect(err).NotTo(HaveOccurred()) + Expect(generateResult.BuildDockerfile).NotTo(BeNil()) + Expect(generateResult.RunDockerfile).NotTo(BeNil()) + + buf := new(strings.Builder) + _, _ = io.Copy(buf, generateResult.RunDockerfile) + Expect(buf.String()).To(ContainSubstring("paketocommunity/run-java-21-ubi-base")) + + buf.Reset() + _, _ = io.Copy(buf, generateResult.BuildDockerfile) + Expect(buf.String()).To(ContainSubstring("java-21-openjdk-devel")) + }) + it("Java version 17 recognised", func() { generateResult, err = ubijavaextension.Generate()(libjvm.GenerateContentContext{ Logger: log.NewDiscardLogger(), From fb7434f32f3ab4e782f1974a0c61c2b2b68afb83 Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Tue, 27 Feb 2024 08:38:24 +0100 Subject: [PATCH 2/2] :broom: Adding properties test for OpenJDK-21 Signed-off-by: Matthias Wessendorf --- generate_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/generate_test.go b/generate_test.go index 622ceae..6fac2df 100644 --- a/generate_test.go +++ b/generate_test.go @@ -42,7 +42,7 @@ func testFillPropsToTemplate(t *testing.T, context spec.G, it spec.S) { context("Adding props on templates with FillPropsToTemplate", func() { - it("Should fill with properties the template/build.Dockerfile", func() { + it("Java version 17: Should fill with properties the template/build.Dockerfile", func() { buildDockerfileProps := BuildDockerfileProps{ JAVA_VERSION: "17", @@ -73,7 +73,7 @@ USER 1000:1000`)) }) - it("Should fill with properties the template/run.Dockerfile", func() { + it("Java version 17: Should fill with properties the template/run.Dockerfile", func() { RunDockerfileProps := RunDockerfileProps{ Source: "paketo-buildpacks/ubi8-paketo-run-java-17", @@ -85,6 +85,50 @@ USER 1000:1000`)) Expect(output).To(Equal(`FROM paketo-buildpacks/ubi8-paketo-run-java-17`)) }) + + it("Java version 21: Should fill with properties the template/build.Dockerfile", func() { + + buildDockerfileProps := BuildDockerfileProps{ + JAVA_VERSION: "21", + CNB_USER_ID: 1000, + CNB_GROUP_ID: 1000, + CNB_STACK_ID: "ubi8-paketo", + PACKAGES: "openssl-devel java-21-openjdk-devel nss_wrapper which", + JAVA_EXTENSION_HELPERS: "helper1, helper2", + } + + output, err := ubijavaextension.FillPropsToTemplate(buildDockerfileProps, buildDockerfileTemplate) + + Expect(err).NotTo(HaveOccurred()) + Expect(output).To(Equal(`ARG base_image +FROM ${base_image} + +USER root + +ARG build_id=0 +RUN echo ${build_id} + +RUN microdnf --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install -y openssl-devel java-21-openjdk-devel nss_wrapper which && microdnf clean all + +RUN echo "21" > /bpi.paketo.ubi.java.version +RUN echo "helper1, helper2" > /bpi.paketo.ubi.java.helpers + +USER 1000:1000`)) + + }) + + it("Java version 21: Should fill with properties the template/run.Dockerfile", func() { + + RunDockerfileProps := RunDockerfileProps{ + Source: "paketo-buildpacks/ubi8-paketo-run-java-21", + } + + output, err := ubijavaextension.FillPropsToTemplate(RunDockerfileProps, runDockerfileTemplate) + + Expect(err).NotTo(HaveOccurred()) + Expect(output).To(Equal(`FROM paketo-buildpacks/ubi8-paketo-run-java-21`)) + + }) }) }