Skip to content

Commit

Permalink
fix logging for docker/podman check version
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Sep 26, 2023
1 parent 7cb768d commit b7550c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,31 @@ protected String getContainerCommandPrefix() throws PluginExecutionException {
* Throw an exception if there is a problem with the version.
*/
private static final String MIN_DOCKER_VERSION = "18.03.0"; // Must use Docker 18.03.0 or higher
protected void checkDockerVersion() throws PluginExecutionException {
protected boolean checkDockerVersion() throws PluginExecutionException {
String versionCmd = "docker version --format {{.Client.Version}}";
String dockerVersion = execContainerCmd(versionCmd, CONTAINER_TIMEOUT);
if (dockerVersion == null) {
checkPodmanVersion(); // Check Podman version if no Docker
return;
return checkPodmanVersion(); // Check Podman version if no Docker
}
debug("Detected Docker version: " + dockerVersion);

if (VersionUtility.compareArtifactVersion(dockerVersion, MIN_DOCKER_VERSION, false) < 0) {
checkPodmanVersion(); // Check that bad Docker version isn't just a Podman version
if (!isDocker) {
return;
}
throw new PluginExecutionException("The detected Docker client version number is not supported:" + dockerVersion.trim() + ". Docker version must be " + MIN_DOCKER_VERSION + " or higher.");
// Check that bad Docker version isn't just a Podman version
if (!checkPodmanVersion()) {
throw new PluginExecutionException("The detected Docker client version number is not supported:" + dockerVersion.trim() + ". Docker version must be " + MIN_DOCKER_VERSION + " or higher.");
}
}
isDocker = true;
checkedContainerType = true;
return true;
}

private static final String MIN_PODMAN_VERSION = "4.4.4"; // Must use Docker 4.4.4 or higher
private void checkPodmanVersion() throws PluginExecutionException {
private boolean checkPodmanVersion() throws PluginExecutionException {
String versionCmd = "podman version --format {{.Client.Version}}";
String podmanVersion = execContainerCmd(versionCmd, CONTAINER_TIMEOUT);
if (podmanVersion == null) {
return; // Can't tell if the version is valid.
return false; // Can't tell if the version is valid.
}
debug("Detected Podman version: " + podmanVersion);

Expand All @@ -99,6 +98,7 @@ private void checkPodmanVersion() throws PluginExecutionException {
}
isDocker = false;
checkedContainerType = true;
return true;
}

/**
Expand Down Expand Up @@ -137,9 +137,9 @@ protected String execContainerCmd(String command, int timeout, boolean throwExce
error("An interruption error occurred while running a container command: " + e.getMessage(), e);
throw new RuntimeException(e.getMessage());
} catch (IOException e) {
// Logging IOExceptions in info stream. This is thrown if Docker or Podman are not installed on the system.
info("An error occurred while running a container command: " + e.getMessage());
info("This message will occur when Docker or Podman are not installed.");
// Logging IOExceptions in debug stream. This is thrown if Docker or Podman are not installed on the system.
debug("An error occurred while running a container command: " + e.getMessage());
debug("This message will occur when Docker or Podman are not installed.");
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.net.ServerSocket;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
Expand Down Expand Up @@ -81,7 +80,6 @@

import com.sun.nio.file.SensitivityWatchEventModifier;

import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
Expand Down Expand Up @@ -763,7 +761,10 @@ public void startServer(boolean buildContainer, boolean pullParentImage) throws
enableServerDebug();

if (container) {
checkDockerVersion();
if (!checkDockerVersion()) {
// Did not find valid docker or podman installation
throw new PluginExecutionException("Could not find a valid Docker or Podman installation.");
}
}

// build container image if in container mode
Expand Down

0 comments on commit b7550c6

Please sign in to comment.