Repository: Kinto/kinto

Issue:
updated default kinto config breaks docker (kinto server not reacheable from host)
In e4e70fb, the default listen ip has been changed to 127.0.0.1.
I couldn't manage to export the port using docker, using this command from the [install documentation](http://kinto.readthedocs.io/en/latest/tutorials/install.html#environment-variables):
```
docker run --env-file kinto.env --link kinto_db:db -p 127.0.0.1:8888:8888 --name kinto_web croco/kinto:latest
```
For instance, when I do `curl http://127.0.0.1:8888` from the host I get `Recv failure: Connection reset by peer`.

When I reverted kinto.ini to listen on 0.0.0.0, curl from the host succeeds.

Maybe there is an environment variable to override the `host` entry in the `server:main` section? Then it would be fine, provided an updated documentation...

This is not visible with the published kinto/kinto-server image, since it's still 5.1. I built my own from master because I needed an armhf image.

Comments:

Patch:
diff --git a/Dockerfile b/Dockerfile
index 714e7d75..663e2611 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -13,7 +13,7 @@ RUN \
     apt-get install -y build-essential git python3-dev libssl-dev libffi-dev libpq-dev; \
     pip3 install -e /code[postgresql,monitoring]; \
     pip3 install kinto-pusher kinto-fxa kinto-attachment ; \
-    kinto --ini $KINTO_INI init --backend=memory; \
+    kinto --ini $KINTO_INI init --host 0.0.0.0 --backend=memory; \
     apt-get remove -y -qq build-essential git python3-dev libssl-dev libffi-dev libpq-dev; \
     apt-get autoremove -y -qq; \
     apt-get clean -y
diff --git a/kinto/__main__.py b/kinto/__main__.py
index b1921857..3b02cf5d 100644
--- a/kinto/__main__.py
+++ b/kinto/__main__.py
@@ -57,6 +57,11 @@ def main(args=None):
                                    dest='backend',
                                    required=False,
                                    default=None)
+            subparser.add_argument('--host',
+                                   help='Host to listen() on.',
+                                   dest='host',
+                                   required=False,
+                                   default='127.0.0.1')
         elif command == 'migrate':
             subparser.add_argument('--dry-run',
                                    action='store_true',
@@ -114,7 +119,7 @@ def main(args=None):
                 except KeyError:
                     pass
 
-        init(config_file, backend)
+        init(config_file, backend, parsed_args['host'])
 
         # Install postgresql libraries if necessary
         if backend == "postgresql":
diff --git a/kinto/config/__init__.py b/kinto/config/__init__.py
index f83aff3a..1406a911 100644
--- a/kinto/config/__init__.py
+++ b/kinto/config/__init__.py
@@ -26,9 +26,10 @@ def render_template(template, destination, **kwargs):
             output.write(rendered)
 
 
-def init(config_file, backend):
+def init(config_file, backend, host='127.0.0.1'):
     values = {}
 
+    values['host'] = host
     values['secret'] = core_utils.random_bytes_hex(32)
 
     values['kinto_version'] = __version__
diff --git a/kinto/config/kinto.tpl b/kinto/config/kinto.tpl
index f180f637..214e17ec 100644
--- a/kinto/config/kinto.tpl
+++ b/kinto/config/kinto.tpl
@@ -4,7 +4,7 @@
 
 [server:main]
 use = egg:waitress#main
-host = 127.0.0.1
+host = {host}
 port = %(http_port)s
 
 


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
index dfe30121..2a20e97a 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -17,6 +17,7 @@ class ConfigTest(unittest.TestCase):
         template = "kinto.tpl"
         dest = tempfile.mktemp()
         config.render_template(template, dest,
+                               host='127.0.0.1',
                                secret='secret',
                                storage_backend='storage_backend',
                                cache_backend='cache_backend',
@@ -41,6 +42,7 @@ class ConfigTest(unittest.TestCase):
         dest = os.path.join(tempfile.mkdtemp(), 'config', 'kinto.ini')
 
         config.render_template("kinto.tpl", dest,
+                               host='127.0.0.1',
                                secret='secret',
                                storage_backend='storage_backend',
                                cache_backend='cache_backend',
@@ -68,6 +70,7 @@ class ConfigTest(unittest.TestCase):
 
         postgresql_url = "postgres://postgres:postgres@localhost/postgres"
         self.assertDictEqual(kwargs, {
+            'host': '127.0.0.1',
             'secret': kwargs['secret'],
             'storage_backend': 'kinto.core.storage.postgresql',
             'cache_backend': 'kinto.core.cache.postgresql',
@@ -90,6 +93,7 @@ class ConfigTest(unittest.TestCase):
 
         self.maxDiff = None  # See the full diff in case of error
         self.assertDictEqual(kwargs, {
+            'host': '127.0.0.1',
             'secret': kwargs['secret'],
             'storage_backend': 'kinto_redis.storage',
             'cache_backend': 'kinto_redis.cache',
@@ -109,6 +113,7 @@ class ConfigTest(unittest.TestCase):
         self.assertEquals(args, ('kinto.tpl', 'kinto.ini'))
 
         self.assertDictEqual(kwargs, {
+            'host': '127.0.0.1',
             'secret': kwargs['secret'],
             'storage_backend': 'kinto.core.storage.memory',
             'cache_backend': 'kinto.core.cache.memory',
@@ -120,26 +125,11 @@ class ConfigTest(unittest.TestCase):
             'config_file_timestamp': strftime('%a, %d %b %Y %H:%M:%S %z')
         })
 
-    def test_render_template_creates_directory_if_necessary(self):
-        temp_path = tempfile.mkdtemp()
-        destination = os.path.join(temp_path, 'config/kinto.ini')
-        config.render_template('kinto.tpl', destination, **{
-            'secret': "abcd-ceci-est-un-secret",
-            'storage_backend': 'kinto.core.storage.memory',
-            'cache_backend': 'kinto.core.cache.memory',
-            'permission_backend': 'kinto.core.permission.memory',
-            'storage_url': '',
-            'cache_url':  '',
-            'permission_url': '',
-            'kinto_version': '',
-            'config_file_timestamp': ''
-        })
-        self.assertTrue(os.path.exists(destination))
-
     def test_render_template_works_with_file_in_cwd(self):
         temp_path = tempfile.mkdtemp()
         os.chdir(temp_path)
         config.render_template('kinto.tpl', 'kinto.ini', **{
+            'host': '127.0.0.1',
             'secret': "abcd-ceci-est-un-secret",
             'storage_backend': 'kinto.core.storage.memory',
             'cache_backend': 'kinto.core.cache.memory',