Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit bfe110c

Browse files
committed
adding "fig pull [SERVICE]" to pull service images
Fixes docker#158
1 parent dc857a7 commit bfe110c

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

fig/cli/main.py

+9
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class TopLevelCommand(Command):
8585
kill Kill containers
8686
logs View output from containers
8787
ps List containers
88+
pull Pulls service images
8889
rm Remove stopped containers
8990
run Run a one-off command
9091
scale Set number of containers for a service
@@ -182,6 +183,14 @@ def ps(self, project, options):
182183
])
183184
print(Formatter().table(headers, rows))
184185

186+
def pull(self, project, options):
187+
"""
188+
Pulls images for services.
189+
190+
Usage: pull [SERVICE...]
191+
"""
192+
project.pull(service_names=options['SERVICE'])
193+
185194
def rm(self, project, options):
186195
"""
187196
Remove stopped service containers.

fig/project.py

+4
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ def up(self, service_names=None, start_links=True, recreate=True):
176176

177177
return running_containers
178178

179+
def pull(self, service_names=None):
180+
for service in self.get_services(service_names, include_links=True):
181+
service.pull()
182+
179183
def remove_stopped(self, service_names=None, **options):
180184
for service in self.get_services(service_names):
181185
service.remove_stopped(**options)

fig/service.py

+5
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ def can_be_scaled(self):
401401
return False
402402
return True
403403

404+
def pull(self):
405+
if 'image' in self.options:
406+
log.info('Pulling %s (%s)...' % (self.name, self.options.get('image')))
407+
self.client.pull(self.options.get('image'))
408+
404409

405410
NAME_RE = re.compile(r'^([^_]+)_([^_]+)_(run_)?(\d+)$')
406411

tests/integration/cli_test.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ def test_ps_alternate_figfile(self, mock_stdout):
5151
self.assertNotIn('multiplefigfiles_another_1', output)
5252
self.assertIn('multiplefigfiles_yetanother_1', output)
5353

54+
@patch('fig.service.log')
55+
def test_pull(self, mock_logging):
56+
self.command.dispatch(['pull'], None)
57+
mock_logging.info.assert_any_call('Pulling simple (busybox:latest)...')
58+
mock_logging.info.assert_any_call('Pulling another (busybox:latest)...')
59+
5460
@patch('sys.stdout', new_callable=StringIO)
5561
def test_build_no_cache(self, mock_stdout):
5662
self.command.base_dir = 'tests/fixtures/simple-dockerfile'
@@ -66,7 +72,6 @@ def test_build_no_cache(self, mock_stdout):
6672
self.command.dispatch(['build', '--no-cache', 'simple'], None)
6773
output = mock_stdout.getvalue()
6874
self.assertNotIn(cache_indicator, output)
69-
7075
def test_up(self):
7176
self.command.dispatch(['up', '-d'], None)
7277
service = self.project.get_service('simple')

0 commit comments

Comments
 (0)