Esempio n. 1
0
def build_docker_image(name: str,
                       obj,
                       server: Server = None,
                       env: DockerEnv = None,
                       tag: str = 'latest',
                       repository: str = None,
                       force_overwrite: bool = False,
                       **kwargs) -> Image:
    """Build docker image from object

    :param name: name of the resultimg image
    :param obj: obj to build image. must be convertible to Buildable: Model, Pipeline, list of one of those, etc.
    :param server: server to build image with
    :param env: DockerEnv to build in. Default - local docker daemon
    :param tag: image tag
    :param repository: image repository
    :param force_overwrite: wheter to force overwrite existing image
    :parma kwargs: additional arguments for DockerBuilder.build_image
    """
    if server is None:
        try:
            from ebonite.ext.flask import FlaskServer
            server = FlaskServer()
        except ImportError:
            raise RuntimeError(
                'cannot use default FlaskServer - flask or flasgger are not installed'
            )
    env = env or DockerEnv()
    source = BuildableAnalyzer.analyze(obj, server=server)
    builder: DockerBuilder = env.get_builder()
    params = builder.create_image(name, env, tag, repository)
    builder.build_image(source, params, env, force_overwrite, **kwargs)
    image = Image(name, source, params=params)
    image.environment = RuntimeEnvironment('temp_env', params=env)
    return image.bind_builder(builder)
Esempio n. 2
0
def run_model_server(model: Model, server: Server = None):
    """
    :func:`.start_runtime` wrapper helper which starts Ebonite runtime for given model and (optional) server

    :param model: model to start Ebonite runtime for
    :param server: server to use for Ebonite runtime, default is a flask-based server
    :return: nothing
    """

    if server is None:
        if module_importable('aiohttp') and module_importable(
                'aiohttp_swagger'):
            from ebonite.ext.aiohttp import AIOHTTPServer
            server = AIOHTTPServer()
        elif module_importable('flask') and module_importable('flasgger'):
            from ebonite.ext.flask import FlaskServer
            server = FlaskServer()
        else:
            raise RuntimeError(
                'You need to install flask and flasgger to use test flask server'
            )

    class MockLoader(ModelLoader):
        def load(self) -> Interface:
            model.ensure_loaded()
            return model_interface(model)

    start_runtime(MockLoader(), server)
Esempio n. 3
0
def build_model_docker(image_name: str, model: 'core.Model', server: Server = None,
                       image_tag='latest', force_overwrite=False, **kwargs):
    """
    Builds docker image from Model instance

    :param image_name: docker image name to create
    :param model: model to create image
    :param server: server instance to wrap model
    :param image_tag: docker image tag
    :param force_overwrite: force overwrite image if it exists
    :param kwargs: same as in DockerBuilder.__init__
    """
    if server is None:
        from ebonite.ext.flask import FlaskServer
        server = FlaskServer()

    if not module_importable('docker'):
        raise RuntimeError("Can't build docker container: docker module is not installed. Install it "
                           "with 'pip install docker'")

    from ebonite.build.builder.docker_builder import DockerBuilder, is_docker_running

    if not is_docker_running():
        raise RuntimeError("Docker is unavailable")

    provider = MLModelProvider(model, server)
    builder = DockerBuilder(provider, image_name, image_tag, force_overwrite, **kwargs)
    builder.build()
Esempio n. 4
0
 def get_default_server(self):
     """
     :return: Default server implementation for this client
     """
     if self.default_server is None:
         from ebonite.ext.flask import FlaskServer
         self.default_server = FlaskServer()
     return self.default_server
Esempio n. 5
0
def build_model_flask_docker(image_name: str,
                             model: 'core.Model',
                             image_tag='latest',
                             force_overwrite=False,
                             debug=False):
    """
    Builds flask docker image with nginx and uwsgi from Model instance

    :param image_name: docker image name to create
    :param model: model to create image
    :param image_tag: docker image tag
    :param force_overwrite: force overwrite image if it exists
    :param debug: run server in debug mode
    """
    kwargs = {
        'templates_dir': os.path.join(os.path.dirname(__file__),
                                      TEMPLATES_DIR),
        'run_cmd': '["/usr/bin/supervisord"]'
    }
    build_model_docker(image_name, model, FlaskServer(), image_tag,
                       force_overwrite, debug, **kwargs)
Esempio n. 6
0
def python_builder(created_model) -> PythonBuilder:
    return PythonBuilder(MLModelProvider(created_model, FlaskServer()))
Esempio n. 7
0
def server():
    return FlaskServer()
Esempio n. 8
0
def python_multi_builder(created_model) -> PythonBuilder:
    return PythonBuilder(MLModelMultiProvider([created_model], FlaskServer()))