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

Add command line option to specify ECR configuration file (fix #3) #6

Merged
merged 1 commit into from
Apr 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add command line option to specify ECR configuration file (fix #3)
  • Loading branch information
laughingman7743 committed Apr 1, 2018
commit 50468e55c7977f4997d6e03f4ca88d521a234e39
9 changes: 5 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Installation

$ pip install ecr-cli

Configuration file
------------------
ECR Configuration file
----------------------

If you place a file in `YAML format`_ with the filename ``.ecr.yml`` in the same directory as ``Dockerfile``,
profile name, region name, registry ID and tag can be set.
Expand Down Expand Up @@ -98,8 +98,9 @@ Build
Build an image from a Dockerfile.

Options:
-t, --tag TEXT
--dockerfile PATH Name of the Dockerfile (Default is ‘PATH/Dockerfile’).
-t, --tag TEXT Name and optionally a tag in the `name:tag` format.
--dockerfile PATH Name of the Dockerfile (Default is `PATH/Dockerfile`).
--configfile PATH Name of the ECR configuration file (Default is `PATH/.ecr.yml`).
--cache / --no-cache Use cache when building the image.
--rm / --no-rm Remove intermediate containers after a successful build.
--force-rm / --no-force-rm Always remove intermediate containers.
Expand Down
15 changes: 11 additions & 4 deletions ecr_cli/cli.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import ecr_cli.message as msg
from ecr_cli import CONTEXT_SETTINGS
from ecr_cli.action import EcrAction
from ecr_cli.util import load_config
from ecr_cli.util import load_ecr_config


@click.group(context_settings=CONTEXT_SETTINGS)
Expand All @@ -31,9 +31,12 @@ def cli(ctx, profile, region, registry_id, debug):

@cli.command(help=msg.HELP_COMMAND_BUILD)
@click.argument('path', type=click.Path(exists=True, dir_okay=True), nargs=1, required=True)
@click.option('--tag', '-t', type=str, multiple=True, required=False)
@click.option('--tag', '-t', type=str, multiple=True, required=False,
help=msg.HELP_OPTION_TAG)
@click.option('--dockerfile', type=click.Path(exists=True, file_okay=True), required=False,
help=msg.HELP_OPTION_DOCKERFILE)
@click.option('--configfile', type=click.Path(exists=True, file_okay=True), required=False,
help=msg.HELP_OPTION_CONFIGFILE)
@click.option('--cache/--no-cache', default=True, required=False,
help=msg.HELP_OPTION_CACHE)
@click.option('--rm/--no-rm', default=False, required=False,
Expand All @@ -49,8 +52,12 @@ def cli(ctx, profile, region, registry_id, debug):
@click.option('--quiet/--no-quiet', default=False, required=False,
help=msg.HELP_OPTION_QUIET)
@click.pass_context
def build(ctx, path, tag, dockerfile, cache, rm, force_rm, pull, squash, push, quiet):
config = load_config(os.path.dirname(dockerfile) if dockerfile else path)
def build(ctx, path, tag, dockerfile, configfile, cache, rm, force_rm,
pull, squash, push, quiet):
if not configfile:
configfile = os.path.join(os.path.dirname(dockerfile) if dockerfile else path,
'.ecr.yml')
config = load_ecr_config(configfile)
if not config and not tag:
raise RuntimeError('Missing argument `tag`.')

Expand Down
5 changes: 3 additions & 2 deletions ecr_cli/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
HELP_OPTION_DEBUG = 'Turn on debug logging.'
HELP_OPTION_REGISTRY_ID = 'AWS account ID that correspond to a Amazon ECR registry ' \
'that you want to log in to.'
HELP_OPTION_TAG = 'Name and optionally a tag in the ‘name:tag’ format.'
HELP_OPTION_DOCKERFILE = 'Name of the Dockerfile (Default is ‘PATH/Dockerfile’).'
HELP_OPTION_TAG = 'Name and optionally a tag in the `name:tag` format.'
HELP_OPTION_DOCKERFILE = 'Name of the Dockerfile (Default is `PATH/Dockerfile`).'
HELP_OPTION_CONFIGFILE = 'Name of the ECR configuration file (Default is `PATH/.ecr.yml`).'
HELP_OPTION_CACHE = 'Use cache when building the image.'
HELP_OPTION_RM = 'Remove intermediate containers after a successful build.'
HELP_OPTION_FORCE_RM = 'Always remove intermediate containers.'
Expand Down
7 changes: 3 additions & 4 deletions ecr_cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
from ecr_cli.model import EcrConfig


def load_config(path):
conf = os.path.join(path, '.ecr.yml')
def load_ecr_config(file_):
config = None
if os.path.exists(conf):
with codecs.open(conf, 'rb', 'utf-8') as f:
if os.path.exists(file_):
with codecs.open(file_, 'rb', 'utf-8') as f:
config = EcrConfig.from_dict(yaml.load(f))
return config