diff options
author | Joffrey F <joffrey@docker.com> | 2018-03-29 16:24:56 -0700 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2018-03-29 16:57:07 -0700 |
commit | 2e100353d38a6fb5cf0ad37d0403305ab6c54f65 (patch) | |
tree | 0095e86c86b56d6c9d3e4c49e829a4152b2ce29d | |
parent | bc6b091bff1fb5bf48987caf7be98b58f1f36732 (diff) |
Add support for build isolation parameter
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | compose/config/config.py | 1 | ||||
-rw-r--r-- | compose/config/config_schema_v2.1.json | 3 | ||||
-rw-r--r-- | compose/config/config_schema_v2.2.json | 3 | ||||
-rw-r--r-- | compose/config/config_schema_v2.3.json | 3 | ||||
-rw-r--r-- | compose/service.py | 3 | ||||
-rw-r--r-- | tests/integration/service_test.py | 14 | ||||
-rw-r--r-- | tests/unit/service_test.py | 27 |
7 files changed, 50 insertions, 4 deletions
diff --git a/compose/config/config.py b/compose/config/config.py index 147c1d31..84d2a86a 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -1119,6 +1119,7 @@ def merge_build(output, base, override): md.merge_scalar('network') md.merge_scalar('target') md.merge_scalar('shm_size') + md.merge_scalar('isolation') md.merge_mapping('args', parse_build_arguments) md.merge_field('cache_from', merge_unique_items_lists, default=[]) md.merge_mapping('labels', parse_labels) diff --git a/compose/config/config_schema_v2.1.json b/compose/config/config_schema_v2.1.json index 87a730dd..5ad5a20e 100644 --- a/compose/config/config_schema_v2.1.json +++ b/compose/config/config_schema_v2.1.json @@ -88,7 +88,8 @@ "context": {"type": "string"}, "dockerfile": {"type": "string"}, "args": {"$ref": "#/definitions/list_or_dict"}, - "labels": {"$ref": "#/definitions/labels"} + "labels": {"$ref": "#/definitions/labels"}, + "isolation": {"type": "string"} }, "additionalProperties": false } diff --git a/compose/config/config_schema_v2.2.json b/compose/config/config_schema_v2.2.json index dc707674..26044b65 100644 --- a/compose/config/config_schema_v2.2.json +++ b/compose/config/config_schema_v2.2.json @@ -90,7 +90,8 @@ "args": {"$ref": "#/definitions/list_or_dict"}, "labels": {"$ref": "#/definitions/labels"}, "cache_from": {"$ref": "#/definitions/list_of_strings"}, - "network": {"type": "string"} + "network": {"type": "string"}, + "isolation": {"type": "string"} }, "additionalProperties": false } diff --git a/compose/config/config_schema_v2.3.json b/compose/config/config_schema_v2.3.json index bd7ce166..ac0778f2 100644 --- a/compose/config/config_schema_v2.3.json +++ b/compose/config/config_schema_v2.3.json @@ -93,7 +93,8 @@ "network": {"type": "string"}, "target": {"type": "string"}, "shm_size": {"type": ["integer", "string"]}, - "extra_hosts": {"$ref": "#/definitions/list_or_dict"} + "extra_hosts": {"$ref": "#/definitions/list_or_dict"}, + "isolation": {"type": "string"} }, "additionalProperties": false } diff --git a/compose/service.py b/compose/service.py index 9b03a399..9e5725e0 100644 --- a/compose/service.py +++ b/compose/service.py @@ -1016,7 +1016,8 @@ class Service(object): container_limits={ 'memory': parse_bytes(memory) if memory else None }, - gzip=gzip + gzip=gzip, + isolation=build_opts.get('isolation', self.options.get('isolation', None)), ) try: diff --git a/tests/integration/service_test.py b/tests/integration/service_test.py index 260867fe..d8f4d094 100644 --- a/tests/integration/service_test.py +++ b/tests/integration/service_test.py @@ -1123,6 +1123,20 @@ class ServiceTest(DockerClientTestCase): service.build(gzip=True) assert service.image() + @v2_1_only() + def test_build_with_isolation(self): + base_dir = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, base_dir) + with open(os.path.join(base_dir, 'Dockerfile'), 'w') as f: + f.write('FROM busybox\n') + + service = self.create_service('build_isolation', build={ + 'context': text_type(base_dir), + 'isolation': 'default', + }) + service.build() + assert service.image() + def test_start_container_stays_unprivileged(self): service = self.create_service('web') container = create_and_start_container(service).inspect() diff --git a/tests/unit/service_test.py b/tests/unit/service_test.py index 5002954b..c4d53a2c 100644 --- a/tests/unit/service_test.py +++ b/tests/unit/service_test.py @@ -562,6 +562,33 @@ class ServiceTest(unittest.TestCase): assert called_build_args['arg1'] == build_args['arg1'] assert called_build_args['arg2'] == 'arg2' + def test_build_with_isolation_from_service_config(self): + self.mock_client.build.return_value = [ + b'{"stream": "Successfully built 12345"}', + ] + + service = Service('foo', client=self.mock_client, build={'context': '.'}, isolation='hyperv') + service.build() + + assert self.mock_client.build.call_count == 1 + called_build_args = self.mock_client.build.call_args[1] + assert called_build_args['isolation'] == 'hyperv' + + def test_build_isolation_from_build_override_service_config(self): + self.mock_client.build.return_value = [ + b'{"stream": "Successfully built 12345"}', + ] + + service = Service( + 'foo', client=self.mock_client, build={'context': '.', 'isolation': 'default'}, + isolation='hyperv' + ) + service.build() + + assert self.mock_client.build.call_count == 1 + called_build_args = self.mock_client.build.call_args[1] + assert called_build_args['isolation'] == 'default' + def test_config_dict(self): self.mock_client.inspect_image.return_value = {'Id': 'abcd'} service = Service( |