def container_name(): name = "{}-{}".format(CONTAINER_NAME, int(time.time() * 1000)) yield name if not CLEAR: return from ebonite.ext.docker import DockerRunner, DockerBuilder, DockerContainer, DockerImage, DockerEnv DockerRunner().remove_instance(DockerContainer(name), DockerEnv(), force=True) DockerBuilder().delete_image(DockerImage(name), DockerEnv())
def run_good_attached(): container_name = 'test' img_registry = DockerRegistry() img = DockerImage('mike0sv/ebaklya', registry=img_registry) instance = DockerContainer(container_name, port_mapping={80: 8080}) host = DockerEnv() runner = DockerRunner() runner.run(instance, img, host, detach=False, rm=True)
def run_detached_and_remove(): container_name = 'test' img_registry = DockerRegistry() img = DockerImage('test_broken_image', registry=img_registry) instance = DockerContainer(container_name) host = DockerEnv() runner = DockerRunner() runner.run(instance, img, host, detach=True, rm=True)
def run_attached(): container_name = 'test' img_registry = DockerRegistry() img = DockerImage('test_broken_image', registry=img_registry) instance = DockerContainer(container_name, port_mapping={80: 8080}) host = DockerEnv() runner = DockerRunner() runner.run(instance, img, host, detach=False, rm=False)
def _check_runner(runner, img, env: DockerEnv, **kwargs): instance = DockerContainer(CONTAINER_NAME, port_mapping={80: None}) runner = runner(env, img, CONTAINER_NAME) assert not runner.is_running(instance, env) runner.run(instance, img, env, **kwargs) time.sleep(.1) assert runner.is_running(instance, env) runner.stop(instance, env) time.sleep(.1) assert not runner.is_running(instance, env)
def runner(pytestconfig): if not has_docker() or 'not docker' in pytestconfig.getoption('markexpr'): pytest.skip('skipping docker tests') args = [] def _runner(docker_env: DockerEnv, image: DockerImage, container_name: str): args.append((docker_env, image, container_name)) return DockerRunner() yield _runner runner = DockerRunner() for env, img, container in args: runner.remove_instance(DockerContainer(container), env, force=True) with env.daemon.client() as client: env.registry.delete_image(client, img)