Skip to content

Commit 25ceb27

Browse files
authored
Merge pull request quarkusio#49722 from geoand/quarkusio#49716
Make Docker detection silent in Dev Services
2 parents 3e10677 + 9ebaddf commit 25ceb27

File tree

4 files changed

+57
-17
lines changed

4 files changed

+57
-17
lines changed

core/deployment/src/main/java/io/quarkus/deployment/IsContainerRuntimeWorking.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Result get() {
8888

8989
boolean isAvailable = (boolean) dockerClientFactoryClass.getMethod("isDockerAvailable")
9090
.invoke(dockerClientFactoryInstance);
91-
if (!isAvailable) {
91+
if (!isAvailable && !silent) {
9292
compressor.closeAndDumpCaptured();
9393
}
9494

@@ -117,6 +117,15 @@ public Result get() {
117117
*/
118118
protected static class DockerHostStrategy implements Strategy {
119119
private static final String UNIX_SCHEME = "unix";
120+
private final boolean silent;
121+
122+
public DockerHostStrategy() {
123+
this.silent = false;
124+
}
125+
126+
public DockerHostStrategy(boolean silent) {
127+
this.silent = silent;
128+
}
120129

121130
@Override
122131
public Result get() {
@@ -136,19 +145,23 @@ public Result get() {
136145
if (Files.isWritable(dockerSocketPath)) {
137146
return Result.AVAILABLE;
138147
} else {
139-
LOGGER.warnf(
140-
"Unix socket defined in DOCKER_HOST %s is not writable, make sure Docker is running on the specified host",
141-
dockerHost);
148+
if (!silent) {
149+
LOGGER.warnf(
150+
"Unix socket defined in DOCKER_HOST %s is not writable, make sure Docker is running on the specified host",
151+
dockerHost);
152+
}
142153
}
143154
} else {
144155
try (Socket s = new Socket()) {
145156
s.connect(new InetSocketAddress(dockerHostUri.getHost(), dockerHostUri.getPort()),
146157
DOCKER_HOST_CHECK_TIMEOUT);
147158
return Result.AVAILABLE;
148159
} catch (IOException e) {
149-
LOGGER.warnf(
150-
"Unable to connect to DOCKER_HOST URI %s, make sure Docker is running on the specified host",
151-
dockerHost);
160+
if (!silent) {
161+
LOGGER.warnf(
162+
"Unable to connect to DOCKER_HOST URI %s, make sure Docker is running on the specified host",
163+
dockerHost);
164+
}
152165
}
153166
}
154167
} catch (URISyntaxException | IllegalArgumentException e) {

core/deployment/src/main/java/io/quarkus/deployment/IsDockerWorking.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ public IsDockerWorking() {
1414
}
1515

1616
public IsDockerWorking(boolean silent) {
17-
super(List.of(new TestContainersStrategy(silent), new DockerHostStrategy(), new DockerBinaryStrategy()));
17+
super(List.of(new TestContainersStrategy(silent), new DockerHostStrategy(silent), new DockerBinaryStrategy(silent)));
1818
}
1919

2020
private static class DockerBinaryStrategy implements Strategy {
21+
private final boolean silent;
22+
23+
public DockerBinaryStrategy(boolean silent) {
24+
this.silent = silent;
25+
}
26+
2127
@Override
2228
public Result get() {
23-
if (ContainerRuntimeUtil.detectContainerRuntime(false,
29+
if (ContainerRuntimeUtil.detectContainerRuntime(false, silent,
2430
ContainerRuntime.DOCKER, ContainerRuntime.PODMAN) != UNAVAILABLE) {
2531
return Result.AVAILABLE;
2632
} else {

core/deployment/src/main/java/io/quarkus/deployment/IsPodmanWorking.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ public IsPodmanWorking() {
1515
public IsPodmanWorking(boolean silent) {
1616
super(List.of(
1717
new TestContainersStrategy(silent),
18-
new DockerHostStrategy(),
19-
new PodmanBinaryStrategy()));
18+
new DockerHostStrategy(silent),
19+
new PodmanBinaryStrategy(silent)));
2020
}
2121

2222
private static class PodmanBinaryStrategy implements Strategy {
23+
private final boolean silent;
24+
25+
public PodmanBinaryStrategy(boolean silent) {
26+
this.silent = silent;
27+
}
28+
2329
@Override
2430
public Result get() {
25-
if (ContainerRuntimeUtil.detectContainerRuntime(false, ContainerRuntime.PODMAN) != UNAVAILABLE) {
31+
if (ContainerRuntimeUtil.detectContainerRuntime(false, silent, ContainerRuntime.PODMAN) != UNAVAILABLE) {
2632
return Result.AVAILABLE;
2733
} else {
2834
return Result.UNKNOWN;

core/deployment/src/main/java/io/quarkus/deployment/util/ContainerRuntimeUtil.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,19 @@ public static ContainerRuntime detectContainerRuntime(boolean required, Containe
5050
: List.of(ContainerRuntime.DOCKER, ContainerRuntime.PODMAN));
5151
}
5252

53+
public static ContainerRuntime detectContainerRuntime(boolean required, boolean silent,
54+
ContainerRuntime... orderToCheckRuntimes) {
55+
return detectContainerRuntime(required, silent,
56+
((orderToCheckRuntimes != null) && (orderToCheckRuntimes.length > 0)) ? Arrays.asList(orderToCheckRuntimes)
57+
: List.of(ContainerRuntime.DOCKER, ContainerRuntime.PODMAN));
58+
}
59+
5360
public static ContainerRuntime detectContainerRuntime(boolean required, List<ContainerRuntime> orderToCheckRuntimes) {
61+
return detectContainerRuntime(required, false, orderToCheckRuntimes);
62+
}
63+
64+
public static ContainerRuntime detectContainerRuntime(boolean required, boolean silent,
65+
List<ContainerRuntime> orderToCheckRuntimes) {
5466
ContainerRuntime containerRuntime = loadContainerRuntimeFromSystemProperty();
5567
if ((containerRuntime != null) && orderToCheckRuntimes.contains(containerRuntime)) {
5668
return containerRuntime;
@@ -69,7 +81,7 @@ public static ContainerRuntime detectContainerRuntime(boolean required, List<Con
6981
}
7082

7183
// we have a working container environment, let's resolve it fully
72-
containerRuntime = fullyResolveContainerRuntime(containerRuntimeEnvironment);
84+
containerRuntime = fullyResolveContainerRuntime(containerRuntimeEnvironment, silent);
7385

7486
storeContainerRuntimeInSystemProperty(containerRuntime);
7587

@@ -131,7 +143,8 @@ private static ContainerRuntime getContainerRuntimeEnvironment(List<ContainerRun
131143
return ContainerRuntime.UNAVAILABLE;
132144
}
133145

134-
private static ContainerRuntime fullyResolveContainerRuntime(ContainerRuntime containerRuntimeEnvironment) {
146+
private static ContainerRuntime fullyResolveContainerRuntime(ContainerRuntime containerRuntimeEnvironment,
147+
boolean silent) {
135148
String execName = containerRuntimeEnvironment.getExecutableName();
136149
try {
137150
return ProcessBuilder.newBuilder(execName)
@@ -174,9 +187,11 @@ private static ContainerRuntime fullyResolveContainerRuntime(ContainerRuntime co
174187
})
175188
.run();
176189
} catch (Exception e) {
177-
log.warnf("Command \"%s\" failed. "
178-
+ "Rootless container runtime detection might not be reliable or the container service is not running at all.",
179-
execName);
190+
if (!silent) {
191+
log.warnf("Command \"%s\" failed. "
192+
+ "Rootless container runtime detection might not be reliable or the container service is not running at all.",
193+
execName);
194+
}
180195
return ContainerRuntime.UNAVAILABLE;
181196
}
182197
}

0 commit comments

Comments
 (0)