17
17
18
18
import com .github .zafarkhaja .semver .Version ;
19
19
import com .google .common .base .Strings ;
20
+ import com .google .common .base .Supplier ;
21
+ import com .google .common .base .Suppliers ;
20
22
import com .google .common .collect .ImmutableList ;
21
23
import com .palantir .docker .compose .configuration .DockerComposeFiles ;
22
24
import com .palantir .docker .compose .configuration .ProjectName ;
40
42
public final class DefaultDockerCompose implements DockerCompose {
41
43
42
44
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" );
43
46
private static final Duration LOG_TIMEOUT = Duration .standardMinutes (1 );
44
47
private static final Logger log = LoggerFactory .getLogger (DefaultDockerCompose .class );
45
48
46
49
private final Command command ;
47
50
private final DockerMachine dockerMachine ;
48
51
private final DockerComposeExecutable rawExecutable ;
52
+ private final Supplier <Version > version ;
49
53
50
54
public DefaultDockerCompose (
51
55
DockerComposeFiles dockerComposeFiles , DockerMachine dockerMachine , ProjectName projectName ) {
@@ -62,6 +66,14 @@ public DefaultDockerCompose(DockerComposeExecutable rawExecutable, DockerMachine
62
66
this .rawExecutable = rawExecutable ;
63
67
this .command = new Command (rawExecutable , log ::trace );
64
68
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
+ });
65
77
}
66
78
67
79
@ Override
@@ -145,12 +157,7 @@ public String run(
145
157
146
158
private void verifyDockerComposeVersionAtLeast (Version targetVersion , String message )
147
159
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 );
154
161
}
155
162
156
163
private static String [] constructFullDockerComposeExecArguments (
@@ -236,7 +243,11 @@ private Optional<String> id(String containerName) throws IOException, Interrupte
236
243
private Process logs (String container ) throws IOException , InterruptedException {
237
244
verifyDockerComposeVersionAtLeast (
238
245
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
+ }
240
251
}
241
252
242
253
@ Override
0 commit comments