From 9f043b1a4ef8598116cd87d6f5ac9de4d92b513f Mon Sep 17 00:00:00 2001 From: Eric Deandrea Date: Mon, 10 Jun 2024 13:23:59 -0400 Subject: [PATCH] Docker-build fails to detect podman Fixes #41085 --- .../io/quarkus/deployment/IsDockerWorking.java | 4 +++- .../io/quarkus/deployment/IsPodmanWorking.java | 7 ++++++- .../deployment/util/ContainerRuntimeUtil.java | 16 ++++++++-------- .../common/deployment/CommonProcessor.java | 12 ++++++------ .../docker/deployment/DockerProcessor.java | 17 +++++++++++++++-- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/IsDockerWorking.java b/core/deployment/src/main/java/io/quarkus/deployment/IsDockerWorking.java index 1efd20d2da3826..19882135e0e292 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/IsDockerWorking.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/IsDockerWorking.java @@ -6,6 +6,7 @@ import java.util.List; import io.quarkus.deployment.util.ContainerRuntimeUtil; +import io.quarkus.deployment.util.ContainerRuntimeUtil.ContainerRuntime; public class IsDockerWorking extends IsContainerRuntimeWorking { public IsDockerWorking() { @@ -19,7 +20,8 @@ public IsDockerWorking(boolean silent) { private static class DockerBinaryStrategy implements Strategy { @Override public Result get() { - if (ContainerRuntimeUtil.detectContainerRuntime(false) != UNAVAILABLE) { + if (ContainerRuntimeUtil.detectContainerRuntime(false, + ContainerRuntime.DOCKER, ContainerRuntime.PODMAN) != UNAVAILABLE) { return Result.AVAILABLE; } else { return Result.UNKNOWN; diff --git a/core/deployment/src/main/java/io/quarkus/deployment/IsPodmanWorking.java b/core/deployment/src/main/java/io/quarkus/deployment/IsPodmanWorking.java index 2a6fce41c656d0..a9e5aa857f1d3a 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/IsPodmanWorking.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/IsPodmanWorking.java @@ -5,6 +5,7 @@ import java.util.List; import io.quarkus.deployment.util.ContainerRuntimeUtil; +import io.quarkus.deployment.util.ContainerRuntimeUtil.ContainerRuntime; public class IsPodmanWorking extends IsContainerRuntimeWorking { public IsPodmanWorking() { @@ -21,7 +22,11 @@ public IsPodmanWorking(boolean silent) { private static class PodmanBinaryStrategy implements Strategy { @Override public Result get() { - return (ContainerRuntimeUtil.detectContainerRuntime(false) != UNAVAILABLE) ? Result.AVAILABLE : Result.UNKNOWN; + if (ContainerRuntimeUtil.detectContainerRuntime(false, ContainerRuntime.PODMAN) != UNAVAILABLE) { + return Result.AVAILABLE; + } else { + return Result.UNKNOWN; + } } } } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/util/ContainerRuntimeUtil.java b/core/deployment/src/main/java/io/quarkus/deployment/util/ContainerRuntimeUtil.java index 10d33810a02a05..97133d8b2a8996 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/util/ContainerRuntimeUtil.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/util/ContainerRuntimeUtil.java @@ -6,6 +6,7 @@ import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Predicate; @@ -42,21 +43,20 @@ private ContainerRuntimeUtil() { * @return a fully resolved {@link ContainerRuntime} indicating if Docker or Podman is available and in rootless mode or not * @throws IllegalStateException if no container runtime was found to build the image */ - public static ContainerRuntime detectContainerRuntime() { - return detectContainerRuntime(true); - } - - public static ContainerRuntime detectContainerRuntime(List orderToCheckRuntimes) { + public static ContainerRuntime detectContainerRuntime(ContainerRuntime... orderToCheckRuntimes) { return detectContainerRuntime(true, orderToCheckRuntimes); } - public static ContainerRuntime detectContainerRuntime(boolean required) { - return detectContainerRuntime(required, List.of(ContainerRuntime.DOCKER, ContainerRuntime.PODMAN)); + public static ContainerRuntime detectContainerRuntime(boolean required, ContainerRuntime... orderToCheckRuntimes) { + return detectContainerRuntime( + required, + ((orderToCheckRuntimes != null) && (orderToCheckRuntimes.length > 0)) ? Arrays.asList(orderToCheckRuntimes) + : List.of(ContainerRuntime.DOCKER, ContainerRuntime.PODMAN)); } public static ContainerRuntime detectContainerRuntime(boolean required, List orderToCheckRuntimes) { ContainerRuntime containerRuntime = loadContainerRuntimeFromSystemProperty(); - if (containerRuntime != null) { + if ((containerRuntime != null) && orderToCheckRuntimes.contains(containerRuntime)) { return containerRuntime; } diff --git a/extensions/container-image/container-image-docker-common/deployment/src/main/java/io/quarkus/container/image/docker/common/deployment/CommonProcessor.java b/extensions/container-image/container-image-docker-common/deployment/src/main/java/io/quarkus/container/image/docker/common/deployment/CommonProcessor.java index ff9e2bbdbc5a70..4e897e013def99 100644 --- a/extensions/container-image/container-image-docker-common/deployment/src/main/java/io/quarkus/container/image/docker/common/deployment/CommonProcessor.java +++ b/extensions/container-image/container-image-docker-common/deployment/src/main/java/io/quarkus/container/image/docker/common/deployment/CommonProcessor.java @@ -56,7 +56,7 @@ protected void buildFromJar(C config, BuildProducer artifactResultProducer, BuildProducer containerImageBuilder, PackageConfig packageConfig, - ContainerRuntime containerRuntime) { + ContainerRuntime... containerRuntimes) { var buildContainerImage = buildContainerImageNeeded(containerImageConfig, buildRequest); var pushContainerImage = pushContainerImageNeeded(containerImageConfig, pushRequest); @@ -84,7 +84,7 @@ protected void buildFromJar(C config, LOGGER.infof("Starting (local) container image build for jar using %s", getProcessorImplementation()); } - var executableName = getExecutableName(config, containerRuntime); + var executableName = getExecutableName(config, containerRuntimes); var builtContainerImage = createContainerImage(containerImageConfig, config, containerImageInfo, out, dockerfilePaths, buildContainerImage, pushContainerImage, packageConfig, executableName); @@ -113,7 +113,7 @@ protected void buildFromNativeImage(C config, BuildProducer containerImageBuilder, PackageConfig packageConfig, NativeImageBuildItem nativeImage, - ContainerRuntime containerRuntime) { + ContainerRuntime... containerRuntimes) { var buildContainerImage = buildContainerImageNeeded(containerImageConfig, buildRequest); var pushContainerImage = pushContainerImageNeeded(containerImageConfig, pushRequest); @@ -134,7 +134,7 @@ protected void buildFromNativeImage(C config, LOGGER.infof("Starting (local) container image build for jar using %s", getProcessorImplementation()); } - var executableName = getExecutableName(config, containerRuntime); + var executableName = getExecutableName(config, containerRuntimes); var dockerfilePaths = getDockerfilePaths(config, true, packageConfig, out); var builtContainerImage = createContainerImage(containerImageConfig, config, containerImage, out, dockerfilePaths, buildContainerImage, pushContainerImage, packageConfig, executableName); @@ -257,9 +257,9 @@ protected RuntimeException containerRuntimeException(String executableName, Stri getProcessorImplementation())); } - private String getExecutableName(C config, ContainerRuntime containerRuntime) { + protected String getExecutableName(C config, ContainerRuntime... containerRuntimes) { return config.executableName() - .orElseGet(() -> detectContainerRuntime(List.of(containerRuntime)).getExecutableName()); + .orElseGet(() -> detectContainerRuntime(containerRuntimes).getExecutableName()); } private DockerfilePaths getDockerfilePaths(C config, diff --git a/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java b/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java index 830e2145594749..a86157df8cd21c 100644 --- a/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java +++ b/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerProcessor.java @@ -61,7 +61,7 @@ public void dockerBuildFromJar(DockerConfig dockerConfig, buildFromJar(dockerConfig, dockerStatusBuildItem, containerImageConfig, out, containerImageInfo, buildRequest, pushRequest, artifactResultProducer, containerImageBuilder, packageConfig, - ContainerRuntime.DOCKER); + ContainerRuntime.DOCKER, ContainerRuntime.PODMAN); } @BuildStep(onlyIf = { IsNormalNotRemoteDev.class, NativeBuild.class, DockerBuild.class }) @@ -81,7 +81,7 @@ public void dockerBuildFromNativeImage(DockerConfig dockerConfig, buildFromNativeImage(dockerConfig, dockerStatusBuildItem, containerImageConfig, containerImage, buildRequest, pushRequest, out, artifactResultProducer, containerImageBuilder, packageConfig, nativeImage, - ContainerRuntime.DOCKER); + ContainerRuntime.DOCKER, ContainerRuntime.PODMAN); } @Override @@ -147,6 +147,19 @@ protected String createContainerImage(ContainerImageConfig containerImageConfig, return containerImageInfo.getImage(); } + @Override + protected String getExecutableName(DockerConfig config, ContainerRuntime... containerRuntimes) { + var executableName = super.getExecutableName(config, containerRuntimes); + + if (!DOCKER.equals(executableName)) { + LOG.warnf( + "Using executable %s within the quarkus-container-image-%s extension. Maybe you should use the quarkus-container-image-%s extension instead?", + executableName, DOCKER, executableName); + } + + return executableName; + } + private String[] getDockerBuildArgs(String image, DockerfilePaths dockerfilePaths, ContainerImageConfig containerImageConfig,