Skip to content

Commit

Permalink
Merge pull request #13 from matzew/adding_jdk_21_image
Browse files Browse the repository at this point in the history
Adding support for OpenJDK 21/ubi8 image
  • Loading branch information
dmikusa committed Apr 15, 2024
2 parents 946ebe2 + 2514545 commit e6d0d26
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down
68 changes: 66 additions & 2 deletions generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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`))

})
})
}

Expand Down Expand Up @@ -112,6 +156,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(),
Expand Down

0 comments on commit e6d0d26

Please sign in to comment.