-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn if Docker for Mac is likely to be slow
As per [docker issue #3419](docker/compose#3419 (comment)), Docker for Mac uses "localunixsocket" instead of "localhost" to resolve sockets, which causes an order of magnitude slowdown (85s vs 5s for LoggingIntegrationTests on my laptop) unless it is explicitly redirected to 127.0.0.1 in /etc/hosts. Check for this condition, and issue a clear warning once per test run.
- Loading branch information
1 parent
e8b8f66
commit 4ae4c66
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...rule-core/src/main/java/com/palantir/docker/compose/execution/DockerForMacHostsIssue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2016 Palantir Technologies, Inc. All rights reserved. | ||
*/ | ||
|
||
package com.palantir.docker.compose.execution; | ||
|
||
import com.google.common.base.Charsets; | ||
import com.google.common.io.Files; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Check whether Mac OS X users have pointed localunixsocket to localhost. | ||
* | ||
* <p>docker-compose takes an order of magnitude longer to run commands without this tip! | ||
* | ||
* @see <a href="https://github.com/docker/compose/issues/3419#issuecomment-221793401">Docker Compose Issue #3419</a> | ||
*/ | ||
public class DockerForMacHostsIssue { | ||
|
||
private static final String REDIRECT_LINE = "127.0.0.1 localunixsocket\n"; | ||
private static final String WARNING_MESSAGE = "\n\n **** WARNING: Your tests may be slow ****\n" | ||
+ "Please add the following line to /etc/hosts:\n " | ||
+ REDIRECT_LINE | ||
+ "\nFor more information, see https://github.com/docker/compose/issues/3419#issuecomment-221793401\n\n"; | ||
private static volatile boolean checkPerformed = false; | ||
|
||
public static void issueWarning() { | ||
if (!checkPerformed) { | ||
if (onMacOsX() && !localunixsocketRedirectedInEtcHosts()) { | ||
System.err.print(WARNING_MESSAGE); | ||
} | ||
} | ||
checkPerformed = true; | ||
} | ||
|
||
private static boolean onMacOsX() { | ||
return System.getProperty("os.name", "generic").equals("Mac OS X"); | ||
} | ||
|
||
private static boolean localunixsocketRedirectedInEtcHosts() { | ||
try { | ||
return Files.toString(new File("/etc/hosts"), Charsets.UTF_8).contains(REDIRECT_LINE); | ||
} catch (IOException e) { | ||
return true; // Better to be silent than issue false warnings | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
issueWarning(); | ||
} | ||
|
||
private DockerForMacHostsIssue() {} | ||
} |