示例#1
0
def deploy(cluster, service, tag, image, command, env, role, task, region,
           access_key_id, secret_access_key, profile, timeout, newrelic_apikey,
           newrelic_appid, comment, user, ignore_warnings, diff):
    """
    Redeploy or modify a service.

    \b
    CLUSTER is the name of your cluster (e.g. 'my-custer') within ECS.
    SERVICE is the name of your service (e.g. 'my-app') within ECS.

    When not giving any other options, the task definition will not be changed.
    It will just be duplicated, so that all container images will be pulled
    and redeployed.
    """

    try:
        client = get_client(access_key_id, secret_access_key, region, profile)
        deployment = DeployAction(client, cluster, service)

        if task:
            td = deployment.get_task_definition(task)
            click.secho('Deploying based on task definition: %s' % task)
        else:
            td = deployment.get_current_task_definition(deployment.service)

        td.set_images(tag, **{key: value for (key, value) in image})
        td.set_commands(**{key: value for (key, value) in command})
        td.set_environment(env)
        td.set_role_arn(role)

        if diff:
            print_diff(td)

        click.secho('Creating new task definition revision')
        new_td = deployment.update_task_definition(td)

        click.secho('Successfully created revision: %d' % new_td.revision,
                    fg='green')
        click.secho('Successfully deregistered revision: %d\n' % td.revision,
                    fg='green')

        record_deployment(tag, newrelic_apikey, newrelic_appid, comment, user)

        click.secho('Updating service')
        deployment.deploy(new_td)
        click.secho('Successfully changed task definition to: %s:%s\n' %
                    (new_td.family, new_td.revision),
                    fg='green')

        wait_for_finish(action=deployment,
                        timeout=timeout,
                        title='Deploying task definition',
                        success_message='Deployment successful',
                        failure_message='Deployment failed',
                        ignore_warnings=ignore_warnings)

    except Exception as e:
        click.secho('%s\n' % str(e), fg='red', err=True)
        exit(1)