Skip to content

Commit

Permalink
Add devices to config hash to trigger container recreate on change
Browse files Browse the repository at this point in the history
 * add unit test
 * update path to compose spec schema in Makefile

Signed-off-by: aiordache <anca.iordache@docker.com>
  • Loading branch information
aiordache authored and ulyssessouza committed Dec 2, 2020
1 parent 5c6c300 commit 8f2dbd9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions compose/config/config.py
Expand Up @@ -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)


Expand Down
8 changes: 6 additions & 2 deletions compose/service.py
Expand Up @@ -709,7 +709,7 @@ def image_id():
except NoSuchImageError:
return None

return {
c = {
'options': self.options,
'image_id': image_id(),
'links': self.get_link_names(),
Expand All @@ -719,9 +719,13 @@ def image_id():
'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
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/service_test.py
Expand Up @@ -732,6 +732,29 @@ def test_config_dict_with_network_mode_from_container(self):
}
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(
Expand Down

0 comments on commit 8f2dbd9

Please sign in to comment.