-
Notifications
You must be signed in to change notification settings - Fork 0
/
GrpcKitToolsDockerfile
182 lines (141 loc) · 5.21 KB
/
GrpcKitToolsDockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
ARG debian=bullseye
ARG go=1.20.4
ARG libprotoc_version
ARG grpc
ARG grpc_java
ARG buf_version
ARG grpc_web
ARG scalapb_version
# Pure go binaries
FROM golang:$go-$debian AS build-go
ARG libprotoc_version
ARG grpc
# Pin protoc version
RUN apt-get clean && apt-get update && apt-get install -y -qq unzip wget && \
cd /tmp/ && wget https://github.com/protocolbuffers/protobuf/releases/download/v${libprotoc_version}/protoc-${libprotoc_version}-linux-x86_64.zip && \
unzip /tmp/protoc-${libprotoc_version}-linux-x86_64.zip && \
mv /tmp/bin/protoc /usr/local/bin/protoc && \
chmod +x /usr/local/bin/protoc
# Go get go-related bins
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# Gogo and Gogo Fast
RUN go install github.com/gogo/protobuf/protoc-gen-gogo@latest && \
go install github.com/gogo/protobuf/protoc-gen-gogofast@latest && \
go install github.com/gogo/protobuf/protoc-gen-gogoslick@latest
# Lint
RUN go install github.com/ckaznocha/protoc-gen-lint@latest
# Validations
RUN go install github.com/envoyproxy/protoc-gen-validate@latest
# Docs
RUN go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest
# Install google openapi
# https://github.com/google/gnostic/tree/master/cmd/protoc-gen-openapi
RUN go install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
# Figure out if this is a naming collision
# RUN go get -u github.com/micro/protobuf/protoc-gen-go
# Omniproto
RUN go install github.com/grpckit/omniproto@latest
RUN go install github.com/GoogleCloudPlatform/protoc-gen-bq-schema@latest
# Add Ruby Sorbet types support (rbi)
RUN go install github.com/coinbase/protoc-gen-rbi@latest
FROM build-go AS build
ARG grpc
ARG grpc_java
ARG buf_version
ARG grpc_web
ARG scalapb_version
# TIL docker arg variables need to be redefined in each build stage
ARG grpc
ARG grpc_java
ARG grpc_web
ARG buf_version
ARG scalapb_version
# Parallel cmake
ENV CMAKE_BUILD_PARALLEL_LEVEL=8
# update path for go get dependencies
ENV PATH "$PATH:/opt/bin"
RUN set -ex && apt-get clean && apt-get update && apt-get install -y --no-install-recommends \
build-essential \
pkg-config \
cmake \
curl \
git \
openjdk-11-jre \
unzip \
libtool \
autoconf \
zlib1g-dev \
libssl-dev \
make
WORKDIR /tmp
RUN git clone https://github.com/grpc/grpc.git && cd grpc && git checkout v$grpc && git submodule update --init
RUN mkdir -p /tmp/grpc/cmake/build
WORKDIR /tmp/grpc/cmake/build
RUN cmake ../.. \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DgRPC_ZLIB_PROVIDER=package \
-DgRPC_SSL_PROVIDER=package \
-DCMAKE_INSTALL_PREFIX=/opt && \
make -j ${CMAKE_BUILD_PARALLEL_LEVEL} && \
make install
WORKDIR /tmp
RUN git clone https://github.com/grpc/grpc-java.git && cd grpc-java && git checkout v$grpc_java
WORKDIR /tmp/grpc-java/compiler
RUN CXXFLAGS="-I/opt/include" LDFLAGS="-L/opt/lib" ../gradlew -PskipAndroid=true java_pluginExecutable
WORKDIR /tmp
# Install Buf
RUN BIN="/usr/local/bin" && \
BINARY_NAME="buf" && \
curl -sSL \
"https://github.com/bufbuild/buf/releases/download/v"$buf_version"/${BINARY_NAME}-$(uname -s)-$(uname -m)" \
-o "${BIN}/${BINARY_NAME}" && \
chmod +x "${BIN}/${BINARY_NAME}"
WORKDIR /tmp
# Add scala support
RUN curl -LO https://github.com/scalapb/ScalaPB/releases/download/v${scalapb_version}/protoc-gen-scala-${scalapb_version}-linux-x86_64.zip \
&& unzip protoc-gen-scala-${scalapb_version}-linux-x86_64.zip \
&& chmod +x /tmp/protoc-gen-scala
# Add grpc-web support
RUN curl -sSL https://github.com/grpc/grpc-web/releases/download/${grpc_web}/protoc-gen-grpc-web-${grpc_web}-linux-x86_64 \
-o /tmp/grpc_web_plugin && \
chmod +x /tmp/grpc_web_plugin
FROM debian:$debian-slim AS grpckit
RUN mkdir -p /usr/share/man/man1
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
bash \
ca-certificates \
nodejs \
npm \
zlib1g \
libssl1.1 \
openjdk-11-jre
WORKDIR /workspace
# Add TypeScript support
RUN npm config set unsafe-perm true
RUN npm i -g [email protected]
RUN npm i -g [email protected]
COPY --from=build /opt/bin/ /usr/local/bin/
COPY --from=build /opt/include/ /usr/local/include/
COPY --from=build /opt/lib/ /usr/local/lib/
COPY --from=build /opt/share/ /usr/local/share/
COPY --from=build /tmp/grpc-java/compiler/build/exe/java_plugin/protoc-gen-grpc-java /usr/local/bin/
COPY --from=build /go/bin/ /usr/local/bin/
COPY --from=build /tmp/grpc_web_plugin /usr/local/bin/protoc-gen-grpc-web
COPY --from=build /usr/local/bin/buf /usr/local/bin/buf
COPY --from=build /tmp/protoc-gen-scala /usr/local/bin/
# NB(MLH) We shouldn't need to copy these to include, as protofiles should be sourced elsewhere
# COPY --from=build /go/src/github.com/envoyproxy/protoc-gen-validate/ /opt/include/github.com/envoyproxy/protoc-gen-validate/
# COPY --from=build /go/src/github.com/mwitkow/go-proto-validators/ /opt/include/github.com/mwitkow/go-proto-validators/
# protoc
FROM grpckit AS protoc
ENTRYPOINT [ "protoc" ]
# buf
FROM grpckit AS buf
ENTRYPOINT [ "buf" ]
# omnikit
FROM grpckit AS omniproto
ENTRYPOINT [ "omniproto" ]
FROM grpckit