Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #148 from orchardup/only-self-link-in-one-off-cont…

…ainers

Only `fig run` containers link back to the service they're part of
  • Loading branch information...
commit 1a1a61a6726424b5d5a95c9857ccb3bbdc092e05 2 parents 3a48172 + 13c7380
@bfirsh bfirsh authored
Showing with 17 additions and 11 deletions.
  1. +6 −5 fig/service.py
  2. +11 −6 tests/service_test.py
View
11 fig/service.py
@@ -207,7 +207,7 @@ def start_container(self, container=None, **override_options):
volume_bindings[os.path.abspath(external_dir)] = internal_dir
container.start(
- links=self._get_links(),
+ links=self._get_links(link_to_self=override_options.get('one_off', False)),
port_bindings=port_bindings,
binds=volume_bindings,
)
@@ -227,7 +227,7 @@ def next_container_number(self, one_off=False):
else:
return max(numbers) + 1
- def _get_links(self):
+ def _get_links(self, link_to_self):
links = []
for service, link_name in self.links:
for container in service.containers():
@@ -235,9 +235,10 @@ def _get_links(self):
links.append((container.name, link_name))
links.append((container.name, container.name))
links.append((container.name, container.name_without_project))
- for container in self.containers():
- links.append((container.name, container.name))
- links.append((container.name, container.name_without_project))
+ if link_to_self:
+ for container in self.containers():
+ links.append((container.name, container.name))
+ links.append((container.name, container.name_without_project))
return links
def _get_container_options(self, override_options, one_off=False):
View
17 tests/service_test.py
@@ -175,12 +175,17 @@ def test_start_container_creates_links_with_names(self):
web.start_container()
self.assertIn('custom_link_name', web.containers()[0].links())
- def test_start_container_creates_links_to_its_own_service(self):
- db1 = self.create_service('db')
- db2 = self.create_service('db')
- db1.start_container()
- db2.start_container()
- self.assertIn('db_1', db2.containers()[0].links())
+ def test_start_normal_container_does_not_create_links_to_its_own_service(self):
+ db = self.create_service('db')
+ c1 = db.start_container()
+ c2 = db.start_container()
+ self.assertNotIn(c1.name, c2.links())
+
+ def test_start_one_off_container_creates_links_to_its_own_service(self):
+ db = self.create_service('db')
+ c1 = db.start_container()
+ c2 = db.start_container(one_off=True)
+ self.assertIn(c1.name, c2.links())
def test_start_container_builds_images(self):
service = Service(
Please sign in to comment.
Something went wrong with that request. Please try again.