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

Improve C# support, set GRPC_CSHARP_VERSION=1.28.1 #15

Merged
merged 4 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 48 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,72 @@ ARG ALPINE_VERSION=3.10
ARG GO_VERSION=1.13.4
ARG GRPC_GATEWAY_VERSION=1.12.2
ARG GRPC_JAVA_VERSION=1.26.0
ARG GRPC_CSHARP_VERSION=1.28.1
ARG GRPC_VERSION=1.26.0
ARG PROTOC_GEN_GO_VERSION=1.3.2
ARG PROTOC_GEN_GOGO_VERSION=ba06b47c162d49f2af050fb4c75bcbc86a159d5c
ARG PROTOC_GEN_LINT_VERSION=0.2.1
ARG UPX_VERSION=3.96


FROM alpine:${ALPINE_VERSION} as protoc_builder
RUN apk add --no-cache build-base curl automake autoconf libtool git zlib-dev

RUN mkdir -p /out
FROM alpine:${ALPINE_VERSION} as protoc_base
RUN apk add --no-cache build-base curl cmake autoconf libtool git zlib-dev linux-headers && \
mkdir -p /out


FROM protoc_base as protoc_builder
ARG GRPC_VERSION
RUN git clone --recursive --depth=1 -b v${GRPC_VERSION} https://github.com/grpc/grpc.git /grpc && \
RUN apk add --no-cache automake && \
git clone --recursive --depth=1 -b v${GRPC_VERSION} https://github.com/grpc/grpc.git /grpc && \
ln -s /grpc/third_party/protobuf /protobuf && \
cd /protobuf && \
./autogen.sh && \
./configure --prefix=/usr --enable-static=no && \
make && \
make check && \
make install && \
make install DESTDIR=/out && \
make -j4 && \
make -j4 check && \
make -j4 install && \
make -j4 install DESTDIR=/out && \
cd /grpc && \
make install-plugins prefix=/out/usr
make -j4 install-plugins prefix=/out/usr

ARG GRPC_JAVA_VERSION
RUN mkdir -p /grpc-java && \
curl -sSL https://api.github.com/repos/grpc/grpc-java/tarball/v${GRPC_JAVA_VERSION} | tar xz --strip 1 -C /grpc-java && \
cd /grpc-java && \
g++ \
-I. -I/protobuf/src \
-I/out/usr/include \
compiler/src/java_plugin/cpp/*.cpp \
-L/protobuf/src/.libs \
-L/out/usr/lib \
-L/out/usr/lib64 \
-lprotoc -lprotobuf -lpthread --std=c++0x -s \
-o protoc-gen-grpc-java && \
install -Ds protoc-gen-grpc-java /out/usr/bin/protoc-gen-grpc-java
install -Ds protoc-gen-grpc-java /out/usr/bin/protoc-gen-grpc-java && \
rm -Rf /grpc-java && \
rm -Rf /grpc


FROM protoc_base AS protoc_cs_builder
ARG GRPC_CSHARP_VERSION
RUN git clone --recursive --depth=1 -b v${GRPC_CSHARP_VERSION} https://github.com/grpc/grpc.git /grpc && \
ln -s /grpc/third_party/protobuf /protobuf && \
mkdir -p /grpc/cmake/build && \
cd /grpc/cmake/build && \
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_BUILD_TESTS=OFF \
-gRPC_BUILD_GRPC_CPP_PLUGIN=OFF \
-gRPC_BUILD_GRPC_NODE_PLUGIN=OFF \
-gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \
-gRPC_BUILD_GRPC_PHP_PLUGIN=OFF \
-gRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \
-gRPC_BUILD_GRPC_RUBY_PLUGIN=OFF \
-DgRPC_INSTALL=ON \
-DCMAKE_INSTALL_PREFIX=/out/usr \
../.. && \
make -j4 install && \
rm -Rf /grpc


FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} as go_builder
RUN apk add --no-cache build-base curl git
Expand Down Expand Up @@ -84,21 +113,27 @@ RUN mkdir -p ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \
install -D $(find ./third_party/googleapis/google/rpc -name '*.proto') -t /out/usr/include/google/rpc



FROM alpine:${ALPINE_VERSION} as packer
RUN apk add --no-cache curl

ARG UPX_VERSION
RUN mkdir -p /upx && curl -sSL https://github.com/upx/upx/releases/download/v${UPX_VERSION}/upx-${UPX_VERSION}-amd64_linux.tar.xz | tar xJ --strip 1 -C /upx && \
install -D /upx/upx /usr/local/bin/upx

# Use all output including headers and protoc from protoc_builder
COPY --from=protoc_builder /out/ /out/
# Use protoc and plugin from protoc_cs_builder
COPY --from=protoc_cs_builder /out/usr/bin/protoc-* /out/usr/bin/protoc-csharp
COPY --from=protoc_cs_builder /out/usr/bin/grpc_csharp_plugin /out/usr/bin/grpc_csharp_plugin
# Integrate all output from go_builder
COPY --from=go_builder /out/ /out/

RUN upx --lzma \
/out/usr/bin/grpc_* \
/out/usr/bin/protoc-gen-*
RUN find /out -name "*.a" -delete -or -name "*.la" -delete


FROM alpine:${ALPINE_VERSION}
LABEL maintainer="The Jaeger Authors"
COPY --from=packer /out/ /
Expand Down
22 changes: 16 additions & 6 deletions protoc-wrapper
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
c_out=""
csharp_out=""
includes=()
outs=()
args=()
Expand All @@ -10,6 +11,14 @@ for arg in $@; do
c_out=${arg}
shift
;;
--csharp_out=*)
csharp_out=${arg}
shift
;;
--grpc-csharp_out=*)
csharp_out=${arg}
shift
;;
--*_out=*)
outs+=(${arg})
shift
Expand All @@ -31,13 +40,14 @@ fi

protoc_cmd="protoc ${includes[@]} ${outs[@]} ${args[@]}"
protoc_c_cmd="protoc-c ${includes[@]} ${c_out} ${args[@]}"
protoc_csharp_cmd="protoc-csharp ${includes[@]} ${csharp_out} ${args[@]}"

if [ ${c_out} ]; then
if [ ${#outs[@]} -eq 0 ]; then
# only --c_out specified, no need to call `protoc`
exec ${protoc_c_cmd}
fi
${protoc_c_cmd} || exit 1
exec ${protoc_cmd}
fi
exec ${protoc_cmd}
if [ ${csharp_out} ]; then
${protoc_csharp_cmd} || exit 1
fi
if [ ${#outs[@]} -gt 0 ]; then
exec ${protoc_cmd}
fi