瀏覽代碼

New path for docker-compose binary (#90457)

Add 3rd location for Docker Compose:
1. /usr/local/bin/docker-compose
2. /usr/bin/docker-compose
3. /usr/libexec/docker/cli-plugins/docker-compose

The 3rd location was found in Docker 20.10.18, Docker Compose version v2.10.2 on Ubuntu.
Justin Cranford 3 年之前
父節點
當前提交
8d8e4377ea

+ 10 - 1
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/docker/DockerSupportService.java

@@ -48,7 +48,10 @@ public abstract class DockerSupportService implements BuildService<DockerSupport
     private static final Logger LOGGER = Logging.getLogger(DockerSupportService.class);
     // Defines the possible locations of the Docker CLI. These will be searched in order.
     private static final String[] DOCKER_BINARIES = { "/usr/bin/docker", "/usr/local/bin/docker" };
-    private static final String[] DOCKER_COMPOSE_BINARIES = { "/usr/local/bin/docker-compose", "/usr/bin/docker-compose" };
+    private static final String[] DOCKER_COMPOSE_BINARIES = {
+        "/usr/local/bin/docker-compose",
+        "/usr/bin/docker-compose",
+        "/usr/libexec/docker/cli-plugins/docker-compose" };
     private static final Version MINIMUM_DOCKER_VERSION = Version.fromString("17.05.0");
 
     private final ExecOperations execOperations;
@@ -67,6 +70,7 @@ public abstract class DockerSupportService implements BuildService<DockerSupport
     public DockerAvailability getDockerAvailability() {
         if (this.dockerAvailability == null) {
             String dockerPath = null;
+            String dockerComposePath = null;
             Result lastResult = null;
             Version version = null;
             boolean isVersionHighEnough = false;
@@ -98,6 +102,7 @@ public abstract class DockerSupportService implements BuildService<DockerSupport
                         Optional<String> composePath = getDockerComposePath();
                         if (lastResult.isSuccess() && composePath.isPresent()) {
                             isComposeAvailable = runCommand(composePath.get(), "version").isSuccess();
+                            dockerComposePath = composePath.get();
                         }
 
                         // Now let's check if buildx is available and what supported platforms exist
@@ -129,6 +134,7 @@ public abstract class DockerSupportService implements BuildService<DockerSupport
                 isComposeAvailable,
                 isVersionHighEnough,
                 dockerPath,
+                dockerComposePath,
                 version,
                 lastResult,
                 supportedArchitectures
@@ -357,6 +363,9 @@ public abstract class DockerSupportService implements BuildService<DockerSupport
         // The path to the Docker CLI, or null
         String path,
 
+        // The path to the Docker Compose CLI, or null
+        String dockerComposePath,
+
         // The installed Docker version, or null
         Version version,
 

+ 13 - 2
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/testfixtures/TestFixturesPlugin.java

@@ -30,6 +30,7 @@ import org.gradle.api.logging.Logging;
 import org.gradle.api.plugins.BasePlugin;
 import org.gradle.api.plugins.ExtraPropertiesExtension;
 import org.gradle.api.provider.Provider;
+import org.gradle.api.provider.ProviderFactory;
 import org.gradle.api.tasks.TaskContainer;
 import org.gradle.api.tasks.TaskProvider;
 import org.gradle.api.tasks.testing.Test;
@@ -49,6 +50,13 @@ public class TestFixturesPlugin implements Plugin<Project> {
     private static final String DOCKER_COMPOSE_THROTTLE = "dockerComposeThrottle";
     static final String DOCKER_COMPOSE_YML = "docker-compose.yml";
 
+    private final ProviderFactory providerFactory;
+
+    @Inject
+    public TestFixturesPlugin(ProviderFactory providerFactory) {
+        this.providerFactory = providerFactory;
+    }
+
     @Inject
     protected FileSystemOperations getFileSystemOperations() {
         throw new UnsupportedOperationException();
@@ -109,8 +117,11 @@ public class TestFixturesPlugin implements Plugin<Project> {
             ComposeExtension composeExtension = project.getExtensions().getByType(ComposeExtension.class);
             composeExtension.getUseComposeFiles().addAll(Collections.singletonList(DOCKER_COMPOSE_YML));
             composeExtension.getRemoveContainers().set(true);
-            composeExtension.getExecutable()
-                .set(project.file("/usr/local/bin/docker-compose").exists() ? "/usr/local/bin/docker-compose" : "/usr/bin/docker-compose");
+            composeExtension.getExecutable().set(this.providerFactory.provider(() -> {
+                String composePath = dockerSupport.get().getDockerAvailability().dockerComposePath();
+                LOGGER.debug("Docker Compose path: {}", composePath);
+                return composePath != null ? composePath : "/usr/bin/docker-compose";
+            }));
 
             tasks.named("composeUp").configure(t -> {
                 // Avoid running docker-compose tasks in parallel in CI due to some issues on certain Linux distributions