Exemple #1
0
def print_task_diff(ecs_service_name, diffs, color):
    image_diff = next(x for x in diffs if x.field == 'image')
    if image_diff.old_value != image_diff.value:
        log_with_color(ecs_service_name + " New image getting deployed", color)
        log_with_color(ecs_service_name + " " + str(image_diff), color)
    else:
        log_with_color(ecs_service_name + " No change in image version", color)
    env_diff = next(x for x in diffs if x.field == 'environment')
    old_env, current_env = env_diff.old_value, env_diff.value
    env_vars = sorted(
        set(env_diff.old_value.keys()).union(env_diff.value.keys()))
    table_data = []
    table_data.append([
        Color('{autoyellow}Env. var.{/autoyellow}'),
        Color('{autoyellow}Old value{/autoyellow}'),
        Color('{autoyellow}Current value{/autoyellow}')
    ])
    for env_var in env_vars:
        old_val = old_env.get(env_var, '-')
        current_val = current_env.get(env_var, '-')
        if old_val != current_val:
            env_var_diff_color = 'autored'
            table_data.append([
                Color('{' + env_var_diff_color + '}' + env_var + '{/' +
                      env_var_diff_color + '}'), old_val, current_val
            ])
    if len(table_data) > 1:
        log_with_color(ecs_service_name + " Environment changes", color)
        print(SingleTable(table_data).table)
    else:
        log_with_color(
            ecs_service_name + " No change in environment variables", color)
Exemple #2
0
def fetch_and_print_new_events(service, existing_events, color):
    all_events = fetch_events(service)
    new_events = [evnt for evnt in all_events if evnt not in existing_events]
    for event in new_events:
        log_with_color(event['message'].replace("(", "").replace(")", "")[8:],
                       color)
    return all_events
Exemple #3
0
def deploy_task_definition(client, task_definition, cluster_name,
                           ecs_service_name, color, timeout_secs, action_name):
    deployment = DeployAction(client, cluster_name, ecs_service_name)
    log_with_color(f"Starting {action_name} for {ecs_service_name}", color)
    if deployment.service.desired_count == 0:
        desired_count = 1
    else:
        desired_count = deployment.service.desired_count
    deployment.service.set_desired_count(desired_count)
    deployment_succeeded = deploy_and_wait(deployment, task_definition, color,
                                           timeout_secs)
    if not deployment_succeeded:
        record_deployment_failure_metric(deployment.cluster_name,
                                         deployment.service_name)
        raise UnrecoverableException(ecs_service_name +
                                     f" {action_name} failed.")
    log_with_color(
        f"{ecs_service_name} {action_name}: Completed successfully.", color)
Exemple #4
0
def print_task_diff(ecs_service_name, diffs, color):
    image_diff = next(x for x in diffs if x.field == 'image')
    if image_diff.old_value != image_diff.value:
        log_with_color(ecs_service_name + " New image getting deployed", color)
        log_with_color(ecs_service_name + " " + str(image_diff), color)
    else:
        log_with_color(ecs_service_name + " No change in image version", color)
Exemple #5
0
def create_new_task_definition(color, ecr_image_uri, ecs_service_name,
                               env_name, sample_env_file_path, secrets_name,
                               service_name, client, cluster_name,
                               deployment_identifier, ecs_service_logical_name,
                               service_configuration, region):
    deployment = DeployAction(client, cluster_name, ecs_service_name)
    task_definition = deployment.get_current_task_definition(
        deployment.service)
    essential_container = find_essential_container(
        task_definition[u'containerDefinitions'])
    container_configurations = build_config(env_name, service_name,
                                            ecs_service_logical_name,
                                            sample_env_file_path,
                                            essential_container, secrets_name)
    task_definition.compute_diffs(essential_container, ecr_image_uri)
    print_task_diff(ecs_service_name, task_definition.diff, color)

    builder = TaskDefinitionBuilder(
        environment=env_name,
        service_name=ecs_service_logical_name,
        configuration=service_configuration,
        region=region,
    )
    updated_task_definition = EcsTaskDefinition(
        builder.build_task_definition(
            container_configurations=container_configurations,
            ecr_image_uri=ecr_image_uri,
            fallback_task_role=task_definition.role_arn,
            fallback_task_execution_role=task_definition.execution_role_arn,
        ))
    diff = DeepDiff(task_definition, updated_task_definition)
    diff.pop('dictionary_item_removed', 'no dictionary_item_removed')

    if diff:
        log_with_color(
            f"{ecs_service_name} task definition diffs: {pformat(diff)}",
            color)
    return deployment.update_task_definition(updated_task_definition,
                                             deployment_identifier)