Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Result get() {

boolean isAvailable = (boolean) dockerClientFactoryClass.getMethod("isDockerAvailable")
.invoke(dockerClientFactoryInstance);
if (!isAvailable) {
if (!isAvailable && !silent) {
compressor.closeAndDumpCaptured();
}

Expand Down Expand Up @@ -117,6 +117,15 @@ public Result get() {
*/
protected static class DockerHostStrategy implements Strategy {
private static final String UNIX_SCHEME = "unix";
private final boolean silent;

public DockerHostStrategy() {
this.silent = false;
}

public DockerHostStrategy(boolean silent) {
this.silent = silent;
}

@Override
public Result get() {
Expand All @@ -136,19 +145,23 @@ public Result get() {
if (Files.isWritable(dockerSocketPath)) {
return Result.AVAILABLE;
} else {
LOGGER.warnf(
"Unix socket defined in DOCKER_HOST %s is not writable, make sure Docker is running on the specified host",
dockerHost);
if (!silent) {
LOGGER.warnf(
"Unix socket defined in DOCKER_HOST %s is not writable, make sure Docker is running on the specified host",
dockerHost);
}
}
} else {
try (Socket s = new Socket()) {
s.connect(new InetSocketAddress(dockerHostUri.getHost(), dockerHostUri.getPort()),
DOCKER_HOST_CHECK_TIMEOUT);
return Result.AVAILABLE;
} catch (IOException e) {
LOGGER.warnf(
"Unable to connect to DOCKER_HOST URI %s, make sure Docker is running on the specified host",
dockerHost);
if (!silent) {
LOGGER.warnf(
"Unable to connect to DOCKER_HOST URI %s, make sure Docker is running on the specified host",
dockerHost);
}
}
}
} catch (URISyntaxException | IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ public IsDockerWorking() {
}

public IsDockerWorking(boolean silent) {
super(List.of(new TestContainersStrategy(silent), new DockerHostStrategy(), new DockerBinaryStrategy()));
super(List.of(new TestContainersStrategy(silent), new DockerHostStrategy(silent), new DockerBinaryStrategy(silent)));
}

private static class DockerBinaryStrategy implements Strategy {
private final boolean silent;

public DockerBinaryStrategy(boolean silent) {
this.silent = silent;
}

@Override
public Result get() {
if (ContainerRuntimeUtil.detectContainerRuntime(false,
if (ContainerRuntimeUtil.detectContainerRuntime(false, silent,
ContainerRuntime.DOCKER, ContainerRuntime.PODMAN) != UNAVAILABLE) {
return Result.AVAILABLE;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ public IsPodmanWorking() {
public IsPodmanWorking(boolean silent) {
super(List.of(
new TestContainersStrategy(silent),
new DockerHostStrategy(),
new PodmanBinaryStrategy()));
new DockerHostStrategy(silent),
new PodmanBinaryStrategy(silent)));
}

private static class PodmanBinaryStrategy implements Strategy {
private final boolean silent;

public PodmanBinaryStrategy(boolean silent) {
this.silent = silent;
}

@Override
public Result get() {
if (ContainerRuntimeUtil.detectContainerRuntime(false, ContainerRuntime.PODMAN) != UNAVAILABLE) {
if (ContainerRuntimeUtil.detectContainerRuntime(false, silent, ContainerRuntime.PODMAN) != UNAVAILABLE) {
return Result.AVAILABLE;
} else {
return Result.UNKNOWN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,19 @@ public static ContainerRuntime detectContainerRuntime(boolean required, Containe
: List.of(ContainerRuntime.DOCKER, ContainerRuntime.PODMAN));
}

public static ContainerRuntime detectContainerRuntime(boolean required, boolean silent,
ContainerRuntime... orderToCheckRuntimes) {
return detectContainerRuntime(required, silent,
((orderToCheckRuntimes != null) && (orderToCheckRuntimes.length > 0)) ? Arrays.asList(orderToCheckRuntimes)
: List.of(ContainerRuntime.DOCKER, ContainerRuntime.PODMAN));
}

public static ContainerRuntime detectContainerRuntime(boolean required, List<ContainerRuntime> orderToCheckRuntimes) {
return detectContainerRuntime(required, false, orderToCheckRuntimes);
}

public static ContainerRuntime detectContainerRuntime(boolean required, boolean silent,
List<ContainerRuntime> orderToCheckRuntimes) {
ContainerRuntime containerRuntime = loadContainerRuntimeFromSystemProperty();
if ((containerRuntime != null) && orderToCheckRuntimes.contains(containerRuntime)) {
return containerRuntime;
Expand All @@ -69,7 +81,7 @@ public static ContainerRuntime detectContainerRuntime(boolean required, List<Con
}

// we have a working container environment, let's resolve it fully
containerRuntime = fullyResolveContainerRuntime(containerRuntimeEnvironment);
containerRuntime = fullyResolveContainerRuntime(containerRuntimeEnvironment, silent);

storeContainerRuntimeInSystemProperty(containerRuntime);

Expand Down Expand Up @@ -131,7 +143,8 @@ private static ContainerRuntime getContainerRuntimeEnvironment(List<ContainerRun
return ContainerRuntime.UNAVAILABLE;
}

private static ContainerRuntime fullyResolveContainerRuntime(ContainerRuntime containerRuntimeEnvironment) {
private static ContainerRuntime fullyResolveContainerRuntime(ContainerRuntime containerRuntimeEnvironment,
boolean silent) {
String execName = containerRuntimeEnvironment.getExecutableName();
try {
return ProcessBuilder.newBuilder(execName)
Expand Down Expand Up @@ -174,9 +187,11 @@ private static ContainerRuntime fullyResolveContainerRuntime(ContainerRuntime co
})
.run();
} catch (Exception e) {
log.warnf("Command \"%s\" failed. "
+ "Rootless container runtime detection might not be reliable or the container service is not running at all.",
execName);
if (!silent) {
log.warnf("Command \"%s\" failed. "
+ "Rootless container runtime detection might not be reliable or the container service is not running at all.",
execName);
}
return ContainerRuntime.UNAVAILABLE;
}
}
Expand Down
Loading