Skip to content

Commit

Permalink
Omit log prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 committed May 27, 2021
1 parent a7e4928 commit ef9abb1
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import com.github.zafarkhaja.semver.Version;
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
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 @@ -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

0 comments on commit ef9abb1

Please sign in to comment.