构建 grpc protobuf 耗时太长

Posted

技术标签:

【中文标题】构建 grpc protobuf 耗时太长【英文标题】:building grpc protobuf take too long 【发布时间】:2020-09-11 11:01:57 【问题描述】:

我正在使用以下 Dockerfile 在构建映像上安装 grpc,构建 cpp 微服务并将其放入运行时容器中。

https://github.com/npclaudiu/grpc-cpp-docker/blob/master/Dockerfile

但是构建 grpc/protobuf 的部分需要 2 小时以上,而且是针对一项服务。

RUN echo "-- installing protobuf" && \
    cd /var/local/git/grpc/third_party/protobuf && \
    ./autogen.sh && ./configure --enable-shared && \
    make -j$(nproc) && make -j$(nproc) check && make install && ldconfig

我看到所有语言实现都是编译的,而我只需要 C++。

有什么方法可以加快这个过程吗?是否有 debian 或者最好是 alpine linux 映像,其中包含 grpc 和 C++ 或所有语言预装的协议缓冲区?

【问题讨论】:

嗨@Serve Laurijsseen,我看到github.com/npclaudiu/grpc-cpp-docker/blob/master/Dockerfile 是基于hub.docker.com/r/grpc/cxx/dockerfile。为什么不使用grpc/ccx 【参考方案1】:

您可以创建中间图像。在这些行之后将您的 Dockefile 分成两部分:

RUN echo "-- installing grpc" && \
cd /var/local/git/grpc && \
make -j$(nproc) && make install && make clean && ldconfig

一劳永逸地构建第一个(您只需等待 2 小时一次),在本地标记映像并将此映像用作第二个 Dockerfile 的基础映像。

【讨论】:

以上是关于构建 grpc protobuf 耗时太长的主要内容,如果未能解决你的问题,请参考以下文章

将WCF迁移到gRPC

grpc和protobuf结合的示例

CLion 在构建后强制文件刷新,耗时太长

在 android studio 中,Gradle 同步构建模型耗时太长

create-react-app 构建过程耗时太长

每天进步一点点:go基于grpc构建微服务框架-服务注册与发现