diff --git a/cloudlift/__init__.py b/cloudlift/__init__.py index 4f3792d2..981c8f38 100644 --- a/cloudlift/__init__.py +++ b/cloudlift/__init__.py @@ -1,4 +1,5 @@ import functools +import os import boto3 import click @@ -41,6 +42,17 @@ def wrapper(*args, **kwargs): return wrapper +def _fetch_build_args(ctx, param, value): + return_values = [] + for arg_name in value: + try: + value = os.environ[arg_name] + return_values.append((str(arg_name), str(value))) + except KeyError: + raise click.BadParameter("Value not found in environment for build arg " + arg_name) + return dict(return_values) + + class CommandWrapper(click.Group): def __call__(self, *args, **kwargs): try: @@ -113,8 +125,12 @@ def edit_config(name, environment): @click.option("--build-arg", type=(str, str), multiple=True, help="These args are passed to docker build command " "as --build-args. Supports multiple.\ Please leave space between name and value" ) -def deploy_service(name, environment, version, build_arg): - ServiceUpdater(name, environment, None, version, dict(build_arg)).run() +@click.option("--fetch-build-arg", multiple=True, callback=_fetch_build_args, help="These args are passed to docker " + "build command as --build-args. " + "Supports multiple.\ + Values are picked from environment") +def deploy_service(name, environment, version, build_arg, fetch_build_arg): + ServiceUpdater(name, environment, None, version, dict(build_arg, **fetch_build_arg)).run() @cli.command() @@ -125,8 +141,12 @@ def deploy_service(name, environment, version, build_arg): @click.option("--build-arg", type=(str, str), multiple=True, help="These args are passed to docker build command " "as --build-args. Supports multiple.\ Please leave space between name and value" ) -def create_task_definition(name, environment, version, build_arg): - TaskDefinitionCreator(name, environment, version, dict(build_arg)).create() +@click.option("--fetch-build-arg", multiple=True, callback=_fetch_build_args, help="These args are passed to docker " + "build command as --build-args. " + "Supports multiple.\ + Values are picked from environment") +def create_task_definition(name, environment, version, build_arg, fetch_build_arg): + TaskDefinitionCreator(name, environment, version, dict(build_arg, **fetch_build_arg)).create() @cli.command() @@ -137,8 +157,12 @@ def create_task_definition(name, environment, version, build_arg): @click.option("--build-arg", type=(str, str), multiple=True, help="These args are passed to docker build command " "as --build-args. Supports multiple.\ Please leave space between name and value" ) -def update_task_definition(name, environment, version, build_arg): - TaskDefinitionCreator(name, environment, version, dict(build_arg)).update() +@click.option("--fetch-build-arg", multiple=True, callback=_fetch_build_args, help="These args are passed to docker " + "build command as --build-args. " + "Supports multiple.\ + Values are picked from environment") +def update_task_definition(name, environment, version, build_arg, fetch_build_arg): + TaskDefinitionCreator(name, environment, version, dict(build_arg, **fetch_build_arg)).update() @cli.command()