Skip to content

Commit

Permalink
Merge pull request #25 from alenkacz/HostNetworking
Browse files Browse the repository at this point in the history
Fix getting hostname for HOST networking
  • Loading branch information
augi authored Jun 12, 2016
2 parents 84ec061 + c72a656 commit 81fe00a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ class ComposeUp extends DefaultTask {
String gateway
Map<String, Object> networkSettings = inspection.NetworkSettings
Map<String, Object> networks = networkSettings.Networks
if (networks) {
if (networks && networks.every { it.key.toLowerCase().equals("host") }) {
gateway = 'localhost'
logger.debug("Will use $gateway as host of $serviceName because it is using HOST network")
} else if (networks) {
Map.Entry<String, Object> firstNetworkPair = networks.find()
gateway = firstNetworkPair.value.Gateway
logger.debug("Will use $gateway (network ${firstNetworkPair.key}) as host of $serviceName")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,37 @@ class DockerComposePluginTest extends Specification {
''']
}

def "expose localhost as a host for container with HOST networking"() {
def projectDir = new TmpDirTemporaryFileProvider().createTemporaryDirectory("gradle", "projectDir")
new File(projectDir, 'docker-compose.yml') << '''
version: '2'
services:
web:
image: nginx
network_mode: host
ports:
- 80
'''
def project = ProjectBuilder.builder().withProjectDir(projectDir).build()
project.plugins.apply 'java'
project.plugins.apply 'docker-compose'
project.tasks.composeUp.up()
Test test = project.tasks.test as Test
when:
project.dockerCompose.exposeAsEnvironment(test)
project.dockerCompose.exposeAsSystemProperties(test)
then:
test.environment.get('WEB_HOST') == 'localhost'
test.systemProperties.get('web.host') == 'localhost'
cleanup:
project.tasks.composeDown.down()
try {
projectDir.delete()
} catch(ignored) {
projectDir.deleteOnExit()
}
}

def "reads logs of service"() {
def projectDir = new TmpDirTemporaryFileProvider().createTemporaryDirectory("gradle", "projectDir")
new File(projectDir, 'docker-compose.yml') << '''
Expand Down

0 comments on commit 81fe00a

Please sign in to comment.