Skip to content

Commit

Permalink
Merge branch 'master' into kill.dont.stop
Browse files Browse the repository at this point in the history
  • Loading branch information
hpryce authored Feb 15, 2017
2 parents 3726282 + 136ea04 commit 09f8677
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ protected String dockerComposePath() {

@Override
public Process execute(String... commands) throws IOException {
DockerForMacHostsIssue.issueWarning();

List<String> args = ImmutableList.<String>builder()
.add(dockerComposePath())
.addAll(projectName().constructComposeFileCommand())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2016 Palantir Technologies, Inc. All rights reserved.
*/

package com.palantir.docker.compose.execution;

import static java.nio.charset.StandardCharsets.UTF_8;

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"), 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() {}
}

0 comments on commit 09f8677

Please sign in to comment.