mirror of https://github.com/docker/compose.git
Add devices to config hash to trigger container recreate on change
* add unit test * update path to compose spec schema in Makefile Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
5c6c300ba5
commit
8f2dbd9b12
2
Makefile
2
Makefile
|
@ -12,7 +12,7 @@ ifeq ($(UNAME_S),Darwin)
|
|||
BUILD_SCRIPT = osx
|
||||
endif
|
||||
|
||||
COMPOSE_SPEC_SCHEMA_PATH = "compose/config/config_schema_compose_spec.json"
|
||||
COMPOSE_SPEC_SCHEMA_PATH = "compose/config/compose_spec.json"
|
||||
COMPOSE_SPEC_RAW_URL = "https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json"
|
||||
|
||||
all: cli
|
||||
|
|
|
@ -1166,6 +1166,7 @@ def merge_reservations(base, override):
|
|||
md.merge_scalar('cpus')
|
||||
md.merge_scalar('memory')
|
||||
md.merge_sequence('generic_resources', types.GenericResource.parse)
|
||||
md.merge_field('devices', merge_unique_objects_lists, default=[])
|
||||
return dict(md)
|
||||
|
||||
|
||||
|
|
|
@ -709,7 +709,7 @@ class Service:
|
|||
except NoSuchImageError:
|
||||
return None
|
||||
|
||||
return {
|
||||
c = {
|
||||
'options': self.options,
|
||||
'image_id': image_id(),
|
||||
'links': self.get_link_names(),
|
||||
|
@ -719,9 +719,13 @@ class Service:
|
|||
'volumes_from': [
|
||||
(v.source.name, v.mode)
|
||||
for v in self.volumes_from if isinstance(v.source, Service)
|
||||
],
|
||||
]
|
||||
}
|
||||
|
||||
if self.device_requests:
|
||||
c['devices'] = self.device_requests
|
||||
return c
|
||||
|
||||
def get_dependency_names(self):
|
||||
net_name = self.network_mode.service_name
|
||||
pid_namespace = self.pid_mode.service_name
|
||||
|
|
|
@ -732,6 +732,29 @@ class ServiceTest(unittest.TestCase):
|
|||
}
|
||||
assert config_dict == expected
|
||||
|
||||
def test_config_dict_with_device_requests(self):
|
||||
self.mock_client.inspect_image.return_value = {'Id': 'abcd'}
|
||||
service = Service(
|
||||
'foo',
|
||||
image='example.com/foo',
|
||||
client=self.mock_client,
|
||||
network_mode=ServiceNetworkMode(Service('other')),
|
||||
networks={'default': None},
|
||||
device_requests=[{'driver': 'nvidia', 'device_ids': ['0'], 'capabilities': ['gpu']}])
|
||||
|
||||
config_dict = service.config_dict()
|
||||
expected = {
|
||||
'image_id': 'abcd',
|
||||
'options': {'image': 'example.com/foo'},
|
||||
'links': [],
|
||||
'net': 'other',
|
||||
'secrets': [],
|
||||
'networks': {'default': None},
|
||||
'volumes_from': [],
|
||||
'devices': [{'driver': 'nvidia', 'device_ids': ['0'], 'capabilities': ['gpu']}],
|
||||
}
|
||||
assert config_dict == expected
|
||||
|
||||
def test_config_hash_matches_label(self):
|
||||
self.mock_client.inspect_image.return_value = {'Id': 'abcd'}
|
||||
service = Service(
|
||||
|
|
Loading…
Reference in New Issue