Skip to content

Commit f3ec5f5

Browse files
committed
Use Bazel for protoc_plugin Docker build
1 parent d0ecc76 commit f3ec5f5

File tree

1 file changed

+11
-47
lines changed

1 file changed

+11
-47
lines changed

net/grpc/gateway/docker/protoc_plugin/Dockerfile

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,20 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# TODO: Migrate to be using bazel build.
1615
FROM grpcweb/prereqs
1716

18-
ARG MAKEFLAGS=-j8
19-
ARG PROTOBUF_VERSION=v27.1
17+
# Build the protoc-gen-grpc-web plugin with Bazel and install it.
18+
# The base image already provides Bazel, protoc, and third_party deps.
2019

21-
# Install required build tools and libraries
22-
RUN apt-get update && apt-get install -y \
23-
cmake ninja-build \
24-
pkg-config zlib1g-dev \
25-
libtool autoconf automake \
26-
curl unzip git build-essential && \
27-
rm -rf /var/lib/apt/lists/*
28-
29-
# Set working directory for build context
3020
WORKDIR /github/grpc-web
3121

32-
# Copy full grpc-web source including third_party
33-
COPY . /github/grpc-web
34-
35-
# Add this to ensure abseil-cpp is available
36-
RUN git clone --depth 1 https://github.com/abseil/abseil-cpp.git third_party/abseil-cpp
37-
38-
# Clean existing Abseil install (if rebuilding)
39-
RUN rm -rf /usr/local/include/absl /usr/local/lib/libabsl*
40-
41-
# Build Abseil
42-
WORKDIR /github/grpc-web/third_party/abseil-cpp
43-
RUN cmake -S . -B cmake/build \
44-
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
45-
-DCMAKE_CXX_STANDARD=17 \
46-
-DCMAKE_BUILD_TYPE=Release && \
47-
cmake --build cmake/build --target install
48-
49-
# Clone full Protobuf source manually (not shallow)
50-
WORKDIR /github/grpc-web/third_party
51-
RUN rm -rf protobuf && \
52-
git clone https://github.com/protocolbuffers/protobuf.git && \
53-
cd protobuf && \
54-
git checkout ${PROTOBUF_VERSION} && \
55-
git submodule update --init --recursive
56-
57-
# Build and install Protobuf using CMake
58-
WORKDIR /github/grpc-web/third_party/protobuf
59-
RUN cmake -S . -B build \
60-
-DCMAKE_BUILD_TYPE=Release \
61-
-Dprotobuf_BUILD_TESTS=OFF \
62-
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
63-
-DCMAKE_CXX_STANDARD=17 && \
64-
cmake --build build --target install
22+
# Copy only files needed to build the plugin for better caching.
23+
COPY ./MODULE.bazel ./MODULE.bazel
24+
COPY ./MODULE.bazel.lock ./MODULE.bazel.lock
25+
COPY ./.bazelrc ./.bazelrc
26+
COPY ./javascript/net/grpc/web/generator javascript/net/grpc/web/generator
6527

66-
# Optional: Debug CMake errors (if build fails)
67-
# RUN cat build/CMakeFiles/CMakeError.log || true
28+
# Build and install the plugin binary.
29+
RUN bazel build javascript/net/grpc/web/generator:protoc-gen-grpc-web && \
30+
cp $(bazel info bazel-genfiles)/javascript/net/grpc/web/generator/protoc-gen-grpc-web \
31+
/usr/local/bin/protoc-gen-grpc-web

0 commit comments

Comments
 (0)