Exemple #1
0
def is_container_running(container_name, host: TargetHost = None):
    if has_docker():
        time.sleep(.1)
        host = host or LocalTargetHost()
        with create_docker_client(host.get_host()) as client:
            containers = client.containers.list()
            return any(container_name == c.name for c in containers)
Exemple #2
0
def run_good_attached():
    container_name = 'test'

    img_registry = DefaultDockerRegistry()
    img = DockerImage('mike0sv/ebaklya', docker_registry=img_registry)
    host = LocalTargetHost()
    instance = DockerServiceInstance(container_name, img, host, {80: 8080})

    runner = SimpleDockerRunner()
    runner.run(instance, detach=False, rm=True)
Exemple #3
0
def run_detached_and_remove():
    container_name = 'test'

    img_registry = DefaultDockerRegistry()
    img = DockerImage('test_broken_image', docker_registry=img_registry)
    host = LocalTargetHost()
    instance = DockerServiceInstance(container_name, img, host, {80: 8080})

    runner = SimpleDockerRunner()
    runner.run(instance, detach=True, rm=True)
Exemple #4
0
def test_run_remote_registry(runner, registry):
    img = DockerImage(IMAGE_NAME,
                      repository=REPOSITORY_NAME,
                      docker_registry=registry)
    host = LocalTargetHost()
    instance = DockerServiceInstance(CONTAINER_NAME, img, host)

    if is_container_running(CONTAINER_NAME):
        stop_container(CONTAINER_NAME, host)

    runner = runner(host, img, CONTAINER_NAME)
    runner.run(instance)
    assert is_container_running(CONTAINER_NAME, host)
Exemple #5
0
def test_run_local_fail_inside_container_attached(runner, registry):
    img = DockerImage(BROKEN_IMAGE_NAME,
                      repository=REPOSITORY_NAME,
                      docker_registry=registry)
    host = LocalTargetHost()
    instance = DockerServiceInstance(CONTAINER_NAME, img, host, {80: 8080})

    if is_container_running(CONTAINER_NAME):
        stop_container(CONTAINER_NAME, host)

    with pytest.raises(DockerRunnerException):
        runner = runner(host, img, CONTAINER_NAME)
        runner.run(instance, detach=False, rm=True)
Exemple #6
0
def test_run_default_registry(runner):
    img_registry = DefaultDockerRegistry()
    img = DockerImage(IMAGE_NAME, docker_registry=img_registry)

    host = LocalTargetHost()

    instance = DockerServiceInstance(CONTAINER_NAME, img, host, {80: 8080})

    if is_container_running(CONTAINER_NAME):
        stop_container(CONTAINER_NAME, host)

    runner = runner(host, img, CONTAINER_NAME)
    runner.run(instance, detach=True)
    assert is_container_running(CONTAINER_NAME, host)
Exemple #7
0
def test_run_local_image_name_that_will_never_exist(runner):
    img_registry = DefaultDockerRegistry()
    img = DockerImage('ebonite_image_name_that_will_never_exist',
                      docker_registry=img_registry)

    host = LocalTargetHost()

    instance = DockerServiceInstance(CONTAINER_NAME, img, host, {80: 8080})

    if is_container_running(CONTAINER_NAME):
        stop_container(CONTAINER_NAME, host)

    with pytest.raises(HTTPError):
        runner = runner(host, img, CONTAINER_NAME)
        runner.run(instance)
Exemple #8
0
def run_docker_img(container_name: str, image_name: str, port_mapping=None, detach=False):
    if port_mapping is None:
        port_mapping = {9000: 9000}
    runner = SimpleDockerRunner()
    service = DockerServiceInstance(container_name, DockerImage(image_name), LocalTargetHost(), port_mapping)
    runner.run(service, detach=detach)
Exemple #9
0
def rm_image(image_tag: str, host: TargetHost = None):
    host = host or LocalTargetHost()
    with create_docker_client(host.get_host()) as client:
        tags = [t for i in client.images.list() for t in i.tags]
        if any(image_tag == t for t in tags):
            client.images.remove(image_tag, force=True)
Exemple #10
0
def rm_container(container_name: str, host: TargetHost = None):
    host = host or LocalTargetHost()
    with create_docker_client(host.get_host()) as client:
        containers = client.containers.list()
        if any(container_name == c.name for c in containers):
            client.containers.get(container_name).remove(force=True)