Skip to content

Commit

Permalink
fix: s2i default jvm image is selected based on compiled java ver.
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Jan 27, 2022
1 parent 125879f commit 67a71a0
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
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;

@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";

Expand All @@ -21,17 +23,30 @@ 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.
*/
@ConfigItem(defaultValue = "binary")
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<String> baseJvmImage;

/**
* The base image to be used when a container image is being produced for the native binary build
Expand Down Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,6 +119,7 @@ public void openshiftRequirementsJvm(OpenshiftConfig openshiftConfig,
OutputTargetBuildItem out,
PackageConfig packageConfig,
JarBuildItem jarBuildItem,
CompiledJavaVersionBuildItem compiledJavaVersion,
BuildProducer<DecoratorBuildItem> decorator,
BuildProducer<KubernetesEnvBuildItem> envProducer,
BuildProducer<BaseImageInfoBuildItem> builderImageProducer,
Expand All @@ -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<OpenshiftBaseJavaImage> baseImage = OpenshiftBaseJavaImage.findMatching(config.baseJvmImage);
builderImageProducer.produce(new BaseImageInfoBuildItem(baseJvmImage));
Optional<OpenshiftBaseJavaImage> baseImage = OpenshiftBaseJavaImage.findMatching(baseJvmImage);

if (config.buildStrategy == BuildStrategy.BINARY) {
// Jar directory priorities:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,49 @@
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;

@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<String> baseJvmImage;

/**
* The base image to be used when a container image is being produced for the native binary build
Expand Down Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,33 @@
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;

@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<String> baseJvmImage;

/**
* The base image to be used when a container image is being produced for the native binary build
Expand Down Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,6 +85,7 @@ public void s2iRequirementsJvm(S2iConfig s2iConfig,
OutputTargetBuildItem out,
PackageConfig packageConfig,
JarBuildItem jarBuildItem,
CompiledJavaVersionBuildItem compiledJavaVersion,
BuildProducer<KubernetesEnvBuildItem> envProducer,
BuildProducer<BaseImageInfoBuildItem> builderImageProducer,
BuildProducer<KubernetesCommandBuildItem> commandProducer) {
Expand All @@ -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<S2iBaseJavaImage> baseImage = S2iBaseJavaImage.findMatching(s2iConfig.baseJvmImage);
builderImageProducer.produce(new BaseImageInfoBuildItem(baseJvmImage));
Optional<S2iBaseJavaImage> baseImage = S2iBaseJavaImage.findMatching(baseJvmImage);

baseImage.ifPresent(b -> {
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getJarEnvVar(), pathToJar, OPENSHIFT));
Expand Down

0 comments on commit 67a71a0

Please sign in to comment.