示例#1
0
from testcontainers.core.container import DockerContainer

from ebonite.build.builder.base import use_local_installation
from ebonite.build.builder.docker import _DockerfileGenerator, DockerBuilder
from ebonite.build.docker import DockerImage, RemoteDockerRegistry, create_docker_client

from tests.build.conftest import has_docker
from tests.build.builder.test_base import ProviderMock, SECRET

CLEAN = True
IMAGE_NAME = 'ebonite_test_docker_builder_image'

REGISTRY_PORT = 5000
REGISTRY_HOST = f'localhost:{REGISTRY_PORT}'

no_docker = pytest.mark.skipif(not has_docker(),
                               reason='docker is unavailable or skipped')


@pytest.fixture
def docker_builder_local_registry():
    with use_local_installation():
        yield DockerBuilder(ProviderMock(), DockerImage(IMAGE_NAME))


@pytest.fixture
def docker_builder_remote_registry():
    with use_local_installation(), DockerContainer(
            'registry:latest').with_bind_ports(REGISTRY_PORT, REGISTRY_PORT):
        yield DockerBuilder(
            ProviderMock(),
示例#2
0
        yield img_name

    rm_image(img_name + ":latest")  # FIXME later


@pytest.fixture
def container_name():
    container_name = "ebaklya"
    yield container_name
    rm_container(container_name)


@pytest.fixture
def service_name():
    service_name = 'ebnt-test-service'
    yield service_name
    rm_container(service_name)
    rm_image(service_name + ":latest")


@pytest.mark.docker
@pytest.mark.skipif(not has_docker(), reason='no docker installed')
def test_run_docker_img(container_name):
    run_docker_img(container_name, 'mike0sv/ebaklya', ports_mapping={80: None}, detach=True)
    _assert_docker_container_running(container_name)


def _assert_docker_container_running(name):
    time.sleep(.1)
    assert is_docker_container_running(name)