From 789e1ba82b537db589bf2a4f473cc4f64701b0ab Mon Sep 17 00:00:00 2001 From: Sam Hanes Date: Thu, 10 Jul 2014 15:56:26 -0700 Subject: [PATCH 1/2] Add domainname to allowed container config. Signed-off-by: Sam Hanes --- fig/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fig/service.py b/fig/service.py index c0cc297c..0feb56d8 100644 --- a/fig/service.py +++ b/fig/service.py @@ -11,7 +11,7 @@ from .progress_stream import stream_output, StreamOutputError 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 = { 'link' : 'links', 'port' : 'ports', From 699bbe9ca2c40b16cb89170a806aae793396e058 Mon Sep 17 00:00:00 2001 From: Sam Hanes Date: Thu, 10 Jul 2014 15:56:38 -0700 Subject: [PATCH 2/2] Split the domainname out of qualified hostnames. Docker doesn't like it when a fully qualified hostname is passed in the `hostname` parameter. When an FQDN is provided with `-h` the official CLI puts the first component in `hostname` and the rest in `domainname`. This change replicates that behavior when the user specifies an FQDN in `hostname` in their `fig.yml`. Signed-off-by: Sam Hanes --- fig/service.py | 11 +++++++++++ tests/unit/service_test.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/fig/service.py b/fig/service.py index 0feb56d8..0c198269 100644 --- a/fig/service.py +++ b/fig/service.py @@ -304,6 +304,17 @@ class Service(object): 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: ports = [] all_ports = container_options.get('ports', []) + self.options.get('expose', []) diff --git a/tests/unit/service_test.py b/tests/unit/service_test.py index 8acdc056..fe2c61c3 100644 --- a/tests/unit/service_test.py +++ b/tests/unit/service_test.py @@ -41,4 +41,40 @@ class ServiceTest(unittest.TestCase): self.assertEqual(internal_port, "2000") 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')