feat: add --progress flag

Signed-off-by: Nao YONASHIRO <yonashiro@r.recruit.co.jp>
This commit is contained in:
Nao YONASHIRO 2019-08-28 05:34:47 +09:00 committed by Ulysses Souza
parent 862a13b8f3
commit 81e223d499
3 changed files with 100 additions and 90 deletions

View File

@ -270,6 +270,9 @@ class TopLevelCommand(object):
--no-cache Do not use cache when building the image.
--no-rm Do not remove intermediate containers after a successful build.
--parallel Build images in parallel.
--progress string Set type of progress output (auto, plain, tty).
EXPERIMENTAL flag for native builder.
To enable, run with COMPOSE_NATIVE_BUILDER=1)
--pull Always attempt to pull a newer version of the image.
-q, --quiet Don't print anything to STDOUT
"""
@ -297,6 +300,7 @@ class TopLevelCommand(object):
parallel_build=options.get('--parallel', False),
silent=options.get('--quiet', False),
cli=native_builder,
progress=options.get('--progress'),
)
def bundle(self, options):

View File

@ -355,7 +355,8 @@ 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, parallel_build=False, rm=True, silent=False, cli=False):
build_args=None, gzip=False, parallel_build=False, rm=True, silent=False, cli=False,
progress=None):
services = []
for service in self.get_services(service_names):
@ -368,7 +369,7 @@ class Project(object):
log.warning("Native build is an experimental feature and could change at any time")
def build_service(service):
service.build(no_cache, pull, force_rm, memory, build_args, gzip, rm, silent, cli)
service.build(no_cache, pull, force_rm, memory, build_args, gzip, rm, silent, cli, progress)
if parallel_build:
_, errors = parallel.parallel_execute(
services,

View File

@ -1052,7 +1052,7 @@ class Service(object):
return [build_spec(secret) for secret in self.secrets]
def build(self, no_cache=False, pull=False, force_rm=False, memory=None, build_args_override=None,
gzip=False, rm=True, silent=False, cli=False):
gzip=False, rm=True, silent=False, cli=False, progress=None):
output_stream = open(os.devnull, 'w')
if not silent:
output_stream = sys.stdout
@ -1073,8 +1073,8 @@ class Service(object):
'Impossible to perform platform-targeted builds for API version < 1.35'
)
build_image = self.client.build if not cli else cli_build
build_output = build_image(
builder = self.client if not cli else _CLIBuilder(progress)
build_output = builder.build(
path=path,
tag=self.image_name,
rm=rm,
@ -1707,7 +1707,11 @@ def rewrite_build_path(path):
return path
def cli_build(path, tag=None, quiet=False, fileobj=None,
class _CLIBuilder(object):
def __init__(self, progress):
self._progress = progress
def build(self, path, tag=None, quiet=False, fileobj=None,
nocache=False, rm=False, timeout=None,
custom_context=False, encoding=None, pull=False,
forcerm=False, dockerfile=None, container_limits=None,
@ -1779,6 +1783,7 @@ def cli_build(path, tag=None, quiet=False, fileobj=None,
command_builder.add_flag("--force-rm", forcerm)
command_builder.add_arg("--memory", container_limits.get("memory"))
command_builder.add_flag("--no-cache", nocache)
command_builder.add_flag("--progress", self._progress)
command_builder.add_flag("--pull", pull)
command_builder.add_arg("--tag", tag)
command_builder.add_arg("--target", target)