From a50fb419fa9b50ccacf1697e1f8ff64284b1f687 Mon Sep 17 00:00:00 2001 From: tsaikd Date: Wed, 22 Oct 2014 14:58:52 +0800 Subject: [PATCH] fig up support '--allow-insecure-ssl' Signed-off-by: tsaikd --- fig/cli/main.py | 16 ++++++++++------ fig/project.py | 4 ++-- fig/service.py | 8 ++++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/fig/cli/main.py b/fig/cli/main.py index 9a47771f459..ab833850399 100644 --- a/fig/cli/main.py +++ b/fig/cli/main.py @@ -396,11 +396,12 @@ def up(self, project, options): Usage: up [options] [SERVICE...] Options: - -d Detached mode: Run containers in the background, - print new container names. - --no-color Produce monochrome output. - --no-deps Don't start linked services. - --no-recreate If containers already exist, don't recreate them. + -d Detached mode: Run containers in the background, + print new container names. + --no-color Produce monochrome output. + --no-deps Don't start linked services. + --no-recreate If containers already exist, don't recreate them. + --allow-insecure-ssl Allow insecure connections to the docker registry. """ detached = options['-d'] @@ -410,10 +411,13 @@ def up(self, project, options): recreate = not options['--no-recreate'] service_names = options['SERVICE'] + pull_options = {x: options[x] for x in options if x in ['--allow-insecure-ssl']} + project.up( service_names=service_names, start_links=start_links, - recreate=recreate + recreate=recreate, + pull_options=pull_options ) to_attach = [c for s in project.get_services(service_names) for c in s.containers()] diff --git a/fig/project.py b/fig/project.py index 38b9f46fc41..0d451cb3c61 100644 --- a/fig/project.py +++ b/fig/project.py @@ -167,7 +167,7 @@ def build(self, service_names=None, no_cache=False): else: log.info('%s uses an image, skipping' % service.name) - def up(self, service_names=None, start_links=True, recreate=True): + def up(self, service_names=None, start_links=True, recreate=True, pull_options={}): running_containers = [] for service in self.get_services(service_names, include_links=start_links): @@ -175,7 +175,7 @@ def up(self, service_names=None, start_links=True, recreate=True): for (_, container) in service.recreate_containers(): running_containers.append(container) else: - for container in service.start_or_create_containers(): + for container in service.start_or_create_containers(pull_options=pull_options): running_containers.append(container) return running_containers diff --git a/fig/service.py b/fig/service.py index 6c635dee004..900f73777e1 100644 --- a/fig/service.py +++ b/fig/service.py @@ -168,7 +168,7 @@ def remove_stopped(self, **options): log.info("Removing %s..." % c.name) c.remove(**options) - def create_container(self, one_off=False, **override_options): + def create_container(self, one_off=False, pull_options={}, **override_options): """ Create a container for this service. If the image doesn't exist, attempt to pull it. @@ -179,7 +179,7 @@ def create_container(self, one_off=False, **override_options): except APIError as e: if e.response.status_code == 404 and e.explanation and 'No such image' in str(e.explanation): log.info('Pulling image %s...' % container_options['image']) - output = self.client.pull(container_options['image'], stream=True) + output = self.client.pull(container_options['image'], stream=True, insecure_registry=pull_options['--allow-insecure-ssl']) stream_output(output, sys.stdout) return Container.create(self.client, **container_options) raise @@ -270,12 +270,12 @@ def start_container(self, container=None, intermediate_container=None, **overrid ) return container - def start_or_create_containers(self): + def start_or_create_containers(self, pull_options={}, **override_options): containers = self.containers(stopped=True) if not containers: log.info("Creating %s..." % self._next_container_name(containers)) - new_container = self.create_container() + new_container = self.create_container(pull_options=pull_options, **override_options) return [self.start_container(new_container)] else: return [self.start_container_if_stopped(c) for c in containers]