mirror of
https://github.com/docker/compose.git
synced 2025-07-23 05:34:36 +02:00
Spike: Re-use existing containers for fig run
Signed-off-by: Chris Corbyn <chris@w3style.co.uk>
This commit is contained in:
parent
949df97726
commit
3d8ce448b8
@ -222,7 +222,8 @@ class TopLevelCommand(Command):
|
|||||||
if not options['--no-links']:
|
if not options['--no-links']:
|
||||||
self.project.up(
|
self.project.up(
|
||||||
service_names=service.get_linked_names(),
|
service_names=service.get_linked_names(),
|
||||||
start_links=True
|
start_links=True,
|
||||||
|
keep_old=True
|
||||||
)
|
)
|
||||||
|
|
||||||
tty = True
|
tty = True
|
||||||
@ -301,7 +302,9 @@ class TopLevelCommand(Command):
|
|||||||
|
|
||||||
If there are existing containers for a service, `fig up` will stop
|
If there are existing containers for a service, `fig up` will stop
|
||||||
and recreate them (preserving mounted volumes with volumes-from),
|
and recreate them (preserving mounted volumes with volumes-from),
|
||||||
so that changes in `fig.yml` are picked up.
|
so that changes in `fig.yml` are picked up. If you do not want existing
|
||||||
|
containers to be recreated, `fig up --keep-old` will re-use existing
|
||||||
|
containers.
|
||||||
|
|
||||||
Usage: up [options] [SERVICE...]
|
Usage: up [options] [SERVICE...]
|
||||||
|
|
||||||
@ -309,13 +312,19 @@ class TopLevelCommand(Command):
|
|||||||
-d Detached mode: Run containers in the background, print
|
-d Detached mode: Run containers in the background, print
|
||||||
new container names.
|
new container names.
|
||||||
--no-links Don't start linked services.
|
--no-links Don't start linked services.
|
||||||
|
--keep-old If containers already exist, don't recreate them.
|
||||||
"""
|
"""
|
||||||
detached = options['-d']
|
detached = options['-d']
|
||||||
|
|
||||||
start_links = not options['--no-links']
|
start_links = not options['--no-links']
|
||||||
|
keep_old = options['--keep-old']
|
||||||
service_names = options['SERVICE']
|
service_names = options['SERVICE']
|
||||||
|
|
||||||
to_attach = self.project.up(service_names=service_names, start_links=start_links)
|
to_attach = self.project.up(
|
||||||
|
service_names=service_names,
|
||||||
|
start_links=start_links,
|
||||||
|
keep_old=keep_old
|
||||||
|
)
|
||||||
|
|
||||||
if not detached:
|
if not detached:
|
||||||
print("Attaching to", list_containers(to_attach))
|
print("Attaching to", list_containers(to_attach))
|
||||||
|
@ -138,11 +138,11 @@ class Project(object):
|
|||||||
else:
|
else:
|
||||||
log.info('%s uses an image, skipping' % service.name)
|
log.info('%s uses an image, skipping' % service.name)
|
||||||
|
|
||||||
def up(self, service_names=None, start_links=True):
|
def up(self, service_names=None, start_links=True, keep_old=False):
|
||||||
new_containers = []
|
new_containers = []
|
||||||
|
|
||||||
for service in self.get_services(service_names, include_links=start_links):
|
for service in self.get_services(service_names, include_links=start_links):
|
||||||
for (_, new) in service.recreate_containers():
|
for (_, new) in service.recreate_containers(keep_old):
|
||||||
new_containers.append(new)
|
new_containers.append(new)
|
||||||
|
|
||||||
return new_containers
|
return new_containers
|
||||||
@ -159,9 +159,6 @@ class Project(object):
|
|||||||
return l
|
return l
|
||||||
|
|
||||||
def _prepend_with_links(self, acc, service):
|
def _prepend_with_links(self, acc, service):
|
||||||
if service in acc:
|
|
||||||
return acc
|
|
||||||
|
|
||||||
linked_names = service.get_linked_names()
|
linked_names = service.get_linked_names()
|
||||||
|
|
||||||
if len(linked_names) > 0:
|
if len(linked_names) > 0:
|
||||||
|
@ -76,9 +76,7 @@ class Service(object):
|
|||||||
|
|
||||||
def start(self, **options):
|
def start(self, **options):
|
||||||
for c in self.containers(stopped=True):
|
for c in self.containers(stopped=True):
|
||||||
if not c.is_running:
|
self.start_container_if_stopped(c, **options)
|
||||||
log.info("Starting %s..." % c.name)
|
|
||||||
self.start_container(c, **options)
|
|
||||||
|
|
||||||
def stop(self, **options):
|
def stop(self, **options):
|
||||||
for c in self.containers():
|
for c in self.containers():
|
||||||
@ -156,7 +154,7 @@ class Service(object):
|
|||||||
return Container.create(self.client, **container_options)
|
return Container.create(self.client, **container_options)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def recreate_containers(self, **override_options):
|
def recreate_containers(self, keep_old=False, **override_options):
|
||||||
"""
|
"""
|
||||||
If a container for this service doesn't exist, create and start one. If there are
|
If a container for this service doesn't exist, create and start one. If there are
|
||||||
any, stop them, create+start new ones, and remove the old containers.
|
any, stop them, create+start new ones, and remove the old containers.
|
||||||
@ -168,6 +166,8 @@ class Service(object):
|
|||||||
container = self.create_container(**override_options)
|
container = self.create_container(**override_options)
|
||||||
self.start_container(container)
|
self.start_container(container)
|
||||||
return [(None, container)]
|
return [(None, container)]
|
||||||
|
elif keep_old:
|
||||||
|
return [(None, self.start_container_if_stopped(c)) for c in containers]
|
||||||
else:
|
else:
|
||||||
tuples = []
|
tuples = []
|
||||||
|
|
||||||
@ -201,6 +201,13 @@ class Service(object):
|
|||||||
|
|
||||||
return (intermediate_container, new_container)
|
return (intermediate_container, new_container)
|
||||||
|
|
||||||
|
def start_container_if_stopped(self, container, **options):
|
||||||
|
if container.is_running:
|
||||||
|
return container
|
||||||
|
else:
|
||||||
|
log.info("Starting %s..." % container.name)
|
||||||
|
return self.start_container(container, **options)
|
||||||
|
|
||||||
def start_container(self, container=None, volumes_from=None, **override_options):
|
def start_container(self, container=None, volumes_from=None, **override_options):
|
||||||
if container is None:
|
if container is None:
|
||||||
container = self.create_container(**override_options)
|
container = self.create_container(**override_options)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user