def env(ctx, cluster, service, pairs, delete, group): """Manage environment variables |\b # List environment variables $ ecs service env CLUSTER SERVICE # Set environment variables $ ecs service env CLUSTER SERVICE KEY1=VALUE1 KEY2=VALUE2 ... """ ecs = ctx.obj['ecs'] ecr = ctx.obj['ecr'] elbv2 = ctx.obj['elbv2'] srv_names = [service] if group: srv_names = utils.get_group_services(service) services = bulk_update_service_variables(ecs, ecr, cluster, srv_names, pairs, delete) if not any([s['pending_deploy'] for s in services]): sys.exit(0) confirm_input('Do you want to deploy your changes? ') bulk_deploy_service(services) utils.monitor_deployment(ecs, elbv2, cluster, srv_names, exit_on_complete=True)
def cli(ctx, cluster, service, count): """Scale service""" ecs = ctx.obj['ecs'] elbv2 = ctx.obj['elbv2'] try: ecs.update_service(cluster=cluster, service=service, desiredCount=count) except ClientError as e: click.echo(e.response['Error']['Message'], err=True) sys.exit(1) utils.monitor_deployment(ecs, elbv2, cluster, service)
def scale(ctx, cluster, service, count): """Scale service""" ecs = ctx.obj['ecs'] ecr = ctx.obj['ecr'] elbv2 = ctx.obj['elbv2'] srv = Service(ecs, ecr, cluster, service) params = { 'cluster': cluster, 'service': service, 'desiredCount': count } srv.update_service(**params) utils.monitor_deployment(ecs, elbv2, cluster, service, exit_on_complete=True)
def top(ctx, cluster, service, group, exit_on_complete): """Monitor service""" ecs = ctx.obj['ecs'] elbv2 = ctx.obj['elbv2'] try: if group: if service in config['service-group']: service = config['service-group'][service].split(' ') else: click.echo('Error: Service group not in config file.') sys.exit(1) except KeyError: click.echo('Error: Section "service-group" not in config file.') sys.exit(1) utils.monitor_deployment(ecs, elbv2, cluster, service, exit_on_complete=exit_on_complete)
def cli(ctx, cluster, service, artifact, task_definition, count): """Deploy a task definition to a service |\b The deployment respects the current number of tasks in the service. Use '-c' to scale in or out during deploy. """ ecs = ctx.obj['ecs'] ecr = ctx.obj['ecr'] elbv2 = ctx.obj['elbv2'] task_def = artifact if not task_definition: task_def = register_task_def_with_new_image( ecs, ecr, cluster, service, artifact) deploy_task_definition(ecs, cluster, service, task_def, count) click.echo() utils.monitor_deployment(ecs, elbv2, cluster, service)
def deploy(ctx, cluster, service, tags, group, count, verbose): """Deploy a task definition to a service |\b The deployment respects the current number of tasks in the service. Use '-c' to scale in or out during deploy. """ if len(tags) == 0: click.echo('Error: Specify one or more tags to be deployed.', err=True) sys.exit(1) if group: services = utils.get_group_services(service) service = run_group_deployment(ctx, cluster, services, tags, count, verbose) else: deploy_service(ctx, cluster, service, tags, count, verbose) utils.monitor_deployment(ctx.obj['ecs'], ctx.obj['elbv2'], cluster, service, exit_on_complete=True)
def cli(ctx, cluster, service, pairs, delete): """Manage environment variables |\b # List environment variables $ ecs service env CLUSTER SERVICE # Set environment variables $ ecs service env CLUSTER SERVICE KEY1=VALUE1 KEY2=VALUE2 ... """ ecs = ctx.obj['ecs'] elbv2 = ctx.obj['elbv2'] srv = desc_service(ecs, cluster, service) td_arn = srv['taskDefinition'] click.secho('Current task definition for %s %s: %s' % (cluster, service, td_arn.split('/')[-1]), fg='blue') td = desc_task_definition(ecs, td_arn) containers = td['containerDefinitions'] if len(containers) > 1: container = container_selection(containers) else: container = containers[0] click.echo() click.secho(('==> Container: %s' % container['name']), fg='white') # Just print env vars if none were passed if len(pairs) == 0: for e in container['environment']: click.echo('%s=%s' % (e['name'], e['value'])) sys.exit(0) envs = copy.deepcopy(container['environment']) # Delete variable if '-d' is passed if delete: for pair in pairs: for e in envs: if pair == e['name']: click.echo('- %s=%s' % (e['name'], e['value'])) envs.remove(e) else: # Update env var if it exist. Otherwise append it. validate_pairs(pairs) for pair in pairs: k, v = pair.split('=', 1) matched = False # Check if env var already exists for e in envs: if k == e['name']: if v != e['value']: # Env var value is different click.echo('- %s=%s' % (e['name'], e['value'])) click.echo('+ ', nl=False) e['value'] = v click.echo('%s=%s' % (k, v)) matched = True break if not matched: click.echo('+ %s=%s' % (k, v)) envs.append({'name': k, 'value': v}) # Compare new and old environment variables if envs == container['environment']: # Nothing was updated. No need to create task definition. click.echo('\nNo updates') sys.exit(0) click.echo() try: c = input('Do you want to create a new task definition revision? ') if c not in ['yes', 'Yes', 'y', 'Y']: raise ValueError() except: sys.exit(0) # Register new task definition with the new environment variables try: td_name = register_task_definition_with_envs(ecs, td, container['name'], envs) except: sys.exit(0) # # Ask to deploy the changes try: to_deploy = input('Do you want to deploy your changes? ') if to_deploy not in ['yes', 'Yes', 'y', 'Y']: raise ValueError() except: sys.exit(0) # Deploy the new task definition deploy_task_definition(ecs, cluster, service, td_name) click.echo() utils.monitor_deployment(ecs, elbv2, cluster, service)
def cli(ctx, cluster, service): """Monitor service""" ecs = ctx.obj['ecs'] elbv2 = ctx.obj['elbv2'] utils.monitor_deployment(ecs, elbv2, cluster, service)