Skip to content

Commit

Permalink
Merge pull request #20 from remen/master
Browse files Browse the repository at this point in the history
Add logic for Docker for Mac and remove useNetworkGateway
  • Loading branch information
augi committed May 26, 2016
2 parents 250b7b9 + cfd3d90 commit c870300
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dockerCompose {
// removeContainers = false
// removeImages = true
// removeVolumes = false
// useNetworkGateway = false // Connect to localhost instead of gateway. Useful for Docker for Mac.
}
test.doFirst {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class ComposeExtension {
boolean removeContainers = true
boolean removeImages = false
boolean removeVolumes = true
boolean useNetworkGateway = true

ComposeExtension(Project project, ComposeUp upTask, ComposeDown downTask) {
this.project = project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ class ComposeUp extends DefaultTask {
if (dockerHost) {
logger.debug("'DOCKER_HOST environment variable detected - will be used as hostname of service $serviceName'")
new ServiceHost(host: dockerHost.toURI().host, type: ServiceHostType.RemoteDockerHost)
} else if (extension.useNetworkGateway) {
} else if (isMac()) {
// If running on Mac OS and DOCKER_HOST is not set, we can assume that
// we are using Docker for Mac, in which case we should connect to localhost
logger.debug("Will use localhost as host of $serviceName")
new ServiceHost(host: 'localhost', type: ServiceHostType.LocalHost)
} else {
// read gateway of first containers network
String gateway
Map<String, Object> networkSettings = inspection.NetworkSettings
Expand All @@ -115,9 +120,6 @@ class ComposeUp extends DefaultTask {
logger.debug("Will use $gateway as host of $serviceName")
}
new ServiceHost(host: gateway, type: ServiceHostType.NetworkGateway)
} else {
logger.debug("Will use localhost as host of $serviceName")
new ServiceHost(host: 'localhost', type: ServiceHostType.LocalHost)
}
}

Expand Down Expand Up @@ -188,4 +190,8 @@ class ComposeUp extends DefaultTask {
os.toString().trim()
}
}

private static boolean isMac() {
System.getProperty("os.name").toLowerCase().startsWith("mac")
}
}

0 comments on commit c870300

Please sign in to comment.