Skip to content

Commit

Permalink
Merge pull request #76 from trebidav/feat/ecs-fargate-env-file
Browse files Browse the repository at this point in the history
feat(ecs-fargate-env-file): add option to pass env file
  • Loading branch information
trebidav authored Mar 17, 2021
2 parents 7b64458 + 6604b8a commit fc973d8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
27 changes: 26 additions & 1 deletion developers_chamber/ecs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,34 @@ def run_task(cluster, task_definition, command, name, region, ecs_client=None, *
}

for key, value in kwargs.items():
if value is not None:
if key != "environmentFiles" and value is not None:
args[key] = value

if kwargs.get('environmentFiles') is not None:
if 'overrides' in args:
if 'containerOverrides' in args['overrides']:
args['overrides']['containerOverrides'][0]['environmentFiles'] = [
{
'type': 's3',
'value': kwargs.get('environmentFiles')
}
]

else:
args['overrides'] = {
'containerOverrides': [
{
'name': name,
'environmentFiles': [
{
'type': 's3',
'value': kwargs.get('environmentFiles')
}
]
},
],
}

try:
resp = ecs_client.run_task(**args)
except ecs_client.exceptions.ClusterNotFoundException:
Expand Down
5 changes: 3 additions & 2 deletions developers_chamber/scripts/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@ def run_service_task(cluster, service, command, success_string, timeout, region,
@click.option('--region', '-r', help='AWS region', type=str, default=default_region, required=True)
@click.option('--subnet', help='subnet ID', type=str, required=True, multiple=True)
@click.option('--security-group', help='security group ID', type=str, required=True, multiple=True)
def run_service_task_fargate(cluster, service, command, success_string, timeout, region, container, subnet, security_group):
@click.option('--environment-file', '-e', help='S3 arn with path to env file', type=str, required=False, default=None)
def run_service_task_fargate(cluster, service, command, success_string, timeout, region, container, subnet, security_group, environment_file):
"""Run a single task based on service's task definition in AWS ECS and wait for it to stop with success."""
run_service_task_func(cluster, service, command, success_string, timeout, region, container, networkConfiguration={
'awsvpcConfiguration': {
'subnets': [s for s in subnet],
'securityGroups': [s for s in security_group],
'assignPublicIp': 'DISABLED'
}
}, launchType='FARGATE')
}, launchType='FARGATE', environmentFiles=environment_file)


@ecs.command()
Expand Down

0 comments on commit fc973d8

Please sign in to comment.