From aef6a6f020801b2c5b778f5e667efa6006140457 Mon Sep 17 00:00:00 2001 From: Philip Walls Date: Sat, 20 Feb 2016 01:18:40 +0000 Subject: [PATCH 1/3] Add support for docker run --tmpfs flag. --- compose/config/config.py | 5 +++++ compose/config/service_schema_v1.json | 1 + compose/config/service_schema_v2.0.json | 1 + compose/service.py | 1 + docs/compose-file.md | 9 +++++++++ docs/extends.md | 4 ++-- tests/integration/service_test.py | 5 +++++ tests/unit/config/config_test.py | 15 +++++++++++++++ 8 files changed, 39 insertions(+), 2 deletions(-) diff --git a/compose/config/config.py b/compose/config/config.py index d0024e9cd50..53aeb5ec451 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -76,6 +76,7 @@ 'shm_size', 'stdin_open', 'stop_signal', + 'tmpfs', 'tty', 'user', 'volume_driver', @@ -580,6 +581,9 @@ def process_service(service_config): if 'extra_hosts' in service_dict: service_dict['extra_hosts'] = parse_extra_hosts(service_dict['extra_hosts']) + if 'tmpfs' in service_dict: + service_dict['tmpfs'] = to_list(service_dict['tmpfs']) + for field in ['dns', 'dns_search']: if field in service_dict: service_dict[field] = to_list(service_dict[field]) @@ -716,6 +720,7 @@ def merge_service_dicts(base, override, version): 'external_links', 'ports', 'volumes_from', + 'tmpfs', ]: md.merge_field(field, operator.add, default=[]) diff --git a/compose/config/service_schema_v1.json b/compose/config/service_schema_v1.json index 4d974d71084..0cd0a415e9b 100644 --- a/compose/config/service_schema_v1.json +++ b/compose/config/service_schema_v1.json @@ -101,6 +101,7 @@ "shm_size": {"type": ["number", "string"]}, "stdin_open": {"type": "boolean"}, "stop_signal": {"type": "string"}, + "tmpfs": {"$ref": "#/definitions/string_or_list"}, "tty": {"type": "boolean"}, "ulimits": { "type": "object", diff --git a/compose/config/service_schema_v2.0.json b/compose/config/service_schema_v2.0.json index edccedc664b..3b64b448fb3 100644 --- a/compose/config/service_schema_v2.0.json +++ b/compose/config/service_schema_v2.0.json @@ -160,6 +160,7 @@ "shm_size": {"type": ["number", "string"]}, "stdin_open": {"type": "boolean"}, "stop_signal": {"type": "string"}, + "tmpfs": {"$ref": "#/definitions/string_or_list"}, "tty": {"type": "boolean"}, "ulimits": { "type": "object", diff --git a/compose/service.py b/compose/service.py index 8b22b7d7580..0b26dfa0943 100644 --- a/compose/service.py +++ b/compose/service.py @@ -655,6 +655,7 @@ def _get_container_host_config(self, override_options, one_off=False): cgroup_parent=options.get('cgroup_parent'), cpu_quota=options.get('cpu_quota'), shm_size=options.get('shm_size'), + tmpfs=options.get('tmpfs'), ) def build(self, no_cache=False, pull=False, force_rm=False): diff --git a/docs/compose-file.md b/docs/compose-file.md index 6441297fe37..6e2b690db97 100644 --- a/docs/compose-file.md +++ b/docs/compose-file.md @@ -213,6 +213,15 @@ Custom DNS search domains. Can be a single value or a list. - dc1.example.com - dc2.example.com +### tmpfs + +RAM disks to mount inside the container. Can be a single value or a list. + + tmpfs: /run + tmpfs: + - /run + - /tmp + ### entrypoint Override the default entrypoint. diff --git a/docs/extends.md b/docs/extends.md index bceb02578a7..1be0622c1a6 100644 --- a/docs/extends.md +++ b/docs/extends.md @@ -316,8 +316,8 @@ Example of build replacing image: # result build: . -For the **multi-value options** `ports`, `expose`, `external_links`, `dns` and -`dns_search`, Compose concatenates both sets of values: +For the **multi-value options** `ports`, `expose`, `external_links`, `dns`, +`dns_search`, and `tmpfs`, Compose concatenates both sets of values: # original service expose: diff --git a/tests/integration/service_test.py b/tests/integration/service_test.py index bcb8733541f..1f0b0ca08b2 100644 --- a/tests/integration/service_test.py +++ b/tests/integration/service_test.py @@ -871,6 +871,11 @@ def test_dns_search(self): container = create_and_start_container(service) self.assertEqual(container.get('HostConfig.DnsSearch'), ['dc1.example.com', 'dc2.example.com']) + def test_tmpfs(self): + service = self.create_service('web', tmpfs=['/run']) + container = create_and_start_container(service) + self.assertEqual(container.get('HostConfig.Tmpfs'), {'/run': ''}) + def test_working_dir_param(self): service = self.create_service('container', working_dir='/working/dir/sample') container = service.create_container() diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index 204003bce51..3913b91dfbe 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -1133,6 +1133,21 @@ def test_normalize_dns_options(self): } ] + def test_tmpfs_option(self): + actual = config.load(build_config_details({ + 'web': { + 'image': 'alpine', + 'tmpfs': '/run', + } + })) + assert actual.services == [ + { + 'name': 'web', + 'image': 'alipine', + 'tmpfs': ['/run'], + } + ] + def test_merge_service_dicts_from_files_with_extends_in_base(self): base = { 'volumes': ['.:/app'], From fdfcaf7ac485284cb068de5fbb43f86ee01c192b Mon Sep 17 00:00:00 2001 From: Philip Walls Date: Sat, 20 Feb 2016 01:32:23 +0000 Subject: [PATCH 2/3] Fix typo in test_tmpfs_option. --- tests/unit/config/config_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index 3913b91dfbe..61d3a762609 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -1143,7 +1143,7 @@ def test_tmpfs_option(self): assert actual.services == [ { 'name': 'web', - 'image': 'alipine', + 'image': 'alpine', 'tmpfs': ['/run'], } ] From 202fd0467ee2612e28a9b89d2862f2468f082c7a Mon Sep 17 00:00:00 2001 From: Philip Walls Date: Sat, 20 Feb 2016 01:32:23 +0000 Subject: [PATCH 3/3] Fix typo in test_tmpfs_option. Signed-off-by: Philip Walls --- tests/unit/config/config_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py index 3913b91dfbe..61d3a762609 100644 --- a/tests/unit/config/config_test.py +++ b/tests/unit/config/config_test.py @@ -1143,7 +1143,7 @@ def test_tmpfs_option(self): assert actual.services == [ { 'name': 'web', - 'image': 'alipine', + 'image': 'alpine', 'tmpfs': ['/run'], } ]