예제 #1
0
def main():
    args = parse_args()

    if not args.mesos_id:
        sys.stdout.write(
            "The Mesos task id you supplied seems to be an empty string! Please provide a valid task id.\n")
        sys.exit(2)

    base_docker_url = get_docker_host()
    docker_client = Client(base_url=base_docker_url)

    container_id = get_container_id_for_mesos_id(docker_client, args.mesos_id)

    if container_id:
        try:
            with time_limit(args.timeout):
                output, return_code = execute_in_container(docker_client, container_id, args.cmd, args.timeout)
            sys.stdout.write(output)
        except TimeoutException:
            sys.stdout.write("Command timed out!\n")
            return_code = 1
        finally:
            sys.exit(return_code)
    else:
        sys.stdout.write("Could not find container with MESOS_TASK_ID '%s'.\n" % args.mesos_id)
        sys.exit(1)
예제 #2
0
def paasta_local_run(args):
    if args.pull:
        build = False
    elif args.build:
        build = True
    else:
        build = local_makefile_present()

    service = figure_out_service_name(args, soa_dir=args.yelpsoa_config_root)
    base_docker_url = get_docker_host()
    docker_client = Client(base_url=base_docker_url)

    if build:
        default_tag = 'paasta-local-run-%s-%s' % (service, get_username())
        tag = os.environ.get('DOCKER_TAG', default_tag)
        os.environ['DOCKER_TAG'] = tag
        pull_image = False
        paasta_cook_image(None, service=service, soa_dir=args.yelpsoa_config_root)
    else:
        pull_image = True
        tag = None

    try:
        configure_and_run_docker_container(
            docker_client=docker_client,
            docker_hash=tag,
            service=service,
            args=args,
            pull_image=pull_image,
        )
    except errors.APIError as e:
        sys.stderr.write('Can\'t run Docker container. Error: %s\n' % str(e))
        sys.exit(1)
예제 #3
0
def after_scenario(context, scenario):
    if getattr(context, "tmpdir", None):
        shutil.rmtree(context.tmpdir)
    if getattr(context, "running_container_id", None):
        base_docker_url = get_docker_host()
        docker_client = Client(base_url=base_docker_url)
        docker_client.stop(container=context.running_container_id)
        docker_client.remove_container(container=context.running_container_id)
예제 #4
0
def paasta_local_run(args):
    validate_environment()

    service = figure_out_service_name(args, soa_dir=args.yelpsoa_config_root)

    base_docker_url = get_docker_host()

    docker_client = Client(base_url=base_docker_url)

    default_tag = 'paasta-local-run-%s-%s' % (service, get_username())
    tag = os.environ.get('DOCKER_TAG', default_tag)
    os.environ['DOCKER_TAG'] = tag

    paasta_cook_image(None, service=service, soa_dir=args.yelpsoa_config_root)

    try:
        configure_and_run_docker_container(docker_client, tag, service, args)
    except errors.APIError as e:
        sys.stderr.write('Can\'t run Docker container. Error: %s\n' % str(e))
        sys.exit(1)
예제 #5
0
def paasta_local_run(args):
    validate_environment()

    service = figure_out_service_name(args, soa_dir=args.yelpsoa_config_root)

    base_docker_url = get_docker_host()

    docker_client = Client(base_url=base_docker_url)

    default_tag = 'paasta-local-run-%s-%s' % (service, get_username())
    tag = os.environ.get('DOCKER_TAG', default_tag)
    os.environ['DOCKER_TAG'] = tag

    paasta_cook_image(None, service=service, soa_dir=args.yelpsoa_config_root)

    try:
        configure_and_run_docker_container(docker_client, tag, service, args)
    except errors.APIError as e:
        sys.stderr.write('Can\'t run Docker container. Error: %s\n' % str(e))
        sys.exit(1)
예제 #6
0
파일: local_run.py 프로젝트: sbcoba/paasta
def paasta_local_run(args):
    if args.pull:
        build = False
    elif args.build:
        build = True
    else:
        build = local_makefile_present()

    service = figure_out_service_name(args, soa_dir=args.yelpsoa_config_root)
    cluster = guess_cluster(service=service, args=args)
    instance = guess_instance(service=service, cluster=cluster, args=args)
    base_docker_url = get_docker_host()
    docker_client = Client(base_url=base_docker_url)

    if build:
        default_tag = 'paasta-local-run-%s-%s' % (service, get_username())
        tag = os.environ.get('DOCKER_TAG', default_tag)
        os.environ['DOCKER_TAG'] = tag
        pull_image = False
        paasta_cook_image(args=None,
                          service=service,
                          soa_dir=args.yelpsoa_config_root)
    else:
        pull_image = True
        tag = None

    try:
        configure_and_run_docker_container(
            docker_client=docker_client,
            docker_hash=tag,
            service=service,
            instance=instance,
            cluster=cluster,
            args=args,
            pull_image=pull_image,
        )
    except errors.APIError as e:
        sys.stderr.write('Can\'t run Docker container. Error: %s\n' % str(e))
        sys.exit(1)
예제 #7
0
def docker_is_available(context):
    base_docker_url = get_docker_host()
    docker_client = Client(base_url=base_docker_url)
    assert docker_client.ping()
    context.docker_client = docker_client
def docker_is_available(context):
    base_docker_url = get_docker_host()
    docker_client = Client(base_url=base_docker_url)
    assert docker_client.ping()
    context.docker_client = docker_client
예제 #9
0
def get_docker_client():
    base_docker_url = get_docker_host()
    return Client(base_url=base_docker_url)
def get_docker_client():
    base_docker_url = get_docker_host()
    return Client(base_url=base_docker_url)