From 67a71a0294f493c63dc253be8230de87112ccd63 Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Wed, 26 Jan 2022 16:46:14 +0200 Subject: [PATCH] fix: s2i default jvm image is selected based on compiled java ver. --- .../openshift/deployment/OpenshiftConfig.java | 25 ++++++++++--- .../deployment/OpenshiftProcessor.java | 8 +++- .../image/openshift/deployment/S2iConfig.java | 37 ++++++++++++++++--- .../image/s2i/deployment/S2iConfig.java | 19 ++++++++-- .../image/s2i/deployment/S2iProcessor.java | 7 +++- 5 files changed, 78 insertions(+), 18 deletions(-) diff --git a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftConfig.java b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftConfig.java index 3eb6911834ba3..11b85b0353ff3 100644 --- a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftConfig.java +++ b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftConfig.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Optional; +import io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem; import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; @@ -11,7 +12,8 @@ @ConfigRoot(phase = ConfigPhase.BUILD_TIME) public class OpenshiftConfig { - public static final String DEFAULT_BASE_JVM_IMAGE = "registry.access.redhat.com/ubi8/openjdk-11"; + public static final String DEFAULT_BASE_JVM_JDK11_IMAGE = "registry.access.redhat.com/ubi8/openjdk-11:1.11"; + public static final String DEFAULT_BASE_JVM_JDK17_IMAGE = "registry.access.redhat.com/ubi8/openjdk-17:1.11"; public static final String DEFAULT_BASE_NATIVE_IMAGE = "quay.io/quarkus/ubi-quarkus-native-binary-s2i:1.0"; public static final String DEFAULT_NATIVE_TARGET_FILENAME = "application"; @@ -21,6 +23,15 @@ public class OpenshiftConfig { public static final String FALLBACK_JAR_DIRECTORY = "/deployments/"; public static final String FALLBAC_NATIVE_BINARY_DIRECTORY = "/home/quarkus/"; + public static String getDefaultJvmImage(CompiledJavaVersionBuildItem.JavaVersion version) { + switch (version.isJava17OrHigher()) { + case TRUE: + return DEFAULT_BASE_JVM_JDK17_IMAGE; + default: + return DEFAULT_BASE_JVM_JDK11_IMAGE; + } + } + /** * The build config strategy to use. */ @@ -28,10 +39,14 @@ public class OpenshiftConfig { public BuildStrategy buildStrategy; /** - * The base image to be used when a container image is being produced for the jar build + * The base image to be used when a container image is being produced for the jar build. + * + * When the application is built against Java 17 or higher, {@code registry.access.redhat.com/ubi8/openjdk-17:1.11} + * is used as the default. + * Otherwise {@code registry.access.redhat.com/ubi8/openjdk-11:1.11} is used as the default. */ - @ConfigItem(defaultValue = DEFAULT_BASE_JVM_IMAGE) - public String baseJvmImage; + @ConfigItem + public Optional baseJvmImage; /** * The base image to be used when a container image is being produced for the native binary build @@ -103,7 +118,7 @@ public class OpenshiftConfig { * @returns true if baseJvmImage is the default */ public boolean hasDefaultBaseJvmImage() { - return baseJvmImage.equals(DEFAULT_BASE_JVM_IMAGE); + return baseJvmImage.isPresent(); } /** diff --git a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftProcessor.java b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftProcessor.java index c5ac33b959450..671172a2d420e 100644 --- a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftProcessor.java +++ b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/OpenshiftProcessor.java @@ -56,6 +56,7 @@ import io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem; import io.quarkus.deployment.pkg.PackageConfig; import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem; +import io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.deployment.pkg.builditem.JarBuildItem; import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem; @@ -118,6 +119,7 @@ public void openshiftRequirementsJvm(OpenshiftConfig openshiftConfig, OutputTargetBuildItem out, PackageConfig packageConfig, JarBuildItem jarBuildItem, + CompiledJavaVersionBuildItem compiledJavaVersion, BuildProducer decorator, BuildProducer envProducer, BuildProducer builderImageProducer, @@ -126,9 +128,11 @@ public void openshiftRequirementsJvm(OpenshiftConfig openshiftConfig, OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig); String outputJarFileName = jarBuildItem.getPath().getFileName().toString(); String jarFileName = config.jarFileName.orElse(outputJarFileName); + String baseJvmImage = config.baseJvmImage + .orElse(OpenshiftConfig.getDefaultJvmImage(compiledJavaVersion.getJavaVersion())); - builderImageProducer.produce(new BaseImageInfoBuildItem(config.baseJvmImage)); - Optional baseImage = OpenshiftBaseJavaImage.findMatching(config.baseJvmImage); + builderImageProducer.produce(new BaseImageInfoBuildItem(baseJvmImage)); + Optional baseImage = OpenshiftBaseJavaImage.findMatching(baseJvmImage); if (config.buildStrategy == BuildStrategy.BINARY) { // Jar directory priorities: diff --git a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/S2iConfig.java b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/S2iConfig.java index 2f961800e8238..e7a13ff09f3ee 100644 --- a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/S2iConfig.java +++ b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/S2iConfig.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Optional; +import io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem; import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; @@ -11,15 +12,41 @@ @ConfigRoot(phase = ConfigPhase.BUILD_TIME) public class S2iConfig { - public static final String DEFAULT_BASE_JVM_IMAGE = "registry.access.redhat.com/ubi8/openjdk-11"; + public static final String DEFAULT_BASE_JVM_JDK11_IMAGE = "registry.access.redhat.com/ubi8/openjdk-11:1.11"; + public static final String DEFAULT_BASE_JVM_JDK17_IMAGE = "registry.access.redhat.com/ubi8/openjdk-17:1.11"; public static final String DEFAULT_BASE_NATIVE_IMAGE = "quay.io/quarkus/ubi-quarkus-native-binary-s2i:1.0"; public static final String DEFAULT_NATIVE_TARGET_FILENAME = "application"; + public static final String DEFAULT_JVM_DOCKERFILE = "src/main/docker/Dockerfile.jvm"; + public static final String DEFAULT_NATIVE_DOCKERFILE = "src/main/docker/Dockerfile.native"; + + public static final String FALLBACK_JAR_DIRECTORY = "/deployments/"; + public static final String FALLBAC_NATIVE_BINARY_DIRECTORY = "/home/quarkus/"; + + public static String getDefaultJvmImage(CompiledJavaVersionBuildItem.JavaVersion version) { + switch (version.isJava17OrHigher()) { + case TRUE: + return DEFAULT_BASE_JVM_JDK17_IMAGE; + default: + return DEFAULT_BASE_JVM_JDK11_IMAGE; + } + } + /** - * The base image to be used when a container image is being produced for the jar build + * The build config strategy to use. */ - @ConfigItem(defaultValue = DEFAULT_BASE_JVM_IMAGE) - public String baseJvmImage; + @ConfigItem(defaultValue = "binary") + public BuildStrategy buildStrategy; + + /** + * The base image to be used when a container image is being produced for the jar build. + * + * When the application is built against Java 17 or higher, {@code registry.access.redhat.com/ubi8/openjdk-17:1.11} + * is used as the default. + * Otherwise {@code registry.access.redhat.com/ubi8/openjdk-11:1.11} is used as the default. + */ + @ConfigItem + public Optional baseJvmImage; /** * The base image to be used when a container image is being produced for the native binary build @@ -79,7 +106,7 @@ public class S2iConfig { * @returns true if baseJvmImage is the default */ public boolean hasDefaultBaseJvmImage() { - return baseJvmImage.equals(DEFAULT_BASE_JVM_IMAGE); + return baseJvmImage.isPresent(); } /** diff --git a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iConfig.java b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iConfig.java index 8664e350f9d48..f58766bfcd49a 100644 --- a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iConfig.java +++ b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iConfig.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Optional; +import io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem; import io.quarkus.runtime.annotations.ConfigItem; import io.quarkus.runtime.annotations.ConfigPhase; import io.quarkus.runtime.annotations.ConfigRoot; @@ -11,15 +12,25 @@ @ConfigRoot(phase = ConfigPhase.BUILD_TIME) public class S2iConfig { - public static final String DEFAULT_BASE_JVM_IMAGE = "registry.access.redhat.com/ubi8/openjdk-11"; + public static final String DEFAULT_BASE_JVM_JDK11_IMAGE = "registry.access.redhat.com/ubi8/openjdk-11"; + public static final String DEFAULT_BASE_JVM_JDK17_IMAGE = "registry.access.redhat.com/ubi8/openjdk-17"; public static final String DEFAULT_BASE_NATIVE_IMAGE = "quay.io/quarkus/ubi-quarkus-native-binary-s2i:1.0"; public static final String DEFAULT_NATIVE_TARGET_FILENAME = "application"; + public static String getDefaultJvmImage(CompiledJavaVersionBuildItem.JavaVersion version) { + switch (version.isJava17OrHigher()) { + case TRUE: + return DEFAULT_BASE_JVM_JDK17_IMAGE; + default: + return DEFAULT_BASE_JVM_JDK11_IMAGE; + } + } + /** * The base image to be used when a container image is being produced for the jar build */ - @ConfigItem(defaultValue = DEFAULT_BASE_JVM_IMAGE) - public String baseJvmImage; + @ConfigItem + public Optional baseJvmImage; /** * The base image to be used when a container image is being produced for the native binary build @@ -79,7 +90,7 @@ public class S2iConfig { * @returns true if baseJvmImage is the default */ public boolean hasDefaultBaseJvmImage() { - return baseJvmImage.equals(DEFAULT_BASE_JVM_IMAGE); + return baseJvmImage.isPresent(); } /** diff --git a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java index c5e6e6361c684..65a547b07b8de 100644 --- a/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java +++ b/extensions/container-image/container-image-s2i/deployment/src/main/java/io/quarkus/container/image/s2i/deployment/S2iProcessor.java @@ -53,6 +53,7 @@ import io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem; import io.quarkus.deployment.pkg.PackageConfig; import io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem; +import io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem; import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; import io.quarkus.deployment.pkg.builditem.JarBuildItem; import io.quarkus.deployment.pkg.builditem.NativeImageBuildItem; @@ -84,6 +85,7 @@ public void s2iRequirementsJvm(S2iConfig s2iConfig, OutputTargetBuildItem out, PackageConfig packageConfig, JarBuildItem jarBuildItem, + CompiledJavaVersionBuildItem compiledJavaVersion, BuildProducer envProducer, BuildProducer builderImageProducer, BuildProducer commandProducer) { @@ -100,9 +102,10 @@ public void s2iRequirementsJvm(S2iConfig s2iConfig, String jarFileName = s2iConfig.jarFileName.orElse(outputJarFileName); String jarDirectory = s2iConfig.jarDirectory; String pathToJar = concatUnixPaths(jarDirectory, jarFileName); + String baseJvmImage = s2iConfig.baseJvmImage.orElse(S2iConfig.getDefaultJvmImage(compiledJavaVersion.getJavaVersion())); - builderImageProducer.produce(new BaseImageInfoBuildItem(s2iConfig.baseJvmImage)); - Optional baseImage = S2iBaseJavaImage.findMatching(s2iConfig.baseJvmImage); + builderImageProducer.produce(new BaseImageInfoBuildItem(baseJvmImage)); + Optional baseImage = S2iBaseJavaImage.findMatching(baseJvmImage); baseImage.ifPresent(b -> { envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getJarEnvVar(), pathToJar, OPENSHIFT));