示例#1
0
    def retrieve(bento, target_dir):
        if ':' not in bento:
            _echo(f'BentoService {bento} invalid - specify name:version')
            return
        name, version = bento.split(':')

        yatai_client = get_default_yatai_client()

        get_bento_result = yatai_client.repository.get(name, version)
        if get_bento_result.status.status_code != yatai_proto.status_pb2.Status.OK:
            error_code, error_message = status_pb_to_error_code_and_message(
                get_bento_result.status)
            raise CLIException(
                f'Failed to access BentoService {name}:{version} - '
                f'{error_code}:{error_message}')

        if get_bento_result.bento.uri.s3_presigned_url:
            bento_service_bundle_path = get_bento_result.bento.uri.s3_presigned_url
        if get_bento_result.bento.uri.gcs_presigned_url:
            bento_service_bundle_path = get_bento_result.bento.uri.gcs_presigned_url
        else:
            bento_service_bundle_path = get_bento_result.bento.uri.uri

        safe_retrieve(bento_service_bundle_path, target_dir)

        click.echo('Service %s artifact directory => %s' % (name, target_dir))
    def download_to_directory(self, bento_pb, target_dir: str) -> None:
        """
        Download or move bundle bundle to target directory.

        Args:
            bento_pb: bento bundle protobuf dict
            target_dir (`str`):

        Returns:
            None

        Raises:
            BentoMLException:
                Unrecognised Bento bundle storage type
        """
        if bento_pb.uri.type == BentoUri.S3:
            bento_service_bundle_path = bento_pb.uri.s3_presigned_url
        elif bento_pb.uri.type == BentoUri.GCS:
            bento_service_bundle_path = bento_pb.uri.gcs_presigned_url
        elif bento_pb.uri.type == BentoUri.LOCAL:
            # Download from remote yatai otherwise provide the file path.
            if is_remote_yatai(self.yatai_service):
                bento_service_bundle_path = self._download_bento(
                    bento_pb.name, bento_pb.version)
            else:
                bento_service_bundle_path = bento_pb.uri.uri
        else:
            raise BentoMLException(
                f'Unrecognized Bento bundle storage type {bento_pb.uri.type}')

        safe_retrieve(bento_service_bundle_path, target_dir)
示例#3
0
        def ContainerizeBento(self, request, context=None):
            try:
                ensure_docker_available_or_raise()
                tag = request.tag
                if tag is None or len(tag) == 0:
                    name = to_valid_docker_image_name(request.bento_name)
                    version = to_valid_docker_image_version(request.bento_version)
                    tag = f"{name}:{version}"
                if ":" not in tag:
                    version = to_valid_docker_image_version(request.bento_version)
                    tag = f"{tag}:{version}"
                import docker

                docker_client = docker.from_env()
                bento_pb = self.bento_metadata_store.get(
                    request.bento_name, request.bento_version
                )
                if not bento_pb:
                    raise YataiRepositoryException(
                        f'BentoService {request.bento_name}:{request.bento_version} '
                        f'does not exist'
                    )

                with TempDirectory() as temp_dir:
                    temp_bundle_path = f'{temp_dir}/{bento_pb.name}'
                    bento_service_bundle_path = bento_pb.uri.uri
                    if bento_pb.uri.type == BentoUri.S3:
                        bento_service_bundle_path = self.repo.get(
                            bento_pb.name, bento_pb.version
                        )
                    elif bento_pb.uri.type == BentoUri.GCS:
                        bento_service_bundle_path = self.repo.get(
                            bento_pb.name, bento_pb.version
                        )
                    safe_retrieve(bento_service_bundle_path, temp_bundle_path)
                    try:
                        docker_client.images.build(
                            path=temp_bundle_path,
                            tag=tag,
                            buildargs=dict(request.build_args),
                        )
                    except (docker.errors.APIError, docker.errors.BuildError) as error:
                        logger.error(f'Encounter container building issue: {error}')
                        raise YataiRepositoryException(error)
                    if request.push is True:
                        try:
                            docker_client.images.push(
                                repository=request.repository, tag=tag
                            )
                        except docker.errors.APIError as error:
                            raise YataiRepositoryException(error)

                    return ContainerizeBentoResponse(status=Status.OK(), tag=tag)
            except BentoMLException as e:
                logger.error(f"RPC ERROR ContainerizeBento: {e}")
                return ContainerizeBentoResponse(status=e.status_proto)
            except Exception as e:  # pylint: disable=broad-except
                logger.error(f"RPC ERROR ContainerizeBento: {e}")
                return ContainerizeBentoResponse(status=Status.INTERNAL(e))
示例#4
0
    def download_to_directory(self, bento_pb, target_dir):
        if bento_pb.uri.s3_presigned_url:
            bento_service_bundle_path = bento_pb.uri.s3_presigned_url
        elif bento_pb.uri.gcs_presigned_url:
            bento_service_bundle_path = bento_pb.uri.gcs_presigned_url
        else:
            bento_service_bundle_path = bento_pb.uri.uri

        safe_retrieve(bento_service_bundle_path, target_dir)