예제 #1
0
def run(cluster, task, count, command, env, region, access_key_id,
        secret_access_key, profile, diff):
    """
    Run a one-off task.

    \b
    CLUSTER is the name of your cluster (e.g. 'my-custer') within ECS.
    TASK is the name of your task definition (e.g. 'my-task') within ECS.
    COMMAND is the number of tasks your service should run.
    """
    try:
        client = get_client(access_key_id, secret_access_key, region, profile)
        action = RunAction(client, cluster)

        td = action.get_task_definition(task)
        td.set_commands(**{key: value for (key, value) in command})
        td.set_environment(env)

        if diff:
            print_diff(td, 'Using task definition: %s' % task)

        action.run(td, count, 'ECS Deploy')

        click.secho('Successfully started %d instances of task: %s' %
                    (len(action.started_tasks), td.family_revision),
                    fg='green')

        for started_task in action.started_tasks:
            click.secho('- %s' % started_task['taskArn'], fg='green')
        click.secho(' ')

    except Exception as e:
        click.secho('%s\n' % str(e), fg='red', err=True)
        exit(1)
예제 #2
0
파일: cli.py 프로젝트: fabfuel/ecs-deploy
def run(cluster, task, count, command, env, region, access_key_id, secret_access_key, profile):
    """
    Run a one-off task.

    \b
    CLUSTER is the name of your cluster (e.g. 'my-custer') within ECS.
    TASK is the name of your task definintion (e.g. 'mytask') within ECS.
    COMMAND is the number of tasks your service should run.
    """
    try:
        client = get_client(access_key_id, secret_access_key, region, profile)
        action = RunAction(client, cluster)

        task_definition = action.get_task_definition(task)
        task_definition.set_commands(**{key: value for (key, value) in command})
        task_definition.set_environment(env)
        print_diff(task_definition, 'Using task definition: %s' % task)

        action.run(task_definition, count, 'ECS Deploy')

        click.secho('Successfully started %d instances of task: %s' % (len(action.started_tasks), task_definition.family_revision), fg='green')
        for started_task in action.started_tasks:
            click.secho('- %s' % started_task['taskArn'], fg='green')
        click.secho(' ')

    except Exception as e:
        click.secho('%s\n' % str(e), fg='red', err=True)
        exit(1)
예제 #3
0
def test_run_action_run(client, task_definition):
    action = RunAction(client, CLUSTER_NAME)
    client.run_task.return_value = dict(tasks=[dict(taskArn='A'), dict(taskArn='B')])
    action.run(task_definition, 2, 'test')

    client.run_task.assert_called_once_with(
        cluster=CLUSTER_NAME,
        task_definition=task_definition.family_revision,
        count=2,
        started_by='test',
        overrides=dict(containerOverrides=task_definition.get_overrides())
    )

    assert len(action.started_tasks) == 2
예제 #4
0
def test_run_action_run(client, task_definition):
    action = RunAction(client, CLUSTER_NAME)
    client.run_task.return_value = dict(
        tasks=[dict(taskArn='A'), dict(taskArn='B')])
    action.run(task_definition, 2, 'test')

    client.run_task.assert_called_once_with(
        cluster=CLUSTER_NAME,
        task_definition=task_definition.family_revision,
        count=2,
        started_by='test',
        overrides=dict(containerOverrides=task_definition.get_overrides()))

    assert len(action.started_tasks) == 2
예제 #5
0
def test_run_action_run(client, task_definition):
    action = RunAction(client, CLUSTER_NAME)
    client.run_task.return_value = dict(
        tasks=[dict(taskArn='A'), dict(taskArn='B')])
    action.run(task_definition, 2, 'test', LAUNCH_TYPE_EC2, (), (), False)

    client.run_task.assert_called_once_with(
        cluster=CLUSTER_NAME,
        task_definition=task_definition.family_revision,
        count=2,
        started_by='test',
        overrides=dict(containerOverrides=task_definition.get_overrides()),
        launchtype=LAUNCH_TYPE_EC2,
        subnets=(),
        security_groups=(),
        public_ip=False)

    assert len(action.started_tasks) == 2