Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #10 from laughingman7743/add_quiet_option
Browse files Browse the repository at this point in the history
Add quiet option
  • Loading branch information
laughingman7743 authored May 10, 2018
2 parents 0928351 + 5908820 commit 326d541
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Build
--pull / --no-pull Always attempt to pull a newer version of the image.
--squash / --no-squash Squash newly built layers into a single new layer.
--push / --no-push Push an image or a repository to a Amazon ECR registry after a successful build.
--quiet / --no-quiet Suppress the build output and print image ID on success.
--quiet / --no-quiet Suppress the standard output.
--no-profile Forcibly disable the ECR configuration file profile.
-h, --help Show this message and exit.
Expand All @@ -121,6 +121,7 @@ Push
Push an image or a repository to a Amazon ECR registry.
Options:
--quiet / --no-quiet Suppress the standard output.
-h, --help Show this message and exit.
Pull
Expand All @@ -133,6 +134,7 @@ Pull
Pull an image or a repository from a Amazon ECR registry
Options:
--quiet / --no-quiet Suppress the standard output.
-h, --help Show this message and exit.
Authentication
Expand Down
16 changes: 9 additions & 7 deletions ecr_cli/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def login(self, reauth=True):
return self._registry

def _process_stream(self, stream):
# TODO Safe dictionary key access
result_stream, internal_stream = itertools.tee(json_stream(stream))
image_ids = set()
progress_bars = {}
Expand Down Expand Up @@ -122,13 +123,14 @@ def build(self, tags, path=None, dockerfile=None, cache=True, rm=False,
image.tag('{0}/{1}'.format(self._registry, name), tag, force=True)
return image

def push(self, name, tag=None):
def push(self, name, tag=None, quiet=False):
resp = self._docker_client.images.push(
'{0}/{1}'.format(self._registry, name), tag, stream=True)
image_ids = self._process_stream(resp)
return tuple(image_ids)
'{0}/{1}'.format(self._registry, name), tag, stream=not quiet)
if not quiet:
self._process_stream(resp)

def pull(self, name, tag=None):
def pull(self, name, tag=None, quiet=False):
resp = self._docker_client.images.client.api.pull(
'{0}/{1}'.format(self._registry, name), tag, stream=True)
self._process_stream(resp)
'{0}/{1}'.format(self._registry, name), tag, stream=not quiet)
if not quiet:
self._process_stream(resp)
14 changes: 9 additions & 5 deletions ecr_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,35 @@ def build(ctx, path, tag, dockerfile, configfile, cache, rm, force_rm,
pull=pull, squash=squash, quiet=quiet)
if push:
for t in config.tags:
action.push(t)
action.push(t, quiet=quiet)


@cli.command(help=msg.HELP_COMMAND_PUSH)
@click.argument('name', type=str, nargs=-1, required=True)
@click.option('--quiet/--no-quiet', default=False, required=False,
help=msg.HELP_OPTION_QUIET)
@click.pass_context
def push(ctx, name):
def push(ctx, name, quiet):
action = EcrAction(profile_name=ctx.obj['profile'],
region_name=ctx.obj['region'],
registry_id=ctx.obj['registry_id'],
debug=ctx.obj['debug'])
for n in name:
action.push(n)
action.push(n, quiet=quiet)


@cli.command(help=msg.HELP_COMMAND_PULL)
@click.argument('name', type=str, nargs=-1, required=True)
@click.option('--quiet/--no-quiet', default=False, required=False,
help=msg.HELP_OPTION_QUIET)
@click.pass_context
def pull(ctx, name):
def pull(ctx, name, quiet):
action = EcrAction(profile_name=ctx.obj['profile'],
region_name=ctx.obj['region'],
registry_id=ctx.obj['registry_id'],
debug=ctx.obj['debug'])
for n in name:
action.pull(n)
action.pull(n, quiet=quiet)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion ecr_cli/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
HELP_OPTION_SQUASH = 'Squash newly built layers into a single new layer.'
HELP_OPTION_PUSH = 'Push an image or a repository to a Amazon ECR registry ' \
'after a successful build.'
HELP_OPTION_QUIET = 'Suppress the build output and print image ID on success.'
HELP_OPTION_QUIET = 'Suppress the standard output.'
HELP_OPTION_NO_PROFILE = 'Forcibly disable the ECR configuration file profile.'

0 comments on commit 326d541

Please sign in to comment.