1717
1818import com .github .zafarkhaja .semver .Version ;
1919import com .google .common .base .Strings ;
20+ import com .google .common .base .Suppliers ;
2021import com .google .common .collect .ImmutableList ;
2122import com .palantir .docker .compose .configuration .DockerComposeFiles ;
2223import com .palantir .docker .compose .configuration .ProjectName ;
3132import java .util .List ;
3233import java .util .Optional ;
3334import java .util .concurrent .TimeUnit ;
35+ import java .util .function .Supplier ;
3436import org .apache .commons .io .IOUtils ;
3537import org .apache .commons .lang3 .Validate ;
3638import org .joda .time .Duration ;
4042public final class DefaultDockerCompose implements DockerCompose {
4143
4244 public static final Version VERSION_1_7_0 = Version .valueOf ("1.7.0" );
45+ public static final Version VERSION_1_28_0 = Version .valueOf ("1.28.0" );
4346 private static final Duration LOG_TIMEOUT = Duration .standardMinutes (1 );
4447 private static final Logger log = LoggerFactory .getLogger (DefaultDockerCompose .class );
4548
4649 private final Command command ;
4750 private final DockerMachine dockerMachine ;
4851 private final DockerComposeExecutable rawExecutable ;
52+ private final Supplier <Version > version ;
4953
5054 public DefaultDockerCompose (
5155 DockerComposeFiles dockerComposeFiles , DockerMachine dockerMachine , ProjectName projectName ) {
@@ -62,6 +66,14 @@ public DefaultDockerCompose(DockerComposeExecutable rawExecutable, DockerMachine
6266 this .rawExecutable = rawExecutable ;
6367 this .command = new Command (rawExecutable , log ::trace );
6468 this .dockerMachine = dockerMachine ;
69+ this .version = Suppliers .memoize (() -> {
70+ try {
71+ String versionOutput = command .execute (Command .throwingOnError (), "-v" );
72+ return DockerComposeVersion .parseFromDockerComposeVersion (versionOutput );
73+ } catch (IOException | InterruptedException e ) {
74+ throw new RuntimeException (e );
75+ }
76+ });
6577 }
6678
6779 @ Override
@@ -145,12 +157,7 @@ public String run(
145157
146158 private void verifyDockerComposeVersionAtLeast (Version targetVersion , String message )
147159 throws IOException , InterruptedException {
148- Validate .validState (version ().greaterThanOrEqualTo (targetVersion ), message );
149- }
150-
151- private Version version () throws IOException , InterruptedException {
152- String versionOutput = command .execute (Command .throwingOnError (), "-v" );
153- return DockerComposeVersion .parseFromDockerComposeVersion (versionOutput );
160+ Validate .validState (version .get ().greaterThanOrEqualTo (targetVersion ), message );
154161 }
155162
156163 private static String [] constructFullDockerComposeExecArguments (
@@ -236,7 +243,11 @@ private Optional<String> id(String containerName) throws IOException, Interrupte
236243 private Process logs (String container ) throws IOException , InterruptedException {
237244 verifyDockerComposeVersionAtLeast (
238245 VERSION_1_7_0 , "You need at least docker-compose 1.7 to run docker-compose logs" );
239- return rawExecutable .execute ("logs" , "--no-color" , container );
246+ if (version .get ().lessThan (VERSION_1_28_0 )) {
247+ return rawExecutable .execute ("logs" , "--no-color" , container );
248+ } else {
249+ return rawExecutable .execute ("logs" , "--no-color" , "--no-log-prefix" , container );
250+ }
240251 }
241252
242253 @ Override
0 commit comments