mirror of https://github.com/docker/compose.git
Merge pull request #5839 from docker/5744-build-isolation
Add support for build isolation parameter
This commit is contained in:
commit
54c535d2f1
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -472,24 +472,8 @@ class ServiceTest(unittest.TestCase):
|
|||
_, args, _ = mock_log.warn.mock_calls[0]
|
||||
assert 'was built because it did not already exist' in args[0]
|
||||
|
||||
self.mock_client.build.assert_called_once_with(
|
||||
tag='default_foo',
|
||||
dockerfile=None,
|
||||
path='.',
|
||||
pull=False,
|
||||
forcerm=False,
|
||||
nocache=False,
|
||||
rm=True,
|
||||
buildargs={},
|
||||
labels=None,
|
||||
cache_from=None,
|
||||
network_mode=None,
|
||||
target=None,
|
||||
shmsize=None,
|
||||
extra_hosts=None,
|
||||
container_limits={'memory': None},
|
||||
gzip=False,
|
||||
)
|
||||
assert self.mock_client.build.call_count == 1
|
||||
self.mock_client.build.call_args[1]['tag'] == 'default_foo'
|
||||
|
||||
def test_ensure_image_exists_no_build(self):
|
||||
service = Service('foo', client=self.mock_client, build={'context': '.'})
|
||||
|
@ -515,24 +499,8 @@ class ServiceTest(unittest.TestCase):
|
|||
service.ensure_image_exists(do_build=BuildAction.force)
|
||||
|
||||
assert not mock_log.warn.called
|
||||
self.mock_client.build.assert_called_once_with(
|
||||
tag='default_foo',
|
||||
dockerfile=None,
|
||||
path='.',
|
||||
pull=False,
|
||||
forcerm=False,
|
||||
nocache=False,
|
||||
rm=True,
|
||||
buildargs={},
|
||||
labels=None,
|
||||
cache_from=None,
|
||||
network_mode=None,
|
||||
target=None,
|
||||
shmsize=None,
|
||||
extra_hosts=None,
|
||||
container_limits={'memory': None},
|
||||
gzip=False
|
||||
)
|
||||
assert self.mock_client.build.call_count == 1
|
||||
self.mock_client.build.call_args[1]['tag'] == 'default_foo'
|
||||
|
||||
def test_build_does_not_pull(self):
|
||||
self.mock_client.build.return_value = [
|
||||
|
@ -562,6 +530,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(
|
||||
|
|
Loading…
Reference in New Issue