mirror of https://github.com/docker/compose.git
Merge pull request #304 from Elemecca/t-domainname
add support for domainname, qualified hostname
This commit is contained in:
commit
3996947024
|
@ -11,7 +11,7 @@ from .progress_stream import stream_output, StreamOutputError
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
DOCKER_CONFIG_KEYS = ['image', 'command', 'hostname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'entrypoint', 'privileged', 'volumes_from', 'net', 'working_dir']
|
DOCKER_CONFIG_KEYS = ['image', 'command', 'hostname', 'domainname', 'user', 'detach', 'stdin_open', 'tty', 'mem_limit', 'ports', 'environment', 'dns', 'volumes', 'entrypoint', 'privileged', 'volumes_from', 'net', 'working_dir']
|
||||||
DOCKER_CONFIG_HINTS = {
|
DOCKER_CONFIG_HINTS = {
|
||||||
'link' : 'links',
|
'link' : 'links',
|
||||||
'port' : 'ports',
|
'port' : 'ports',
|
||||||
|
@ -304,6 +304,17 @@ class Service(object):
|
||||||
|
|
||||||
container_options['name'] = self.next_container_name(one_off)
|
container_options['name'] = self.next_container_name(one_off)
|
||||||
|
|
||||||
|
# If a qualified hostname was given, split it into an
|
||||||
|
# unqualified hostname and a domainname unless domainname
|
||||||
|
# was also given explicitly. This matches the behavior of
|
||||||
|
# the official Docker CLI in that scenario.
|
||||||
|
if ('hostname' in container_options
|
||||||
|
and 'domainname' not in container_options
|
||||||
|
and '.' in container_options['hostname']):
|
||||||
|
parts = container_options['hostname'].partition('.')
|
||||||
|
container_options['hostname'] = parts[0]
|
||||||
|
container_options['domainname'] = parts[2]
|
||||||
|
|
||||||
if 'ports' in container_options or 'expose' in self.options:
|
if 'ports' in container_options or 'expose' in self.options:
|
||||||
ports = []
|
ports = []
|
||||||
all_ports = container_options.get('ports', []) + self.options.get('expose', [])
|
all_ports = container_options.get('ports', []) + self.options.get('expose', [])
|
||||||
|
|
|
@ -41,4 +41,40 @@ class ServiceTest(unittest.TestCase):
|
||||||
self.assertEqual(internal_port, "2000")
|
self.assertEqual(internal_port, "2000")
|
||||||
self.assertEqual(external_port, "1000")
|
self.assertEqual(external_port, "1000")
|
||||||
|
|
||||||
|
def test_split_domainname_none(self):
|
||||||
|
service = Service('foo',
|
||||||
|
hostname = 'name',
|
||||||
|
)
|
||||||
|
service.next_container_name = lambda x: 'foo'
|
||||||
|
opts = service._get_container_create_options({})
|
||||||
|
self.assertEqual(opts['hostname'], 'name', 'hostname')
|
||||||
|
self.assertFalse('domainname' in opts, 'domainname')
|
||||||
|
|
||||||
|
def test_split_domainname_fqdn(self):
|
||||||
|
service = Service('foo',
|
||||||
|
hostname = 'name.domain.tld',
|
||||||
|
)
|
||||||
|
service.next_container_name = lambda x: 'foo'
|
||||||
|
opts = service._get_container_create_options({})
|
||||||
|
self.assertEqual(opts['hostname'], 'name', 'hostname')
|
||||||
|
self.assertEqual(opts['domainname'], 'domain.tld', 'domainname')
|
||||||
|
|
||||||
|
def test_split_domainname_both(self):
|
||||||
|
service = Service('foo',
|
||||||
|
hostname = 'name',
|
||||||
|
domainname = 'domain.tld',
|
||||||
|
)
|
||||||
|
service.next_container_name = lambda x: 'foo'
|
||||||
|
opts = service._get_container_create_options({})
|
||||||
|
self.assertEqual(opts['hostname'], 'name', 'hostname')
|
||||||
|
self.assertEqual(opts['domainname'], 'domain.tld', 'domainname')
|
||||||
|
|
||||||
|
def test_split_domainname_weird(self):
|
||||||
|
service = Service('foo',
|
||||||
|
hostname = 'name.sub',
|
||||||
|
domainname = 'domain.tld',
|
||||||
|
)
|
||||||
|
service.next_container_name = lambda x: 'foo'
|
||||||
|
opts = service._get_container_create_options({})
|
||||||
|
self.assertEqual(opts['hostname'], 'name.sub', 'hostname')
|
||||||
|
self.assertEqual(opts['domainname'], 'domain.tld', 'domainname')
|
||||||
|
|
Loading…
Reference in New Issue