Skip to content

Commit 891f982

Browse files
author
Corneil du Plessis
committed
Ensure docker-compose uses docker compose when docker-compose executable is absent.
1 parent 8f6a793 commit 891f982

File tree

1 file changed

+18
-5
lines changed
  • spring-cloud-dataflow-common/spring-cloud-dataflow-common-test-docker/src/main/java/org/springframework/cloud/dataflow/common/test/docker/compose/execution

1 file changed

+18
-5
lines changed

spring-cloud-dataflow-common/spring-cloud-dataflow-common-test-docker/src/main/java/org/springframework/cloud/dataflow/common/test/docker/compose/execution/DockerComposeExecutable.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.cloud.dataflow.common.test.docker.compose.execution;
1717

18+
import java.io.File;
1819
import java.io.IOException;
1920
import java.util.ArrayList;
2021
import java.util.Arrays;
@@ -34,7 +35,9 @@ public class DockerComposeExecutable implements Executable {
3435
private static final DockerCommandLocations DOCKER_COMPOSE_LOCATIONS = new DockerCommandLocations(
3536
System.getenv("DOCKER_COMPOSE_LOCATION"),
3637
"/usr/local/bin/docker-compose",
37-
"/usr/bin/docker-compose"
38+
"/usr/bin/docker-compose",
39+
"/usr/local/bin/docker",
40+
"/usr/bin/docker"
3841
);
3942

4043
private static String defaultDockerComposePath() {
@@ -52,13 +55,18 @@ static Version version() throws IOException, InterruptedException {
5255

5356
@Override
5457
public String commandName() {
55-
return "docker-compose";
58+
File file = new File(defaultDockerComposePath());
59+
return file.getName().equals("docker-compose") ? "docker-compose" : "docker";
5660
}
5761

5862
@Override
5963
public Process execute(String... commands) throws IOException {
6064
List<String> args = new ArrayList<>();
61-
args.add(defaultDockerComposePath());
65+
String dockerComposePath = defaultDockerComposePath();
66+
args.add(dockerComposePath);
67+
if(commandName().equals("docker")) {
68+
args.add("compose");
69+
}
6270
args.addAll(Arrays.asList(commands));
6371
log.debug("execute:{}", args);
6472
return new ProcessBuilder(args).redirectErrorStream(true).start();
@@ -98,7 +106,8 @@ public ProjectName projectName() {
98106

99107
@Override
100108
public final String commandName() {
101-
return "docker-compose";
109+
File file = new File(defaultDockerComposePath());
110+
return file.getName().equals("docker-compose") ? "docker-compose" : "docker";
102111
}
103112

104113
protected String dockerComposePath() {
@@ -110,7 +119,11 @@ public Process execute(String... commands) throws IOException {
110119
DockerForMacHostsIssue.issueWarning();
111120

112121
List<String> args = new ArrayList<>();
113-
args.add(dockerComposePath());
122+
String dockerComposePath = dockerComposePath();
123+
args.add(dockerComposePath);
124+
if(commandName().equals("docker")) {
125+
args.add("compose");
126+
}
114127
// if a single option is provided that starts with - skips the file commands.
115128
if (commands.length > 1 || commands[0].charAt(0) != '-') {
116129
args.addAll(projectName().constructComposeFileCommand());

0 commit comments

Comments
 (0)