forked from namely/docker-protoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
214 lines (166 loc) · 7.43 KB
/
Dockerfile
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
ARG debian=buster
ARG go_version
ARG grpc_version
ARG grpc_gateway_version
ARG grpc_java_version
ARG uber_prototool_version
ARG scala_pb_version
ARG node_version
ARG node_grpc_tools_node_protoc_ts_version
ARG node_grpc_tools_version
ARG node_protoc_gen_grpc_web_version
ARG go_envoyproxy_pgv_version
ARG go_mwitkow_gpv_version
FROM golang:$go_version-$debian AS build
# TIL docker arg variables need to be redefined in each build stage
ARG grpc_version
ARG grpc_gateway_version
ARG grpc_java_version
ARG grpc_web_version
ARG scala_pb_version
ARG go_envoyproxy_pgv_version
ARG go_mwitkow_gpv_version
RUN set -ex && 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 \
clang
WORKDIR /tmp
RUN git clone --depth 1 --shallow-submodules -b v$grpc_version.x --recursive https://github.com/grpc/grpc && \
git clone --depth 1 --shallow-submodules -b v$grpc_java_version.x --recursive https://github.com/grpc/grpc-java.git && \
git clone --depth 1 --shallow-submodules -b v$grpc_version.x --recursive https://github.com/grpc/grpc-go.git && \
git clone --depth 1 https://github.com/googleapis/googleapis && \
git clone --depth 1 https://github.com/googleapis/api-common-protos
ARG bazel=/tmp/grpc/tools/bazel
WORKDIR /tmp/grpc
RUN $bazel build //external:protocol_compiler && \
$bazel build //src/compiler:all && \
$bazel build //test/cpp/util:grpc_cli
WORKDIR /tmp/grpc-java
RUN $bazel build //compiler:grpc_java_plugin
WORKDIR /tmp
# Install protoc required by envoyproxy/protoc-gen-validate package
RUN cp -a /tmp/grpc/bazel-bin/external/com_google_protobuf/. /usr/local/bin/
# Copy well known proto files required by envoyproxy/protoc-gen-validate package
RUN mkdir -p /usr/local/include/google/protobuf && \
cp -a /tmp/grpc/bazel-grpc/external/com_google_protobuf/src/google/protobuf/. /usr/local/include/google/protobuf/
WORKDIR /tmp
RUN curl -sSL https://github.com/uber/prototool/releases/download/v${uber_prototool_version}/prototool-$(uname -s)-$(uname -m) \
-o /usr/local/bin/prototool && \
chmod +x /usr/local/bin/prototool
# Workaround for the transition to protoc-gen-go-grpc
# https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code
RUN ( cd ./grpc-go/cmd/protoc-gen-go-grpc && go install . )
# Go get go-related bins
WORKDIR /tmp
RUN set -e && \
GO111MODULE=on go get google.golang.org/grpc@v$grpc_version
# install protoc-gen-grpc-gateway and protoc-gen-openapiv2
RUN set -e && \
GO111MODULE=on go get -u github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v${grpc_gateway_version} && \
cd /go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v${grpc_gateway_version}/protoc-gen-grpc-gateway && \
go install .
RUN set -e && \
GO111MODULE=on go get -u github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@v${grpc_gateway_version} && \
cd /go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v${grpc_gateway_version}/protoc-gen-openapiv2 && \
go install .
RUN go get -u github.com/gogo/protobuf/protoc-gen-gogo
RUN go get -u github.com/gogo/protobuf/protoc-gen-gogofast
RUN go get -u github.com/ckaznocha/protoc-gen-lint
RUN set -e && \
GO111MODULE=on go get github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
RUN go get -u github.com/micro/micro/v3/cmd/protoc-gen-micro
RUN GO111MODULE=on go get -d github.com/envoyproxy/protoc-gen-validate@v${go_envoyproxy_pgv_version}
RUN make -C /go/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v${go_envoyproxy_pgv_version}/ build
# Add Ruby Sorbet types support (rbi)
RUN go get -u github.com/coinbase/protoc-gen-rbi
RUN go get github.com/gomatic/renderizer/v2/cmd/renderizer
# Origin protoc-gen-go should be installed last, for not been overwritten by any other binaries(see #210)
RUN go get -u github.com/golang/protobuf/protoc-gen-go
# Need to get these too:
RUN go get -u github.com/mwitkow/go-proto-validators/@v${go_mwitkow_gpv_version}
RUN go get -u github.com/mwitkow/go-proto-validators/protoc-gen-govalidators@v${go_mwitkow_gpv_version}
# Add scala support
RUN curl -LO https://github.com/scalapb/ScalaPB/releases/download/v${scala_pb_version}/protoc-gen-scala-${scala_pb_version}-linux-x86_64.zip \
&& unzip protoc-gen-scala-${scala_pb_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_version}/protoc-gen-grpc-web-${grpc_web_version}-linux-x86_64 \
-o /tmp/grpc_web_plugin && \
chmod +x /tmp/grpc_web_plugin
FROM debian:$debian-slim AS protoc-all
ARG grpc_version
ARG grpc_gateway_version
ARG node_version
ARG node_grpc_tools_node_protoc_ts_version
ARG node_grpc_tools_version
ARG node_protoc_gen_grpc_web_version
ARG go_envoyproxy_pgv_version
ARG go_mwitkow_gpv_version
RUN mkdir -p /usr/share/man/man1
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
bash \
curl \
software-properties-common \
ca-certificates \
zlib1g \
libssl1.1 \
openjdk-11-jre \
dos2unix \
gawk
# Install latest Node version
RUN curl -fsSL https://deb.nodesource.com/setup_${node_version}.x | bash -
RUN apt-get install -y nodejs npm
# Add TypeScript support
RUN npm config set unsafe-perm true
RUN npm i -g grpc_tools_node_protoc_ts@$node_grpc_tools_node_protoc_ts_version grpc-tools@$node_grpc_tools_version protoc-gen-grpc-web@$node_protoc_gen_grpc_web_version
COPY --from=build /tmp/googleapis/google/ /opt/include/google
COPY --from=build /tmp/api-common-protos/google/ /opt/include/google
# Copy well known proto files
COPY --from=build /tmp/grpc/bazel-grpc/external/com_google_protobuf/src/google/protobuf/ /opt/include/google/protobuf/
# Copy protoc
COPY --from=build /tmp/grpc/bazel-bin/external/com_google_protobuf/ /usr/local/bin/
# Copy protoc default plugins
COPY --from=build /tmp/grpc/bazel-bin/src/compiler/ /usr/local/bin/
# Copy protoc java plugin
COPY --from=build /tmp/grpc-java/bazel-bin/compiler/ /usr/local/bin/
# Copy grpc_cli
COPY --from=build /tmp/grpc/bazel-bin/test/cpp/util/ /usr/local/bin/
COPY --from=build /usr/local/bin/prototool /usr/local/bin/prototool
COPY --from=build /go/bin/* /usr/local/bin/
COPY --from=build /tmp/grpc_web_plugin /usr/local/bin/grpc_web_plugin
COPY --from=build /tmp/protoc-gen-scala /usr/local/bin/
COPY --from=build /go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v${grpc_gateway_version}/protoc-gen-openapiv2/options /opt/include/protoc-gen-openapiv2/options/
COPY --from=build /go/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v${go_envoyproxy_pgv_version}/ /opt/include/
COPY --from=build /go/pkg/mod/github.com/mwitkow/go-proto-validators@v${go_mwitkow_gpv_version}/ /opt/include/github.com/mwitkow/go-proto-validators/
ADD all/entrypoint.sh /usr/local/bin
RUN chmod +x /usr/local/bin/entrypoint.sh
WORKDIR /defs
ENTRYPOINT [ "entrypoint.sh" ]
# protoc
FROM protoc-all AS protoc
ENTRYPOINT [ "protoc", "-I/opt/include" ]
# prototool
FROM protoc-all AS prototool
ENTRYPOINT [ "prototool" ]
# grpc-cli
FROM protoc-all as grpc-cli
ADD ./cli/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
WORKDIR /run
ENTRYPOINT [ "/entrypoint.sh" ]
# gen-grpc-gateway
FROM protoc-all AS gen-grpc-gateway
COPY gwy/templates /templates
COPY gwy/generate_gateway.sh /usr/local/bin
RUN chmod +x /usr/local/bin/generate_gateway.sh
WORKDIR /defs
ENTRYPOINT [ "generate_gateway.sh" ]