Skip to content

Commit

Permalink
Merge pull request docker#411 from Banno/fig-pull
Browse files Browse the repository at this point in the history
adding "fig pull [SERVICE]" to pull service images
  • Loading branch information
bfirsh committed Sep 10, 2014
2 parents 6b221d5 + 648c897 commit fc4c35e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ Print the public port for a port binding

List containers.

## pull

Pulls service images.

## rm

Remove stopped service containers.
Expand Down
9 changes: 9 additions & 0 deletions fig/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class TopLevelCommand(Command):
logs View output from containers
port Print the public port for a port binding
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
Expand Down Expand Up @@ -204,6 +205,14 @@ def ps(self, project, options):
])
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.
Expand Down
4 changes: 4 additions & 0 deletions fig/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ def up(self, service_names=None, start_links=True, recreate=True):

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)
Expand Down
5 changes: 5 additions & 0 deletions fig/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ def can_be_scaled(self):
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+)$')

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ def test_ps_alternate_figfile(self, mock_stdout):
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'
Expand All @@ -68,7 +74,6 @@ def test_build_no_cache(self, mock_stdout):
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')
Expand Down

0 comments on commit fc4c35e

Please sign in to comment.