|
1 | 1 | package io.quarkus.deployment.util; |
2 | 2 |
|
| 3 | +import java.nio.file.Path; |
3 | 4 | import java.util.ArrayList; |
4 | 5 | import java.util.Arrays; |
5 | 6 | import java.util.List; |
| 7 | +import java.util.Optional; |
6 | 8 | import java.util.regex.Pattern; |
7 | 9 |
|
8 | 10 | import org.eclipse.microprofile.config.ConfigProvider; |
9 | 11 | import org.jboss.logging.Logger; |
10 | 12 |
|
11 | 13 | import io.smallrye.common.os.OS; |
12 | 14 | import io.smallrye.common.process.ProcessBuilder; |
| 15 | +import io.smallrye.common.process.ProcessUtil; |
13 | 16 | import io.smallrye.config.SmallRyeConfig; |
14 | 17 |
|
15 | 18 | public final class ContainerRuntimeUtil { |
@@ -73,8 +76,8 @@ public static ContainerRuntime detectContainerRuntime(boolean required, boolean |
73 | 76 | storeContainerRuntimeInSystemProperty(ContainerRuntime.UNAVAILABLE); |
74 | 77 |
|
75 | 78 | if (required) { |
76 | | - throw new IllegalStateException("No container runtime was found. " |
77 | | - + "Make sure you have either Docker or Podman installed in your environment."); |
| 79 | + throw new IllegalStateException("No container CLI was found. " |
| 80 | + + "Make sure you have either Docker or Podman CLI installed in your environment."); |
78 | 81 | } |
79 | 82 |
|
80 | 83 | return ContainerRuntime.UNAVAILABLE; |
@@ -147,7 +150,14 @@ private static ContainerRuntime fullyResolveContainerRuntime(ContainerRuntime co |
147 | 150 | boolean silent) { |
148 | 151 | String execName = containerRuntimeEnvironment.getExecutableName(); |
149 | 152 | try { |
150 | | - return ProcessBuilder.newBuilder(execName) |
| 153 | + Optional<Path> execPath = ProcessUtil.pathOfCommand(Path.of(execName)); |
| 154 | + if (execPath.isEmpty()) { |
| 155 | + // this should never happen as we have detected the presence of the Docker/Podman CLI before |
| 156 | + throw new IllegalStateException( |
| 157 | + String.format("Unable to find command: %s in $PATH: %s", execName, ProcessUtil.searchPath())); |
| 158 | + } |
| 159 | + |
| 160 | + return ProcessBuilder.newBuilder(execPath.get()) |
151 | 161 | .arguments("info") |
152 | 162 | .output().gatherOnFail(true).processWith(br -> { |
153 | 163 | boolean rootless = false; |
@@ -218,14 +228,20 @@ private static void storeContainerRuntimeInSystemProperty(ContainerRuntime conta |
218 | 228 |
|
219 | 229 | private static String getVersionOutputFor(ContainerRuntime containerRuntime) { |
220 | 230 | String execName = containerRuntime.getExecutableName(); |
| 231 | + Optional<Path> execPath = ProcessUtil.pathOfCommand(Path.of(execName)); |
| 232 | + if (execPath.isEmpty()) { |
| 233 | + log.debugf("Unable to find command %s in $PATH: %s", execName, ProcessUtil.searchPath()); |
| 234 | + return ""; |
| 235 | + } |
| 236 | + |
221 | 237 | try { |
222 | | - return ProcessBuilder.newBuilder(execName) |
| 238 | + return ProcessBuilder.newBuilder(execPath.get()) |
223 | 239 | .arguments("--version") |
224 | 240 | .output().gatherOnFail(true).toSingleString(16384) |
225 | 241 | .run(); |
226 | 242 | } catch (Throwable t) { |
227 | 243 | // If an exception is thrown in the process, just return an empty String |
228 | | - log.debugf(t, "Failure to read version output from %s", execName); |
| 244 | + log.debugf(t, "Failure to read version output from %s", execPath.get()); |
229 | 245 | return ""; |
230 | 246 | } |
231 | 247 | } |
|
0 commit comments