Skip to content

Commit

Permalink
Merge pull request #7 from BarDweller/main
Browse files Browse the repository at this point in the history
Update Run Image Names, Add Override Env Var, Update tests.
  • Loading branch information
dmikusa authored Nov 1, 2023
2 parents 4cbdb2d + c80229c commit a55e264
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
15 changes: 12 additions & 3 deletions generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ func Generate() libjvm.GenerateContentBuilder {
f := color.New(color.Faint)
ctx.Logger.Body(f.Sprintf("Using UBI Java package %s", buildver))

runOverride, explicit := ctx.ConfigurationResolver.Resolve("BP_UBI_RUN_IMAGE_OVERRIDE")
if explicit {
ctx.Logger.Body(f.Sprintf("Overriding run image with value from BP_UBI_RUN_IMAGE_OVERRIDE"))
runver = runOverride
}

//log choice of run image being selected
ctx.Logger.Body(f.Sprintf("Using UBI Java run image %s", runver))

// Create build.Dockerfile content
buildDockerfileProps := BuildDockerfileProps{
JAVA_VERSION: JAVA_VERSION,
Expand Down Expand Up @@ -132,13 +141,13 @@ func mapRequestedVersionToPackageAndRunImage(requestedVersion string) (packages
switch requestedVersion {
case "8", "1.8", "1.8.0":
buildver = "java-1.8.0-openjdk-devel"
runver = "paketocommunity/ubi8-paketo-run-java-8"
runver = "paketocommunity/run-java-8-ubi-base"
case "11":
buildver = "java-11-openjdk-devel"
runver = "paketocommunity/ubi8-paketo-run-java-11"
runver = "paketocommunity/run-java-11-ubi-base"
case "17":
buildver = "java-17-openjdk-devel"
runver = "paketocommunity/ubi8-paketo-run-java-17"
runver = "paketocommunity/run-java-17-ubi-base"
default:
buildver = ""
runver = ""
Expand Down
31 changes: 28 additions & 3 deletions generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {
Expect(err).NotTo(HaveOccurred())
})

it.After(func() {
os.Unsetenv("BP_UBI_RUN_IMAGE_OVERRIDE")
})

it("Java version 17 recognised", func() {
generateResult, err = ubijavaextension.Generate()(libjvm.GenerateContentContext{
Logger: log.NewDiscardLogger(),
Expand All @@ -121,7 +125,7 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {

buf := new(strings.Builder)
_, _ = io.Copy(buf, generateResult.RunDockerfile)
Expect(buf.String()).To(ContainSubstring("paketocommunity/ubi8-paketo-run-java-17"))
Expect(buf.String()).To(ContainSubstring("paketocommunity/run-java-17-ubi-base"))

buf.Reset()
_, _ = io.Copy(buf, generateResult.BuildDockerfile)
Expand All @@ -141,7 +145,7 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {

buf := new(strings.Builder)
_, _ = io.Copy(buf, generateResult.RunDockerfile)
Expect(buf.String()).To(ContainSubstring("paketocommunity/ubi8-paketo-run-java-8"))
Expect(buf.String()).To(ContainSubstring("paketocommunity/run-java-8-ubi-base"))

buf.Reset()
_, _ = io.Copy(buf, generateResult.BuildDockerfile)
Expand All @@ -161,7 +165,28 @@ func testGenerate(t *testing.T, context spec.G, it spec.S) {

buf := new(strings.Builder)
_, _ = io.Copy(buf, generateResult.RunDockerfile)
Expect(buf.String()).To(ContainSubstring("paketocommunity/ubi8-paketo-run-java-11"))
Expect(buf.String()).To(ContainSubstring("paketocommunity/run-java-11-ubi-base"))

buf.Reset()
_, _ = io.Copy(buf, generateResult.BuildDockerfile)
Expect(buf.String()).To(ContainSubstring("java-11-openjdk-devel"))
})

it("Custom Java version", func() {
os.Setenv("BP_UBI_RUN_IMAGE_OVERRIDE", "stilettos/wibble:latest")
generateResult, err = ubijavaextension.Generate()(libjvm.GenerateContentContext{
Logger: log.NewDiscardLogger(),
ConfigurationResolver: libpak.ConfigurationResolver{Configurations: []libpak.BuildModuleConfiguration{
{Name: "BP_JVM_VERSION", Default: "11"},
}},
})
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("stilettos/wibble:latest"))

buf.Reset()
_, _ = io.Copy(buf, generateResult.BuildDockerfile)
Expand Down

0 comments on commit a55e264

Please sign in to comment.