Skip to content

Commit

Permalink
Merge pull request #20517 from zakkak/fix-20258
Browse files Browse the repository at this point in the history
Honor explicit container-build=false when container-runtime is set
  • Loading branch information
stuartwdouglas committed Oct 5, 2021
2 parents bdce87f + 8d2d6d3 commit 84d9188
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,18 @@ 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<Boolean> containerBuild;

/**
* If this build is done using a remote docker daemon.
*/
@ConfigItem
public boolean remoteContainerBuild;

public boolean isContainerBuild() {
return containerBuild.orElse(containerRuntime.isPresent() || remoteContainerBuild);
}

/**
* The docker image to use to do the image build
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> command = nativeImageArgs.getArgs();
try (FileOutputStream commandFOS = new FileOutputStream(outputDir.resolve("native-image.args").toFile())) {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -202,7 +201,6 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
.setRunnerJarName(runnerJarName)
.setNativeImageName(nativeImageName)
.setNoPIE(noPIE)
.setContainerBuild(isContainerBuild)
.setGraalVMVersion(graalVMVersion)
.build();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private void handleSnappy(BuildProducer<ReflectiveClassBuildItem> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,7 +122,7 @@ private void registerClassesThatAreAccessedViaJni(BuildProducer<JniRuntimeAccess

private void addSupportForRocksDbLib(BuildProducer<NativeImageResourceBuildItem> 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
Expand Down

0 comments on commit 84d9188

Please sign in to comment.