Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to pick build args from env #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 30 additions & 6 deletions cloudlift/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import functools
import os

import boto3
import click
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down