diff --git a/build/docker/Dockerfile b/build/docker/Dockerfile index c00950a10f7fced92b50e35546ecea92bb2cbc61..9d6de7d2d829d5c7db5d58a5c530115222e1c62e 100644 --- a/build/docker/Dockerfile +++ b/build/docker/Dockerfile @@ -19,6 +19,10 @@ FROM ubuntu:16.04 +# prepare the directory for pulsar related files +RUN mkdir /pulsar +ADD protobuf.patch /pulsar + RUN apt-get update RUN apt-get install -y maven tig g++ cmake libssl-dev libcurl4-openssl-dev \ liblog4cxx-dev libprotobuf-dev libboost-all-dev libgtest-dev \ @@ -51,3 +55,12 @@ RUN wget https://github.com/pseudomuto/protoc-gen-doc/releases/download/v1.0.0-a tar xvfz protoc-gen-doc-1.0.0-alpha.linux-amd64.go1.8.1.tar.gz && \ cp protoc-gen-doc-1.0.0-alpha.linux-amd64.go1.8.1/protoc-gen-doc /usr/local/bin && \ rm protoc-gen-doc-1.0.0-alpha.linux-amd64.go1.8.1.tar.gz + +# Build the patched protoc +RUN git clone https://github.com/google/protobuf.git /pulsar/protobuf && \ + cd /pulsar/protobuf && \ + git checkout v2.4.1 && \ + patch -p1 < /pulsar/protobuf.patch && \ + autoreconf --install && \ + ./configure && \ + make diff --git a/protobuf/protobuf.patch b/build/docker/protobuf.patch similarity index 100% rename from protobuf/protobuf.patch rename to build/docker/protobuf.patch diff --git a/protobuf/README.md b/protobuf/README.md index fbeb477455c6598f60e404d133657f12ad058df3..dd698ef6d604fe94a160f068ae3d7de860ab05bf 100644 --- a/protobuf/README.md +++ b/protobuf/README.md @@ -11,15 +11,9 @@ The pre-generated Java code is at `pulsar-common/src/main/java/org/apache/pulsar We are currently using a modified version of the Google Protocol Buffer code generator, to generate code that can serialize/deserialize messages with no memory allocations (caching already instantiated objects) and also to be able to directly use Netty pooled ByteBuf with direct memory. -To re-generate the `PulsarApi.java` code you need to apply a patch to the protobuf generator. Patch is found in `protobuf.patch`. +To re-generate the `PulsarApi.java` code you need to apply a patch to the protobuf generator. Patch is found in `build/docker/protobuf.patch`. -### For C++ Client: - -The pre-generated C++ code is at `pulsar-client-cpp/lib/PulsarApi.pb.cc` and `pulsar-client-cpp/lib/PulsarApi.pb.h`. - -You don't need to manually generate C++ code. The C++ code is automatically generated by `cmake`. - -### Commands for creating the pre-generated Java code +#### Commands for creating the pre-generated Java code ```shell export PULSAR_HOME= @@ -31,7 +25,7 @@ cd ${HOME}/protobuf git checkout v2.4.1 ### Apply patch -patch -p1 < ${PULSAR_HOME}/protobuf/protobuf.patch +patch -p1 < ${PULSAR_HOME}/build/docker/protobuf.patch ### Compile protobuf autoreconf --install @@ -43,3 +37,16 @@ cd ${PULSAR_HOME}/pulsar-common/ export PROTOC=${HOME}/protobuf/src/protoc ./generate_protobuf.sh ``` + +Or you can use the pre-built protoc included in `pulsar-build` docker image to generate java protobuf files. + +``` +cd ${PULSAR_HOME}/pulsar-common/ +./generate_protobuf_docker.sh +``` + +### For C++ Client: + +The pre-generated C++ code is at `pulsar-client-cpp/lib/PulsarApi.pb.cc` and `pulsar-client-cpp/lib/PulsarApi.pb.h`. + +You don't need to manually generate C++ code. The C++ code is automatically generated by `cmake`. diff --git a/pulsar-common/generate_protobuf_docker.sh b/pulsar-common/generate_protobuf_docker.sh new file mode 100755 index 0000000000000000000000000000000000000000..c568c9a07dcfe9bf6e30cb33b19613ba543697ed --- /dev/null +++ b/pulsar-common/generate_protobuf_docker.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Fail script in case of errors +set -e + +ROOT_DIR=$(git rev-parse --show-toplevel) +COMMON_DIR=$ROOT_DIR/pulsar-common +cd $COMMON_DIR + +BUILD_IMAGE_NAME="${BUILD_IMAGE_NAME:-apachepulsar/pulsar-build}" +BUILD_IMAGE_VERSION="${BUILD_IMAGE_VERSION:-ubuntu-16.04}" + +IMAGE="$BUILD_IMAGE_NAME:$BUILD_IMAGE_VERSION" + +echo $IMAGE + +docker run -i \ + -v ${COMMON_DIR}:${COMMON_DIR} $IMAGE \ + bash -c "cd ${COMMON_DIR}; /pulsar/protobuf/src/protoc --java_out=src/main/java src/main/proto/PulsarApi.proto"