Exemple #1
0
    def describe(self, deployment_pb, repo=None):
        deployment_spec = deployment_pb.spec
        aws_config = deployment_spec.aws_lambda_operator_config

        bento_path = repo.get(deployment_spec.bento_name,
                              deployment_spec.bento_version)
        bento_config = load_bentoml_config(bento_path)
        with TemporaryServerlessConfig(
                archive_path=bento_path,
                deployment_name=deployment_pb.name,
                region=aws_config.region,
                stage=deployment_pb.namespace,
                provider_name='aws',
                functions=generate_aws_handler_functions_config(
                    bento_config['apis']),
        ) as tempdir:
            try:
                response = call_serverless_command(["serverless", "info"],
                                                   tempdir)
                info_json = parse_serverless_info_response_to_json_string(
                    response)
                state = DeploymentState(state=DeploymentState.RUNNING,
                                        info_json=info_json)
            except BentoMLException as e:
                state = DeploymentState(state=DeploymentState.ERROR,
                                        error_message=str(e))

        return DescribeDeploymentResponse(status=Status.OK(), state=state)
Exemple #2
0
    def apply(self, deployment_pb, repo, prev_deployment=None):
        deployment_spec = deployment_pb.spec
        gcp_config = deployment_spec.gcp_function_operator_config
        bento_path = repo.get(deployment_spec.bento_name,
                              deployment_spec.bento_version)

        bento_config = load_bentoml_config(bento_path)
        with TemporaryServerlessContent(
                archive_path=bento_path,
                deployment_name=deployment_pb.name,
                bento_name=deployment_spec.bento_name,
                template_type='google-python',
        ) as output_path:
            generate_main_py(bento_config['name'], bento_config['apis'],
                             output_path)
            generate_serverless_configuration_for_gcp_function(
                service_name=bento_config['name'],
                apis=bento_config['apis'],
                output_path=output_path,
                region=gcp_config.region,
                stage=deployment_pb.namespace,
            )
            call_serverless_command(["deploy"], output_path)

        res_deployment_pb = Deployment(state=DeploymentState())
        res_deployment_pb.CopyFrom(deployment_pb)
        state = self.describe(res_deployment_pb, repo).state
        res_deployment_pb.state.CopyFrom(state)

        return ApplyDeploymentResponse(status=Status.OK(),
                                       deployment=res_deployment_pb)
Exemple #3
0
    def delete(self, deployment_pb, repo=None):
        state = self.describe(deployment_pb, repo).state
        if state.state != DeploymentState.RUNNING:
            message = ('Failed to delete, no active deployment {name}. '
                       'The current state is {state}'.format(
                           name=deployment_pb.name,
                           state=DeploymentState.State.Name(state.state),
                       ))
            return DeleteDeploymentResponse(status=Status.ABORTED(message))

        deployment_spec = deployment_pb.spec
        aws_config = deployment_spec.aws_lambda_operator_config

        bento_path = repo.get(deployment_spec.bento_name,
                              deployment_spec.bento_version)
        bento_config = load_bentoml_config(bento_path)

        with TemporaryServerlessConfig(
                archive_path=bento_path,
                deployment_name=deployment_pb.name,
                region=aws_config.region,
                stage=deployment_pb.namespace,
                provider_name='aws',
                functions=generate_aws_handler_functions_config(
                    bento_config['apis']),
        ) as tempdir:
            response = call_serverless_command(['serverless', 'remove'],
                                               tempdir)
            if "Serverless: Stack removal finished..." in response:
                status = Status.OK()
            else:
                status = Status.ABORTED()

        return DeleteDeploymentResponse(status=status)
Exemple #4
0
    def apply(self, deployment_pb, repo, prev_deployment=None):
        ensure_docker_available_or_raise()
        deployment_spec = deployment_pb.spec
        aws_config = deployment_spec.aws_lambda_operator_config

        bento_path = repo.get(deployment_spec.bento_name,
                              deployment_spec.bento_version)
        bento_config = load_bentoml_config(bento_path)

        template = 'aws-python3'
        minimum_python_version = version.parse('3.0.0')
        bento_python_version = version.parse(
            bento_config['env']['python_version'])
        if bento_python_version < minimum_python_version:
            template = 'aws-python'

        with TemporaryServerlessContent(
                archive_path=bento_path,
                deployment_name=deployment_pb.name,
                bento_name=deployment_spec.bento_name,
                template_type=template,
        ) as output_path:
            generate_handler_py(deployment_spec.bento_name,
                                bento_config['apis'], output_path)
            generate_serverless_configuration_for_aws_lambda(
                service_name=deployment_pb.name,
                apis=bento_config['apis'],
                output_path=output_path,
                region=aws_config.region,
                stage=deployment_pb.namespace,
            )
            logger.info(
                'Installing additional packages: serverless-python-requirements, '
                'serverless-apigw-binary')
            install_serverless_plugin("serverless-python-requirements",
                                      output_path)
            install_serverless_plugin("serverless-apigw-binary", output_path)
            logger.info('Deploying to AWS Lambda')
            call_serverless_command(["deploy"], output_path)

        res_deployment_pb = Deployment(state=DeploymentState())
        res_deployment_pb.CopyFrom(deployment_pb)
        state = self.describe(res_deployment_pb, repo).state
        res_deployment_pb.state.CopyFrom(state)
        return ApplyDeploymentResponse(status=Status.OK(),
                                       deployment=res_deployment_pb)