当前位置: 首页>>代码示例>>Python>>正文


Python Client.logs方法代码示例

本文整理汇总了Python中docker.client.Client.logs方法的典型用法代码示例。如果您正苦于以下问题:Python Client.logs方法的具体用法?Python Client.logs怎么用?Python Client.logs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docker.client.Client的用法示例。


在下文中一共展示了Client.logs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import logs [as 别名]
class Runner:
    """
    This class is in charge of loading test suites and runs them on different environments

    """
    STOP_TIMEOUT = 3

    def __init__(self, cfg):
        from docker.client import Client
        from docker.utils import kwargs_from_env

        self.config = cfg
        docker_kwargs = kwargs_from_env()
        docker_kwargs['tls'].assert_hostname = False
        self.docker = Client(**docker_kwargs)


    def run(self, build, *tests):
        """
        Run all the test suites passed in as parameters on the given build
        This method will start a container of the build, run the tests and stop it

        """
        from docker.utils import create_host_config

        print("Running tests on {}".format(build.name))
        ports = self.config['environment']['ports']
        host = self.config['global'].get('docker_host', os.getenv('DOCKER_HOST').split('/')[-1].split(':')[0])
        container = self.docker.create_container(
                image=build.docker_tag,
                command='/bin/bash -c "nc -l 8080"',
                ports=ports,
                host_config=create_host_config(port_bindings=dict(zip(ports, [None] * len(ports))))
            ).get('Id')
        self.docker.start(container)
        info = self.docker.inspect_container(container)
        port_bindings = {port: bind[0]['HostPort'] for port, bind in info['NetworkSettings']['Ports'].items()}
        for test in tests:
            test.run(host, port_bindings, build.context)
        self.docker.stop(container, timeout=self.STOP_TIMEOUT)
        log_file_path = os.path.join(self.config['global'].get('logs_dir', '/tmp'), '{}.log'.format(build.name))
        with open(log_file_path, 'wb') as logs:
            logs.write(self.docker.logs(container, stdout=True, stderr=True, stream=False))
        print("Container logs wrote to {}".format(log_file_path))
开发者ID:quanta-computing,项目名称:quanta-php-module,代码行数:46,代码来源:runner.py

示例2: _run_build

# 需要导入模块: from docker.client import Client [as 别名]
# 或者: from docker.client.Client import logs [as 别名]
def _run_build(build):
    """
    The REPOSITORY_DIR will contain a directory for each Project
    instance.

    Each Project instance directory will have a directory called "clone"
    which is the master clone.  Then, each time a build is queued, we
    create a local clone from that repository named after the current
    build's commit sha.

    REPOSITORY_DIR/
        django/
            clone/
            a18bc/
            .../

    Once the local clone is created, we build the docker image, create
    the container and run the tests.
    """

    project = build.project

    # docker client
    c = Client(build.host)

    project_dir = os.path.join(REPOSITORY_DIR, project.slug)
    main_repo_path = os.path.join(project_dir, 'clone')

    if not os.path.exists(main_repo_path):

        # assert project repo present
        os.makedirs(project_dir)

        # clone repo
        repo = Repo.clone_from(project.repository, main_repo_path)

    else:
        repo = Repo(main_repo_path)
        remote = repo.remote()
        remote.pull()

    # build_path is a local clone of the project and it's named after the
    # current build's commit sha
    build_path = os.path.join(project_dir, build.commit_sha)

    if not os.path.exists(build_path):
        repo = Repo.clone_from(main_repo_path, build_path)
    else:
        repo = Repo(build_path)

    g = repo.git
    g.checkout(build.commit_sha)

    image_name = ':'.join([project.slug, build.commit_sha])

    img_id, res = c.build(build_path)

    # create image
    c.tag(img_id, repository=project.slug, tag=build.commit_sha)

    # run build command from new image and report output
    container = c.create_container(image_name, project.build_command,
                                   stdin_open=True, tty=True)

    container_id = container.get('Id')

    c.start(container_id)
    return_code = c.wait(container_id)

    out = c.logs(container_id)
    build.result = out

    build.return_code = return_code
    build.save()
开发者ID:honza,项目名称:wharf-ci,代码行数:76,代码来源:tasks.py


注:本文中的docker.client.Client.logs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。