Sfoglia il codice sorgente

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 <[email protected]>
Sam Hanes 11 anni fa
parent
commit
699bbe9ca2
2 ha cambiato i file con 47 aggiunte e 0 eliminazioni
  1. 11 0
      fig/service.py
  2. 36 0
      tests/unit/service_test.py

+ 11 - 0
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', [])

+ 36 - 0
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')