From e51851c884d86e956099cfa8e7b49bc9728166d1 Mon Sep 17 00:00:00 2001 From: Luke Amdor Date: Fri, 15 Aug 2014 09:21:41 -0500 Subject: [PATCH 1/2] adding "fig pull [SERVICE]" to pull service images Fixes #158 Signed-off-by: Luke Amdor --- fig/cli/main.py | 9 +++++++++ fig/project.py | 4 ++++ fig/service.py | 5 +++++ tests/integration/cli_test.py | 7 ++++++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/fig/cli/main.py b/fig/cli/main.py index eb19d46d8..666b31a09 100644 --- a/fig/cli/main.py +++ b/fig/cli/main.py @@ -85,6 +85,7 @@ class TopLevelCommand(Command): kill Kill containers logs View output from containers ps List containers + pull Pulls service images rm Remove stopped containers run Run a one-off command scale Set number of containers for a service @@ -182,6 +183,14 @@ class TopLevelCommand(Command): ]) print(Formatter().table(headers, rows)) + def pull(self, project, options): + """ + Pulls images for services. + + Usage: pull [SERVICE...] + """ + project.pull(service_names=options['SERVICE']) + def rm(self, project, options): """ Remove stopped service containers. diff --git a/fig/project.py b/fig/project.py index d0c556c48..1ade6d1a5 100644 --- a/fig/project.py +++ b/fig/project.py @@ -176,6 +176,10 @@ class Project(object): return running_containers + def pull(self, service_names=None): + for service in self.get_services(service_names, include_links=True): + service.pull() + def remove_stopped(self, service_names=None, **options): for service in self.get_services(service_names): service.remove_stopped(**options) diff --git a/fig/service.py b/fig/service.py index 48f63e6a5..04d4759dc 100644 --- a/fig/service.py +++ b/fig/service.py @@ -401,6 +401,11 @@ class Service(object): return False return True + def pull(self): + if 'image' in self.options: + log.info('Pulling %s (%s)...' % (self.name, self.options.get('image'))) + self.client.pull(self.options.get('image')) + NAME_RE = re.compile(r'^([^_]+)_([^_]+)_(run_)?(\d+)$') diff --git a/tests/integration/cli_test.py b/tests/integration/cli_test.py index d0c8585ea..3b95ef468 100644 --- a/tests/integration/cli_test.py +++ b/tests/integration/cli_test.py @@ -51,6 +51,12 @@ class CLITestCase(DockerClientTestCase): self.assertNotIn('multiplefigfiles_another_1', output) self.assertIn('multiplefigfiles_yetanother_1', output) + @patch('fig.service.log') + def test_pull(self, mock_logging): + self.command.dispatch(['pull'], None) + mock_logging.info.assert_any_call('Pulling simple (busybox:latest)...') + mock_logging.info.assert_any_call('Pulling another (busybox:latest)...') + @patch('sys.stdout', new_callable=StringIO) def test_build_no_cache(self, mock_stdout): self.command.base_dir = 'tests/fixtures/simple-dockerfile' @@ -66,7 +72,6 @@ class CLITestCase(DockerClientTestCase): self.command.dispatch(['build', '--no-cache', 'simple'], None) output = mock_stdout.getvalue() self.assertNotIn(cache_indicator, output) - def test_up(self): self.command.dispatch(['up', '-d'], None) service = self.project.get_service('simple') From 648c89768bff900cb560c65d2734cd1e294e6ef0 Mon Sep 17 00:00:00 2001 From: Luke Amdor Date: Wed, 10 Sep 2014 15:06:21 -0500 Subject: [PATCH 2/2] adding 'fig pull' to cli docs Signed-off-by: Luke Amdor --- docs/cli.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/cli.md b/docs/cli.md index a697ab7ae..5e11d8d66 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -32,6 +32,10 @@ View output from services. List containers. +## pull + +Pulls service images. + ## rm Remove stopped service containers.