Skip to content

Commit

Permalink
Ensure docker-compose uses docker compose when docker-compose executa…
Browse files Browse the repository at this point in the history
…ble is absent.
  • Loading branch information
corneil committed Aug 5, 2024
1 parent 8f6a793 commit 891f982
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.cloud.dataflow.common.test.docker.compose.execution;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -34,7 +35,9 @@ public class DockerComposeExecutable implements Executable {
private static final DockerCommandLocations DOCKER_COMPOSE_LOCATIONS = new DockerCommandLocations(
System.getenv("DOCKER_COMPOSE_LOCATION"),
"/usr/local/bin/docker-compose",
"/usr/bin/docker-compose"
"/usr/bin/docker-compose",
"/usr/local/bin/docker",
"/usr/bin/docker"
);

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

@Override
public String commandName() {
return "docker-compose";
File file = new File(defaultDockerComposePath());
return file.getName().equals("docker-compose") ? "docker-compose" : "docker";
}

@Override
public Process execute(String... commands) throws IOException {
List<String> args = new ArrayList<>();
args.add(defaultDockerComposePath());
String dockerComposePath = defaultDockerComposePath();
args.add(dockerComposePath);
if(commandName().equals("docker")) {
args.add("compose");
}
args.addAll(Arrays.asList(commands));
log.debug("execute:{}", args);
return new ProcessBuilder(args).redirectErrorStream(true).start();
Expand Down Expand Up @@ -98,7 +106,8 @@ public ProjectName projectName() {

@Override
public final String commandName() {
return "docker-compose";
File file = new File(defaultDockerComposePath());
return file.getName().equals("docker-compose") ? "docker-compose" : "docker";
}

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

List<String> args = new ArrayList<>();
args.add(dockerComposePath());
String dockerComposePath = dockerComposePath();
args.add(dockerComposePath);
if(commandName().equals("docker")) {
args.add("compose");
}
// if a single option is provided that starts with - skips the file commands.
if (commands.length > 1 || commands[0].charAt(0) != '-') {
args.addAll(projectName().constructComposeFileCommand());
Expand Down

0 comments on commit 891f982

Please sign in to comment.