mirror of https://github.com/docker/docs.git
Merge pull request #276 from marksteve/nocache
Add `--no-cache` option to `fig build` (Closes #152)
This commit is contained in:
commit
ed80576236
|
@ -103,9 +103,13 @@ class TopLevelCommand(Command):
|
||||||
e.g. `figtest_db`. If you change a service's `Dockerfile` or the
|
e.g. `figtest_db`. If you change a service's `Dockerfile` or the
|
||||||
contents of its build directory, you can run `fig build` to rebuild it.
|
contents of its build directory, you can run `fig build` to rebuild it.
|
||||||
|
|
||||||
Usage: build [SERVICE...]
|
Usage: build [options] [SERVICE...]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
--no-cache Do not use cache when building the image.
|
||||||
"""
|
"""
|
||||||
self.project.build(service_names=options['SERVICE'])
|
no_cache = bool(options.get('--no-cache', False))
|
||||||
|
self.project.build(service_names=options['SERVICE'], no_cache=no_cache)
|
||||||
|
|
||||||
def help(self, options):
|
def help(self, options):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -154,10 +154,10 @@ class Project(object):
|
||||||
for service in reversed(self.get_services(service_names)):
|
for service in reversed(self.get_services(service_names)):
|
||||||
service.kill(**options)
|
service.kill(**options)
|
||||||
|
|
||||||
def build(self, service_names=None, **options):
|
def build(self, service_names=None, no_cache=False):
|
||||||
for service in self.get_services(service_names):
|
for service in self.get_services(service_names):
|
||||||
if service.can_be_built():
|
if service.can_be_built():
|
||||||
service.build(**options)
|
service.build(no_cache)
|
||||||
else:
|
else:
|
||||||
log.info('%s uses an image, skipping' % service.name)
|
log.info('%s uses an image, skipping' % service.name)
|
||||||
|
|
||||||
|
|
|
@ -356,14 +356,15 @@ class Service(object):
|
||||||
|
|
||||||
return container_options
|
return container_options
|
||||||
|
|
||||||
def build(self):
|
def build(self, no_cache=False):
|
||||||
log.info('Building %s...' % self.name)
|
log.info('Building %s...' % self.name)
|
||||||
|
|
||||||
build_output = self.client.build(
|
build_output = self.client.build(
|
||||||
self.options['build'],
|
self.options['build'],
|
||||||
tag=self._build_tag_name(),
|
tag=self._build_tag_name(),
|
||||||
stream=True,
|
stream=True,
|
||||||
rm=True
|
rm=True,
|
||||||
|
nocache=no_cache,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
simple:
|
||||||
|
build: tests/fixtures/simple-dockerfile
|
|
@ -46,6 +46,18 @@ class CLITestCase(DockerClientTestCase):
|
||||||
self.assertNotIn('multiplefigfiles_another_1', output)
|
self.assertNotIn('multiplefigfiles_another_1', output)
|
||||||
self.assertIn('multiplefigfiles_yetanother_1', output)
|
self.assertIn('multiplefigfiles_yetanother_1', output)
|
||||||
|
|
||||||
|
@patch('sys.stdout', new_callable=StringIO)
|
||||||
|
def test_build_no_cache(self, mock_stdout):
|
||||||
|
self.command.base_dir = 'tests/fixtures/simple-dockerfile'
|
||||||
|
self.command.dispatch(['build', 'simple'], None)
|
||||||
|
mock_stdout.truncate(0)
|
||||||
|
cache_indicator = 'Using cache'
|
||||||
|
self.command.dispatch(['build', 'simple'], None)
|
||||||
|
self.assertIn(cache_indicator, output)
|
||||||
|
mock_stdout.truncate(0)
|
||||||
|
self.command.dispatch(['build', '--no-cache', 'simple'], None)
|
||||||
|
self.assertNotIn(cache_indicator, output)
|
||||||
|
|
||||||
def test_up(self):
|
def test_up(self):
|
||||||
self.command.dispatch(['up', '-d'], None)
|
self.command.dispatch(['up', '-d'], None)
|
||||||
service = self.command.project.get_service('simple')
|
service = self.command.project.get_service('simple')
|
||||||
|
@ -193,3 +205,4 @@ class CLITestCase(DockerClientTestCase):
|
||||||
self.command.scale({'SERVICE=NUM': ['simple=0', 'another=0']})
|
self.command.scale({'SERVICE=NUM': ['simple=0', 'another=0']})
|
||||||
self.assertEqual(len(project.get_service('simple').containers()), 0)
|
self.assertEqual(len(project.get_service('simple').containers()), 0)
|
||||||
self.assertEqual(len(project.get_service('another').containers()), 0)
|
self.assertEqual(len(project.get_service('another').containers()), 0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue