diff --git a/fig/cli/main.py b/fig/cli/main.py index 127760051..594a20aee 100644 --- a/fig/cli/main.py +++ b/fig/cli/main.py @@ -220,10 +220,10 @@ class TopLevelCommand(Command): service = self.project.get_service(options['SERVICE']) if not options['--no-links']: - self.up({ - '-d': True, - 'SERVICE': self._get_linked_service_names(service) - }) + self.project.up( + service_names=service.get_linked_names(), + start_links=True + ) tty = True if options['-d'] or options['-T'] or not sys.stdin.isatty(): @@ -306,12 +306,16 @@ class TopLevelCommand(Command): Usage: up [options] [SERVICE...] Options: - -d Detached mode: Run containers in the background, print new - container names + -d Detached mode: Run containers in the background, print + new container names. + --no-links Don't start linked services. """ detached = options['-d'] - to_attach = self.project.up(service_names=options['SERVICE']) + start_links = not options['--no-links'] + service_names = options['SERVICE'] + + to_attach = self.project.up(service_names=service_names, start_links=start_links) if not detached: print("Attaching to", list_containers(to_attach)) @@ -321,12 +325,12 @@ class TopLevelCommand(Command): log_printer.run() finally: def handler(signal, frame): - self.project.kill(service_names=options['SERVICE']) + self.project.kill(service_names=service_names) sys.exit(0) signal.signal(signal.SIGINT, handler) print("Gracefully stopping... (press Ctrl+C again to force)") - self.project.stop(service_names=options['SERVICE']) + self.project.stop(service_names=service_names) def _attach_to_container(self, container_id, raw=False): socket_in = self.client.attach_socket(container_id, params={'stdin': 1, 'stream': 1}) diff --git a/fig/project.py b/fig/project.py index 605e4c077..5152c5d7d 100644 --- a/fig/project.py +++ b/fig/project.py @@ -125,10 +125,18 @@ class Project(object): else: log.info('%s uses an image, skipping' % service.name) - def up(self, service_names=None): + def up(self, service_names=None, start_links=True): new_containers = [] for service in self.get_services(service_names): + linked_services = service.get_linked_names() + + if start_links and len(linked_services) > 0: + new_containers.extend(self.up( + service_names=linked_services, + start_links=True + )) + for (_, new) in service.recreate_containers(): new_containers.append(new) diff --git a/fig/service.py b/fig/service.py index 7df3c46b9..748b13e02 100644 --- a/fig/service.py +++ b/fig/service.py @@ -242,6 +242,9 @@ class Service(object): ) return container + def get_linked_names(self): + return [s.name for (s, _) in self.links] + def next_container_name(self, one_off=False): bits = [self.project, self.name] if one_off: