mirror of https://github.com/docker/compose.git
Merge pull request #6115 from graphaelli/parallel-build
add --parallel option to build
This commit is contained in:
commit
473703d0d9
|
@ -260,6 +260,7 @@ class TopLevelCommand(object):
|
|||
--pull Always attempt to pull a newer version of the image.
|
||||
-m, --memory MEM Sets memory limit for the build container.
|
||||
--build-arg key=val Set build-time variables for services.
|
||||
--parallel Build images in parallel.
|
||||
"""
|
||||
service_names = options['SERVICE']
|
||||
build_args = options.get('--build-arg', None)
|
||||
|
@ -280,6 +281,7 @@ class TopLevelCommand(object):
|
|||
memory=options.get('--memory'),
|
||||
build_args=build_args,
|
||||
gzip=options.get('--compress', False),
|
||||
parallel_build=options.get('--parallel', False),
|
||||
)
|
||||
|
||||
def bundle(self, options):
|
||||
|
|
|
@ -372,13 +372,36 @@ class Project(object):
|
|||
return containers
|
||||
|
||||
def build(self, service_names=None, no_cache=False, pull=False, force_rm=False, memory=None,
|
||||
build_args=None, gzip=False):
|
||||
build_args=None, gzip=False, parallel_build=False):
|
||||
|
||||
services = []
|
||||
for service in self.get_services(service_names):
|
||||
if service.can_be_built():
|
||||
service.build(no_cache, pull, force_rm, memory, build_args, gzip)
|
||||
services.append(service)
|
||||
else:
|
||||
log.info('%s uses an image, skipping' % service.name)
|
||||
|
||||
def build_service(service):
|
||||
service.build(no_cache, pull, force_rm, memory, build_args, gzip)
|
||||
|
||||
if parallel_build:
|
||||
_, errors = parallel.parallel_execute(
|
||||
services,
|
||||
build_service,
|
||||
operator.attrgetter('name'),
|
||||
'Building',
|
||||
limit=5,
|
||||
)
|
||||
if len(errors):
|
||||
combined_errors = '\n'.join([
|
||||
e.decode('utf-8') if isinstance(e, six.binary_type) else e for e in errors.values()
|
||||
])
|
||||
raise ProjectError(combined_errors)
|
||||
|
||||
else:
|
||||
for service in services:
|
||||
build_service(service)
|
||||
|
||||
def create(
|
||||
self,
|
||||
service_names=None,
|
||||
|
|
|
@ -773,6 +773,13 @@ class CLITestCase(DockerClientTestCase):
|
|||
|
||||
assert 'does not exist, is not accessible, or is not a valid URL' in result.stderr
|
||||
|
||||
def test_build_parallel(self):
|
||||
self.base_dir = 'tests/fixtures/build-multiple-composefile'
|
||||
result = self.dispatch(['build', '--parallel'])
|
||||
assert 'Successfully tagged build-multiple-composefile_a:latest' in result.stdout
|
||||
assert 'Successfully tagged build-multiple-composefile_b:latest' in result.stdout
|
||||
assert 'Successfully built' in result.stdout
|
||||
|
||||
def test_create(self):
|
||||
self.dispatch(['create'])
|
||||
service = self.project.get_service('simple')
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
FROM busybox:latest
|
||||
RUN echo a
|
||||
CMD top
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
FROM busybox:latest
|
||||
RUN echo b
|
||||
CMD top
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
version: "2"
|
||||
|
||||
services:
|
||||
a:
|
||||
build: ./a
|
||||
b:
|
||||
build: ./b
|
Loading…
Reference in New Issue