Skip to content

Commit fc4c35e

Browse files
committed
Merge pull request #411 from Banno/fig-pull
adding "fig pull [SERVICE]" to pull service images
2 parents 6b221d5 + 648c897 commit fc4c35e

5 files changed

Lines changed: 28 additions & 1 deletion

File tree

docs/cli.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Print the public port for a port binding
3636

3737
List containers.
3838

39+
## pull
40+
41+
Pulls service images.
42+
3943
## rm
4044

4145
Remove stopped service containers.

fig/cli/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class TopLevelCommand(Command):
8686
logs View output from containers
8787
port Print the public port for a port binding
8888
ps List containers
89+
pull Pulls service images
8990
rm Remove stopped containers
9091
run Run a one-off command
9192
scale Set number of containers for a service
@@ -204,6 +205,14 @@ def ps(self, project, options):
204205
])
205206
print(Formatter().table(headers, rows))
206207

208+
def pull(self, project, options):
209+
"""
210+
Pulls images for services.
211+
212+
Usage: pull [SERVICE...]
213+
"""
214+
project.pull(service_names=options['SERVICE'])
215+
207216
def rm(self, project, options):
208217
"""
209218
Remove stopped service containers.

fig/project.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ def up(self, service_names=None, start_links=True, recreate=True):
180180

181181
return running_containers
182182

183+
def pull(self, service_names=None):
184+
for service in self.get_services(service_names, include_links=True):
185+
service.pull()
186+
183187
def remove_stopped(self, service_names=None, **options):
184188
for service in self.get_services(service_names):
185189
service.remove_stopped(**options)

fig/service.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,11 @@ def can_be_scaled(self):
410410
return False
411411
return True
412412

413+
def pull(self):
414+
if 'image' in self.options:
415+
log.info('Pulling %s (%s)...' % (self.name, self.options.get('image')))
416+
self.client.pull(self.options.get('image'))
417+
413418

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

tests/integration/cli_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ def test_ps_alternate_figfile(self, mock_stdout):
5353
self.assertNotIn('multiplefigfiles_another_1', output)
5454
self.assertIn('multiplefigfiles_yetanother_1', output)
5555

56+
@patch('fig.service.log')
57+
def test_pull(self, mock_logging):
58+
self.command.dispatch(['pull'], None)
59+
mock_logging.info.assert_any_call('Pulling simple (busybox:latest)...')
60+
mock_logging.info.assert_any_call('Pulling another (busybox:latest)...')
61+
5662
@patch('sys.stdout', new_callable=StringIO)
5763
def test_build_no_cache(self, mock_stdout):
5864
self.command.base_dir = 'tests/fixtures/simple-dockerfile'
@@ -68,7 +74,6 @@ def test_build_no_cache(self, mock_stdout):
6874
self.command.dispatch(['build', '--no-cache', 'simple'], None)
6975
output = mock_stdout.getvalue()
7076
self.assertNotIn(cache_indicator, output)
71-
7277
def test_up(self):
7378
self.command.dispatch(['up', '-d'], None)
7479
service = self.project.get_service('simple')

0 commit comments

Comments
 (0)