Add a no-build option to fig up, to save time when services were already freshly built.
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
5b777ee5f1
commit
3056ae4be3
5 changed files with 63 additions and 24 deletions
|
|
@ -425,6 +425,7 @@ class TopLevelCommand(Command):
|
|||
--no-color Produce monochrome output.
|
||||
--no-deps Don't start linked services.
|
||||
--no-recreate If containers already exist, don't recreate them.
|
||||
--no-build Don't build an image, even if it's missing
|
||||
"""
|
||||
insecure_registry = options['--allow-insecure-ssl']
|
||||
detached = options['-d']
|
||||
|
|
@ -440,7 +441,8 @@ class TopLevelCommand(Command):
|
|||
start_links=start_links,
|
||||
recreate=recreate,
|
||||
insecure_registry=insecure_registry,
|
||||
detach=options['-d']
|
||||
detach=options['-d'],
|
||||
do_build=not options['--no-build'],
|
||||
)
|
||||
|
||||
to_attach = [c for s in project.get_services(service_names) for c in s.containers()]
|
||||
|
|
|
|||
|
|
@ -167,14 +167,26 @@ class Project(object):
|
|||
else:
|
||||
log.info('%s uses an image, skipping' % service.name)
|
||||
|
||||
def up(self, service_names=None, start_links=True, recreate=True, insecure_registry=False, detach=False):
|
||||
def up(self,
|
||||
service_names=None,
|
||||
start_links=True,
|
||||
recreate=True,
|
||||
insecure_registry=False,
|
||||
detach=False,
|
||||
do_build=True):
|
||||
running_containers = []
|
||||
for service in self.get_services(service_names, include_links=start_links):
|
||||
if recreate:
|
||||
for (_, container) in service.recreate_containers(insecure_registry=insecure_registry, detach=detach):
|
||||
for (_, container) in service.recreate_containers(
|
||||
insecure_registry=insecure_registry,
|
||||
detach=detach,
|
||||
do_build=do_build):
|
||||
running_containers.append(container)
|
||||
else:
|
||||
for container in service.start_or_create_containers(insecure_registry=insecure_registry, detach=detach):
|
||||
for container in service.start_or_create_containers(
|
||||
insecure_registry=insecure_registry,
|
||||
detach=detach,
|
||||
do_build=do_build):
|
||||
running_containers.append(container)
|
||||
|
||||
return running_containers
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ DOCKER_START_KEYS = [
|
|||
'cap_add',
|
||||
'cap_drop',
|
||||
'dns',
|
||||
'dns_search',
|
||||
'dns_search',
|
||||
'env_file',
|
||||
'net',
|
||||
'privileged',
|
||||
|
|
@ -236,7 +236,7 @@ class Service(object):
|
|||
return Container.create(self.client, **container_options)
|
||||
raise
|
||||
|
||||
def recreate_containers(self, insecure_registry=False, **override_options):
|
||||
def recreate_containers(self, insecure_registry=False, do_build=True, **override_options):
|
||||
"""
|
||||
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.
|
||||
|
|
@ -244,7 +244,10 @@ class Service(object):
|
|||
containers = self.containers(stopped=True)
|
||||
if not containers:
|
||||
log.info("Creating %s..." % self._next_container_name(containers))
|
||||
container = self.create_container(insecure_registry=insecure_registry, **override_options)
|
||||
container = self.create_container(
|
||||
insecure_registry=insecure_registry,
|
||||
do_build=do_build,
|
||||
**override_options)
|
||||
self.start_container(container)
|
||||
return [(None, container)]
|
||||
else:
|
||||
|
|
@ -283,7 +286,7 @@ class Service(object):
|
|||
container.remove()
|
||||
|
||||
options = dict(override_options)
|
||||
new_container = self.create_container(**options)
|
||||
new_container = self.create_container(do_build=False, **options)
|
||||
self.start_container(new_container, intermediate_container=intermediate_container)
|
||||
|
||||
intermediate_container.remove()
|
||||
|
|
@ -330,14 +333,19 @@ class Service(object):
|
|||
)
|
||||
return container
|
||||
|
||||
def start_or_create_containers(self, insecure_registry=False, detach=False):
|
||||
def start_or_create_containers(
|
||||
self,
|
||||
insecure_registry=False,
|
||||
detach=False,
|
||||
do_build=True):
|
||||
containers = self.containers(stopped=True)
|
||||
|
||||
if not containers:
|
||||
log.info("Creating %s..." % self._next_container_name(containers))
|
||||
new_container = self.create_container(
|
||||
insecure_registry=insecure_registry,
|
||||
detach=detach
|
||||
detach=detach,
|
||||
do_build=do_build,
|
||||
)
|
||||
return [self.start_container(new_container)]
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue