From af61eb2168283546ffc8b6fdcae1452ac84eddb7 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Tue, 18 Jul 2023 09:28:45 +0300 Subject: [PATCH] Fix container builds when explicitly setting `container-runtime` Looking at how this works right now the process is the following: 1. If the user has set `quarkus.native.container-runtime`, Quarkus uses this verbatim [1] (so if you want rootless you have to say `podman-rootless` instead of just `podman` 2. If `quarkus.native.container-runtime` is not set Quarkus next picks up the system property `quarkus-local-container-runtime` [2], this was introduced in https://github.com/quarkusio/quarkus/pull/31857 and is expected to be set by Quarkus and not the user, so the first time we try to detect the container runtime it should be unset. 3. If the system property is unset, Quarkus then checks the parameter `quarkus.native.container-runtime` (again) [3]. If it's set it uses it to test if the set runtime is available or not. If it's not available it falls back to testing first docker and then podman [4]. As a result, removing step 1 allows Quarkus to properly check the value of `quarkus.native.container-runtime` and fully resolve the runtime. [1] https://github.com/quarkusio/quarkus/blob/f3f97198a3a6892a828540811e0644fad7397acf/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java#L31 [2] https://github.com/quarkusio/quarkus/blob/f652f64823f4c54018344c2c941d9819ca9c3d72/core/runtime/src/main/java/io/quarkus/runtime/util/ContainerRuntimeUtil.java#L43 [3] https://github.com/quarkusio/quarkus/blob/f652f64823f4c54018344c2c941d9819ca9c3d72/core/runtime/src/main/java/io/quarkus/runtime/util/ContainerRuntimeUtil.java#L48 [4] https://github.com/quarkusio/quarkus/blob/f652f64823f4c54018344c2c941d9819ca9c3d72/core/runtime/src/main/java/io/quarkus/runtime/util/ContainerRuntimeUtil.java#L96C1-L111 Closes: #34725 (cherry picked from commit e2d6b366b95623633b5194cd80eba6a2a4128da7) --- .../deployment/pkg/steps/NativeImageBuildContainerRunner.java | 2 +- .../quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java index 15eb300febff0..d826c15c68113 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildContainerRunner.java @@ -28,7 +28,7 @@ public abstract class NativeImageBuildContainerRunner extends NativeImageBuildRu protected NativeImageBuildContainerRunner(NativeConfig nativeConfig) { this.nativeConfig = nativeConfig; - containerRuntime = nativeConfig.containerRuntime().orElseGet(ContainerRuntimeUtil::detectContainerRuntime); + containerRuntime = ContainerRuntimeUtil.detectContainerRuntime(); this.baseContainerRuntimeArgs = new String[] { "--env", "LANG=C", "--rm" }; diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java index c58500f1be332..c9275a0c79b7d 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/UpxCompressionBuildStep.java @@ -104,8 +104,7 @@ private boolean runUpxInContainer(NativeImageBuildItem nativeImage, NativeConfig List extraArgs = nativeConfig.compression().additionalArgs().orElse(Collections.emptyList()); List commandLine = new ArrayList<>(); - ContainerRuntimeUtil.ContainerRuntime containerRuntime = nativeConfig.containerRuntime() - .orElseGet(ContainerRuntimeUtil::detectContainerRuntime); + ContainerRuntimeUtil.ContainerRuntime containerRuntime = ContainerRuntimeUtil.detectContainerRuntime(); commandLine.add(containerRuntime.getExecutableName()); commandLine.add("run");