From 8d2d6d3f088969c0f48dd2f19e65b96b2981400f Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Mon, 4 Oct 2021 11:05:51 +0300 Subject: [PATCH] Honor explicit container-build=false when container-runtime is set Makes -Dquarkus.native.container-runtime=docker not imply -Dquarkus.native.container-build=true when the latter is explicitly set to false. Additionally makes isContainerBuild checks consistent. I.e. if -Dquarkus.native.container-runtime=podman -Dquarkus.native.container-build=false are passed as parameters Quarkus will not use a builder image. Closes: #20258 --- .../quarkus/deployment/pkg/NativeConfig.java | 6 +++++- .../pkg/steps/NativeImageBuildStep.java | 18 +++--------------- .../client/deployment/KafkaProcessor.java | 2 +- .../deployment/KafkaStreamsProcessor.java | 3 +-- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java index 8af513280303a..ed4721754f7c0 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/NativeConfig.java @@ -171,7 +171,7 @@ public class NativeConfig { * used by default. If docker is not available or is an alias to podman, podman will be used instead as the default. */ @ConfigItem - public boolean containerBuild; + public Optional containerBuild; /** * If this build is done using a remote docker daemon. @@ -179,6 +179,10 @@ public class NativeConfig { @ConfigItem public boolean remoteContainerBuild; + public boolean isContainerBuild() { + return containerBuild.orElse(containerRuntime.isPresent() || remoteContainerBuild); + } + /** * The docker image to use to do the image build */ diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index 5077793e53a04..1eb6b48083755 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -110,7 +110,6 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig, .setRunnerJarName(runnerJar.getFileName().toString()) // the path to native-image is not known now, it is only known at the time the native-sources will be consumed .setNativeImageName(nativeImageName) - .setContainerBuild(nativeConfig.containerRuntime.isPresent() || nativeConfig.containerBuild) .build(); List command = nativeImageArgs.getArgs(); try (FileOutputStream commandFOS = new FileOutputStream(outputDir.resolve("native-image.args").toFile())) { @@ -153,7 +152,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa String noPIE = ""; - boolean isContainerBuild = isContainerBuild(nativeConfig); + boolean isContainerBuild = nativeConfig.isContainerBuild(); if (!isContainerBuild && SystemUtils.IS_OS_LINUX) { noPIE = detectNoPIE(); } @@ -202,7 +201,6 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa .setRunnerJarName(runnerJarName) .setNativeImageName(nativeImageName) .setNoPIE(noPIE) - .setContainerBuild(isContainerBuild) .setGraalVMVersion(graalVMVersion) .build(); @@ -254,13 +252,9 @@ private String getResultingExecutableName(String nativeImageName, boolean isCont return resultingExecutableName; } - public static boolean isContainerBuild(NativeConfig nativeConfig) { - return nativeConfig.containerRuntime.isPresent() || nativeConfig.containerBuild || nativeConfig.remoteContainerBuild; - } - private static NativeImageBuildRunner getNativeImageBuildRunner(NativeConfig nativeConfig, Path outputDir, String nativeImageName, String resultingExecutableName) { - if (!isContainerBuild(nativeConfig)) { + if (!nativeConfig.isContainerBuild()) { NativeImageBuildLocalRunner localRunner = getNativeImageBuildLocalRunner(nativeConfig, outputDir.toFile()); if (localRunner != null) { return localRunner; @@ -482,7 +476,6 @@ static class Builder { private Path outputDir; private String runnerJarName; private String noPIE = ""; - private boolean isContainerBuild = false; private GraalVM.Version graalVMVersion = GraalVM.Version.UNVERSIONED; private String nativeImageName; private boolean classpathIsBroken; @@ -533,11 +526,6 @@ public Builder setNoPIE(String noPIE) { return this; } - public Builder setContainerBuild(boolean containerBuild) { - isContainerBuild = containerBuild; - return this; - } - public Builder setGraalVMVersion(GraalVM.Version graalVMVersion) { this.graalVMVersion = graalVMVersion; return this; @@ -591,7 +579,7 @@ public NativeImageInvokerInfo build() { enableAllSecurityServices = true; } - handleAdditionalProperties(nativeConfig, nativeImageArgs, isContainerBuild, outputDir); + handleAdditionalProperties(nativeConfig, nativeImageArgs, nativeConfig.isContainerBuild(), outputDir); nativeImageArgs.add( "-H:InitialCollectionPolicy=com.oracle.svm.core.genscavenge.CollectionPolicy$BySpaceAndTime"); //the default collection policy results in full GC's 50% of the time nativeImageArgs.add("-H:+JNI"); diff --git a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/KafkaProcessor.java b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/KafkaProcessor.java index 6bdf533c4174f..6ea3fc40bb4a0 100644 --- a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/KafkaProcessor.java +++ b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/KafkaProcessor.java @@ -254,7 +254,7 @@ private void handleSnappy(BuildProducer reflectiveClas String root = "org/xerial/snappy/native/"; // add linux64 native lib when targeting containers - if (nativeConfig.containerRuntime.isPresent() || nativeConfig.containerBuild) { + if (nativeConfig.isContainerBuild()) { String dir = "Linux/x86_64"; String snappyNativeLibraryName = "libsnappyjava.so"; String path = root + dir + "/" + snappyNativeLibraryName; diff --git a/extensions/kafka-streams/deployment/src/main/java/io/quarkus/kafka/streams/deployment/KafkaStreamsProcessor.java b/extensions/kafka-streams/deployment/src/main/java/io/quarkus/kafka/streams/deployment/KafkaStreamsProcessor.java index 8726e68929429..93774a61fbe28 100644 --- a/extensions/kafka-streams/deployment/src/main/java/io/quarkus/kafka/streams/deployment/KafkaStreamsProcessor.java +++ b/extensions/kafka-streams/deployment/src/main/java/io/quarkus/kafka/streams/deployment/KafkaStreamsProcessor.java @@ -32,7 +32,6 @@ import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; import io.quarkus.deployment.builditem.nativeimage.RuntimeReinitializedClassBuildItem; import io.quarkus.deployment.pkg.NativeConfig; -import io.quarkus.deployment.pkg.steps.NativeImageBuildStep; import io.quarkus.kafka.streams.runtime.KafkaStreamsProducer; import io.quarkus.kafka.streams.runtime.KafkaStreamsRecorder; import io.quarkus.kafka.streams.runtime.KafkaStreamsRuntimeConfig; @@ -123,7 +122,7 @@ private void registerClassesThatAreAccessedViaJni(BuildProducer nativeLibs, NativeConfig nativeConfig) { // for RocksDB, either add linux64 native lib when targeting containers - if (NativeImageBuildStep.isContainerBuild(nativeConfig)) { + if (nativeConfig.isContainerBuild()) { nativeLibs.produce(new NativeImageResourceBuildItem("librocksdbjni-linux64.so")); } // otherwise the native lib of the platform this build runs on