Beispiel #1
0
def run_docker_instance(image: Image,
                        name: str = None,
                        env: DockerEnv = None,
                        port_mapping: Dict[int, int] = None,
                        instance_kwargs: Dict[str, Any] = None,
                        rm: bool = False,
                        detach: bool = True,
                        **kwargs) -> RuntimeInstance:
    """Create and run docker container

    :param image: image to build from
    :param name: name of the container. defaults to image name
    :param env: DockerEnv to run in. Default - local docker daemon
    :param port_mapping: port mapping for container
    :param instance_kwargs: additional DockerInstance args
    :param rm: wheter to remove container on exit
    :param detach: wheter to detach from container after run
    :param kwargs: additional args for DockerRunner.run
    """
    env = env or DockerEnv()
    name = name or image.name
    runner: DockerRunner = env.get_runner()
    params = runner.create_instance(name, port_mapping, **instance_kwargs
                                    or {})
    runner.run(params, image.params, env, rm, detach, **kwargs)
    instance = RuntimeInstance(name, params=params,
                               image_id=image.id).bind_runner(runner)
    instance.environment = RuntimeEnvironment('temp_env', params=env)
    return instance
Beispiel #2
0
    def run_instance(self,
                     name: str,
                     image: Image,
                     environment: RuntimeEnvironment = None,
                     **kwargs) -> RuntimeInstance:
        """
        Runs model service instance and stores it to repository

        :param name: name of instance to run
        :param image: image to run instance from
        :param environment: environment to run instance in, if no given `localhost` is used
        :return: :class:`~ebonite.core.objects.RuntimeInstance` instance representing run instance
        """

        if environment is None:
            environment = self.get_default_environment()
        runner = environment.params.get_runner()

        params = runner.create_instance(name, **kwargs)

        instance = RuntimeInstance(name, params=params)
        instance.image = image
        instance.environment = environment
        instance = self.meta_repo.create_instance(instance)

        runner.run(params, image.params, environment.params, **kwargs)

        return instance.bind_runner(runner)
Beispiel #3
0
    def create_instance(self, image: Image, name: str = None, environment: RuntimeEnvironment = None, run=False,
                        runner_kwargs: Dict[str, object] = None,
                        **instance_kwargs) -> RuntimeInstance:
        """
        Runs model service instance and stores it to repository

        :param image: image to run instance from
        :param name: name of instance to run
        :param environment: environment to run instance in, if no given `localhost` is used
        :param run:  whether to automatically run instance after creation
        :param runner_kwargs: additional parameters for runner
        :param instance_kwargs: additional parameters for instance
        :return: :class:`~ebonite.core.objects.RuntimeInstance` instance representing run instance
        """

        if environment is None:
            environment = self.get_default_environment()

        if name is not None and self.meta_repo.get_instance_by_name(name, image, environment) is not None:
            raise ExistingInstanceError(name)

        runner = environment.params.get_runner()

        instance = RuntimeInstance(name)

        instance.params = runner.create_instance(instance.name, **instance_kwargs)
        instance.image = image
        instance.environment = environment
        instance.bind_runner(runner)
        instance = self.meta_repo.create_instance(instance)
        if run:
            runner_kwargs = runner_kwargs or {}
            instance.run(**runner_kwargs)
        return self._bind(instance)
Beispiel #4
0
    def delete_instance(self, instance: RuntimeInstance, meta_only: bool = False):
        """"
        Stops instance of model service and deletes it from repository

        :param instance: instance to delete
        :param meta_only: only remove from metadata, do not stop instance
        :return: nothing
        """
        return instance.delete(meta_only)