Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize podman vs. podman.exe and Podman Desktop #33720

Merged
merged 1 commit into from
Jun 1, 2023
Merged
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 @@ -7,19 +7,20 @@
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

import io.smallrye.common.os.OS;
import io.smallrye.config.SmallRyeConfig;

public final class ContainerRuntimeUtil {

private static final Logger log = Logger.getLogger(ContainerRuntimeUtil.class);
private static final String CONTAINER_EXECUTABLE = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class)
.getOptionalValue("quarkus.native.container-runtime", String.class).orElse(null);
private static final Pattern PODMAN_PATTERN = Pattern.compile("^podman(?:\\.exe)? version.*", Pattern.DOTALL);

/**
* Static variable is not used because the class gets loaded by different classloaders at
Expand All @@ -44,7 +45,7 @@ public static ContainerRuntime detectContainerRuntime(boolean required) {
return containerRuntime;
}

ContainerRuntime containerRuntimeEnvironment = getContainerRuntimeEnvironment();
final ContainerRuntime containerRuntimeEnvironment = getContainerRuntimeEnvironment();
if (containerRuntimeEnvironment == ContainerRuntime.UNAVAILABLE) {
storeContainerRuntimeInSystemProperty(ContainerRuntime.UNAVAILABLE);

Expand Down Expand Up @@ -83,7 +84,7 @@ private static ContainerRuntime getContainerRuntimeEnvironment() {
}
if (CONTAINER_EXECUTABLE.trim().equalsIgnoreCase("podman")) {
podmanVersionOutput = getVersionOutputFor(ContainerRuntime.PODMAN);
podmanAvailable = podmanVersionOutput.startsWith("podman version");
podmanAvailable = PODMAN_PATTERN.matcher(podmanVersionOutput).matches();
if (podmanAvailable) {
return ContainerRuntime.PODMAN;
}
Expand All @@ -96,15 +97,13 @@ private static ContainerRuntime getContainerRuntimeEnvironment() {
dockerAvailable = dockerVersionOutput.contains("Docker version");
if (dockerAvailable) {
// Check if "docker" is an alias to "podman"
if (dockerVersionOutput.startsWith("podman version") ||
dockerVersionOutput.startsWith("podman.exe version")) {
if (PODMAN_PATTERN.matcher(dockerVersionOutput).matches()) {
return ContainerRuntime.PODMAN;
}
return ContainerRuntime.DOCKER;
}
podmanVersionOutput = getVersionOutputFor(ContainerRuntime.PODMAN);
podmanAvailable = podmanVersionOutput.startsWith("podman version") ||
podmanVersionOutput.startsWith("podman.exe version");
podmanAvailable = PODMAN_PATTERN.matcher(podmanVersionOutput).matches();
Karm marked this conversation as resolved.
Show resolved Hide resolved
if (podmanAvailable) {
return ContainerRuntime.PODMAN;
}
Expand All @@ -130,7 +129,7 @@ private static ContainerRuntime loadContainerRuntimeFromSystemProperty() {
return null;
}

ContainerRuntime containerRuntime = ContainerRuntime.valueOf(runtime);
final ContainerRuntime containerRuntime = ContainerRuntime.of(runtime);

if (containerRuntime == null) {
log.warnf("System property %s contains an unknown value %s. Ignoring it.",
Expand Down Expand Up @@ -225,7 +224,7 @@ public enum ContainerRuntime {
private final boolean rootless;

ContainerRuntime(String executableName, boolean rootless) {
this.executableName = executableName + (OS.current() == OS.WINDOWS ? ".exe" : "");
Karm marked this conversation as resolved.
Show resolved Hide resolved
this.executableName = executableName;
this.rootless = rootless;
}

Expand Down