diff --git a/generate.go b/generate.go index c049c09..bcad133 100644 --- a/generate.go +++ b/generate.go @@ -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, @@ -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 = "" diff --git a/generate_test.go b/generate_test.go index 6a62671..3739e73 100644 --- a/generate_test.go +++ b/generate_test.go @@ -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(), @@ -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) @@ -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) @@ -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)