diff --git a/fig/project.py b/fig/project.py index 93448ff0bef..946adbf4fea 100644 --- a/fig/project.py +++ b/fig/project.py @@ -96,17 +96,20 @@ def from_dicts(cls, name, service_dicts, client, external_projects): @classmethod def from_config(cls, name, config, client): - dicts = [] + services = [] external_projects = get_external_projects(name, config, client) - for service_name, service in config.items(): + project_config = config.pop('project-config', {}) + name = project_config.get('name', name) + + for service_name, service in list(config.items()): if not isinstance(service, dict): raise ConfigurationError( - 'Service "%s" doesn\'t have any configuration options. All ' - 'top level keys in your fig.yml must map to a dictionary ' + 'Service "%s" doesn\'t have any configuration options. ' + 'All top level keys in your fig.yml must map to a ' 'of configuration options.' % service_name) service['name'] = service_name - dicts.append(service) - return cls.from_dicts(name, dicts, client, external_projects) + services.append(service) + return cls.from_dicts(name, services, client, external_projects) def get_service(self, name): """ diff --git a/tests/unit/project_test.py b/tests/unit/project_test.py index 43f293672e2..9c511257e71 100644 --- a/tests/unit/project_test.py +++ b/tests/unit/project_test.py @@ -67,6 +67,15 @@ def test_from_config_throws_error_when_not_dict(self): 'web': 'busybox:latest', }, None) + def test_from_config_with_project_config(self): + project_name = 'theprojectnamefromconfig' + project = Project.from_config('default_name_not_used', { + 'project-config': {'name': project_name}, + 'web': {'image': 'busybox:latest'} + }, None) + + self.assertEqual(project.name, project_name) + def test_get_service(self): web = Service( project='figtest',