diff --git a/plum/service.py b/plum/service.py index 3f9d95f50..8e7660a11 100644 --- a/plum/service.py +++ b/plum/service.py @@ -2,15 +2,14 @@ import re class Service(object): - def __init__(self, name, client=None, image=None, command=None, links=None): + def __init__(self, name, client=None, links=[], **options): if not re.match('^[a-zA-Z0-9_]+$', name): raise ValueError('Invalid name: %s' % name) self.name = name self.client = client - self.image = image - self.command = command self.links = links or [] + self.options = options @property def containers(self): @@ -33,7 +32,7 @@ class Service(object): def start_container(self): number = self.next_container_number() name = make_name(self.name, number) - container = self.client.create_container(self.image, self.command, name=name) + container = self.client.create_container(name=name, **self.options) self.client.start( container['Id'], links=self._get_links(), diff --git a/plum/tests/service_collection_test.py b/plum/tests/service_collection_test.py index 8d36e996d..1c764ecac 100644 --- a/plum/tests/service_collection_test.py +++ b/plum/tests/service_collection_test.py @@ -17,9 +17,9 @@ class ServiceCollectionTest(DockerClientTestCase): ]) self.assertEqual(len(collection), 2) self.assertEqual(collection.get('web').name, 'web') - self.assertEqual(collection.get('web').image, 'ubuntu') + self.assertEqual(collection.get('web').options['image'], 'ubuntu') self.assertEqual(collection.get('db').name, 'db') - self.assertEqual(collection.get('db').image, 'ubuntu') + self.assertEqual(collection.get('db').options['image'], 'ubuntu') def test_from_dict_sorts_in_dependency_order(self): collection = ServiceCollection.from_dicts(None, [ diff --git a/plum/tests/service_test.py b/plum/tests/service_test.py index 51289e68c..7bd0e0b23 100644 --- a/plum/tests/service_test.py +++ b/plum/tests/service_test.py @@ -59,11 +59,16 @@ class NameTestCase(DockerClientTestCase): service.stop() self.assertEqual(len(service.containers), 0) - def test_links_are_created_when_starting(self): + def test_start_container_passes_through_options(self): + db = self.create_service('db', environment={'FOO': 'BAR'}) + db.start_container() + self.assertEqual(db.inspect()[0]['Config']['Env'], ['FOO=BAR']) + + def test_start_container_creates_links(self): db = self.create_service('db') web = self.create_service('web', links=[db]) - db.start() - web.start() + db.start_container() + web.start_container() self.assertIn('/web_1/db_1', db.containers[0]['Names']) db.stop() web.stop()