From 8bf2c07be232ea9759efc8b0f97496c9f4fe3aea Mon Sep 17 00:00:00 2001 From: Bhargav kodali <115476530+kb019@users.noreply.github.com> Date: Fri, 4 Oct 2024 04:45:24 -0700 Subject: [PATCH] SDK-339: Fix auto Docker setup in Sdk (#297) * docker-fix * add windows pipe for connecting to docker on windows --- .../main/java/org/openmrs/maven/plugins/CreateMySql.java | 8 ++++++-- .../org/openmrs/maven/plugins/utility/DefaultWizard.java | 2 +- .../org/openmrs/maven/plugins/utility/DockerHelper.java | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docker-maven-plugin/src/main/java/org/openmrs/maven/plugins/CreateMySql.java b/docker-maven-plugin/src/main/java/org/openmrs/maven/plugins/CreateMySql.java index d56e2fd7..bceabe54 100644 --- a/docker-maven-plugin/src/main/java/org/openmrs/maven/plugins/CreateMySql.java +++ b/docker-maven-plugin/src/main/java/org/openmrs/maven/plugins/CreateMySql.java @@ -11,12 +11,14 @@ import com.github.dockerjava.api.model.PullResponseItem; import com.github.dockerjava.api.model.Volume; import org.apache.commons.lang.StringUtils; +import com.github.dockerjava.api.command.ListImagesCmd; import org.apache.maven.plugin.MojoExecutionException; import java.io.Closeable; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Collections; import java.util.concurrent.CountDownLatch; /** @@ -62,8 +64,10 @@ public void executeTask() throws MojoExecutionException { } private boolean noMySqlImage(DockerClient docker) { - List mysql = docker.listImagesCmd().withImageNameFilter(MYSQL_8_4_1).exec(); - return mysql.size() == 0; + ListImagesCmd listImagesCmd = docker.listImagesCmd(); + listImagesCmd.getFilters().put("reference", Collections.singletonList(MYSQL_8_4_1)); + List mysql = listImagesCmd.exec(); + return mysql.isEmpty(); } private void createMysqlContainer(DockerClient docker) { diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java index 4126f7b8..d7128cf1 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DefaultWizard.java @@ -971,7 +971,7 @@ private String determineDefaultDockerHost() { private String determineWindowsDockerHost() { if (determineDockerForWindowsHost()) { - return DockerHelper.DEFAULT_HOST_DOCKER_FOR_WINDOWS; + return DockerHelper.DEFAULT_WINDOWS_PIPE_FOR_DOCKER; } else { return determineDockerToolboxHost(); } diff --git a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DockerHelper.java b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DockerHelper.java index e51b5cb3..adc77a51 100644 --- a/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DockerHelper.java +++ b/sdk-commons/src/main/java/org/openmrs/maven/plugins/utility/DockerHelper.java @@ -33,6 +33,7 @@ public class DockerHelper { private static final String DOCKER_HOST_KEY = "dockerHost"; public static final String DEFAULT_DOCKER_HOST_UNIX_SOCKET = "unix:///var/run/docker.sock"; public static final String DEFAULT_HOST_DOCKER_FOR_WINDOWS = "http://127.0.0.1:2375/"; + public static final String DEFAULT_WINDOWS_PIPE_FOR_DOCKER = "npipe:////./pipe/docker_engine"; private static final String DOCKER_HOST_MSG_WINDOWS = "To use dockerized MySQL, You have to pass Docker Host URL to SDK. " + "You should run SDK from docker-machine command line, so SDK can connect to your Docker. Your individual docker host URL can be obtained by calling command" +