Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JDK 17 support for s2i builds #23215

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
iocanel marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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;
iocanel marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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