Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Omit log prefixes
  • Loading branch information
pkoenig10 committed May 27, 2021
commit 0715ff92bd43c0d2d618aafd5907bd6d47e0d696
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.github.zafarkhaja.semver.Version;
import com.google.common.base.Strings;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.palantir.docker.compose.configuration.DockerComposeFiles;
import com.palantir.docker.compose.configuration.ProjectName;
Expand All @@ -31,6 +32,7 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.Validate;
import org.joda.time.Duration;
Expand All @@ -40,12 +42,14 @@
public final class DefaultDockerCompose implements DockerCompose {

public static final Version VERSION_1_7_0 = Version.valueOf("1.7.0");
public static final Version VERSION_1_28_0 = Version.valueOf("1.28.0");
private static final Duration LOG_TIMEOUT = Duration.standardMinutes(1);
private static final Logger log = LoggerFactory.getLogger(DefaultDockerCompose.class);

private final Command command;
private final DockerMachine dockerMachine;
private final DockerComposeExecutable rawExecutable;
private final Supplier<Version> version;

public DefaultDockerCompose(
DockerComposeFiles dockerComposeFiles, DockerMachine dockerMachine, ProjectName projectName) {
Expand All @@ -62,6 +66,14 @@ public DefaultDockerCompose(DockerComposeExecutable rawExecutable, DockerMachine
this.rawExecutable = rawExecutable;
this.command = new Command(rawExecutable, log::trace);
this.dockerMachine = dockerMachine;
this.version = Suppliers.memoize(() -> {
try {
String versionOutput = command.execute(Command.throwingOnError(), "-v");
return DockerComposeVersion.parseFromDockerComposeVersion(versionOutput);
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
});
}

@Override
Expand Down Expand Up @@ -145,12 +157,7 @@ public String run(

private void verifyDockerComposeVersionAtLeast(Version targetVersion, String message)
throws IOException, InterruptedException {
Validate.validState(version().greaterThanOrEqualTo(targetVersion), message);
}

private Version version() throws IOException, InterruptedException {
String versionOutput = command.execute(Command.throwingOnError(), "-v");
return DockerComposeVersion.parseFromDockerComposeVersion(versionOutput);
Validate.validState(version.get().greaterThanOrEqualTo(targetVersion), message);
}

private static String[] constructFullDockerComposeExecArguments(
Expand Down Expand Up @@ -236,7 +243,11 @@ private Optional<String> id(String containerName) throws IOException, Interrupte
private Process logs(String container) throws IOException, InterruptedException {
verifyDockerComposeVersionAtLeast(
VERSION_1_7_0, "You need at least docker-compose 1.7 to run docker-compose logs");
return rawExecutable.execute("logs", "--no-color", container);
if (version.get().lessThan(VERSION_1_28_0)) {
return rawExecutable.execute("logs", "--no-color", container);
} else {
return rawExecutable.execute("logs", "--no-color", "--no-log-prefix", container);
}
}

@Override
Expand Down