parent
401ea4e7a8
commit
352ad7a38c
4 changed files with 60 additions and 8 deletions
|
|
@ -298,20 +298,13 @@ class TopLevelCommand(Command):
|
|||
"""
|
||||
detached = options['-d']
|
||||
|
||||
(old, new) = self.project.recreate_containers(service_names=options['SERVICE'])
|
||||
new = self.project.up(service_names=options['SERVICE'])
|
||||
|
||||
if not detached:
|
||||
to_attach = [c for (s, c) in new]
|
||||
print("Attaching to", list_containers(to_attach))
|
||||
log_printer = LogPrinter(to_attach, attach_params={"logs": True})
|
||||
|
||||
for (service, container) in new:
|
||||
service.start_container(container)
|
||||
|
||||
for (service, container) in old:
|
||||
container.remove()
|
||||
|
||||
if not detached:
|
||||
try:
|
||||
log_printer.run()
|
||||
finally:
|
||||
|
|
|
|||
|
|
@ -137,6 +137,17 @@ class Project(object):
|
|||
else:
|
||||
log.info('%s uses an image, skipping' % service.name)
|
||||
|
||||
def up(self, service_names=None):
|
||||
(old, new) = self.recreate_containers(service_names=service_names)
|
||||
|
||||
for (service, container) in new:
|
||||
service.start_container(container)
|
||||
|
||||
for (service, container) in old:
|
||||
container.remove()
|
||||
|
||||
return new
|
||||
|
||||
def remove_stopped(self, service_names=None, **options):
|
||||
for service in self.get_services(service_names):
|
||||
service.remove_stopped(**options)
|
||||
|
|
|
|||
|
|
@ -85,6 +85,14 @@ class Service(object):
|
|||
c.kill(**options)
|
||||
|
||||
def scale(self, desired_num):
|
||||
"""
|
||||
Adjusts the number of containers to the specified number and ensures they are running.
|
||||
|
||||
- creates containers until there are at least `desired_num`
|
||||
- stops containers until there are at most `desired_num` running
|
||||
- starts containers until there are at least `desired_num` running
|
||||
- removes all stopped containers
|
||||
"""
|
||||
if not self.can_be_scaled():
|
||||
raise CannotBeScaledError()
|
||||
|
||||
|
|
@ -117,6 +125,8 @@ class Service(object):
|
|||
self.start_container(c)
|
||||
running_containers.append(c)
|
||||
|
||||
self.remove_stopped()
|
||||
|
||||
|
||||
def remove_stopped(self, **options):
|
||||
for c in self.containers(stopped=True):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue