Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Several implements of proto and stub-code | 关于管理proto和stub-code的几种实现 #5

Open
jnan806 opened this issue Sep 26, 2022 · 0 comments

Comments

@jnan806
Copy link

jnan806 commented Sep 26, 2022

此 ISSUE 是对 #3 的进一步细化.

关于如何统一管理和保证proto和stub-code,在各个项目中保持一致,本人做了几种实现,(其中包含社区同学提议的工具)。由于还在探索,并未提交PR到社区,后面阐述的实现均会附带仓库地址。

实现方式

实现一 : 利用 原生protoc

github 仓库: jnan806/opensergo-proto 的 protoc-stub 分支 附带 README.md

  1. proto 项目中编写 proto 文件保管在项目中
  2. 通过脚本生成 stub-code
  3. 通过 CI 将 stub-code 发布到远程仓库

实现二 : 利用 buf.build 的代码生成功能以及 BSR( buf.build 提供的 proto远程仓库)

  1. proto 项目负责编写 proto ,并将 proto 文件发布托管到 BSR
    github 仓库: jnan806/opensergo-proto 的 buf.build-push 分支 附带 README.md
  2. 由独立的 项目负责拉取 BSR 中的 proto,通过 buf.build 生成 stub-code
    github 仓库: jnan806/opensergo-grpc-stub 的 initial-version 分支 附带 README.md
  3. 通过 CI 将 stub-code 发布到远程仓库

实现三 : 利用 buf.build 的代码生成功能

github 仓库: jnan806/opensergo-proto 的 buf.build-stub 分支 附带 README.md

  1. proto 项目中编写 proto 文件保管在项目中
  2. 利用 buf.build 管理第三方 proto 的依赖,通过 buf.build 生成 stub-code
  3. 通过 CI 将 stub-code 发布到远程仓库

示例Demo

上述实现方式,均得到相同的结果,因此仅列出以下一种demo示例

项目生成stub code主要用于OpenSergo SDK基于gRpc协议的依赖, 以及 opensergo-control-plane

总结

经过探索与实践,我得出如下结论:
推荐采用实现一 ,同时实现三 可保留到 feature 分支作为后续提升优化的方向

理由:
1、实现一是传统的 stub-code 的生成方式,基本上了解 gRpc 就能够快速掌握
2、实现三虽然技术新颖,功能强大,但就目前而言,在其官方提供的 中央仓库 BSR(Buf Schema Registry) 中,托管着的 proto 资源并不多,此时引入 buf.build 的话,只能利用其生成代码的功能,遇到在 BSR 中没有的 proto 资源,我们仍然需要 copy 到自己的项目里,这样一来就跟实现一区别不大,而且还需要花费时间去了解 bufbuild。

因此,暂时推荐采用实现一,等托管在BSR的 proto 资源 丰富起来后,并且OpenSergo 项目中依赖大量第三方 proto 资源时,可以切换到实现三。而且由于我们采用的是 SDK 引入 stub-code 模式,不论是实现一或是实现三,生成的 stub-code 还是一样的,对 SDK 来说只需要升级一下 stub-code 的版本号即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant