构建 grpc protobuf 花费的时间太长

building grpc protobuf take too long

我正在使用以下 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++ 或预装所有语言?

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

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

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