-
Notifications
You must be signed in to change notification settings - Fork 35
/
Dockerfile
153 lines (135 loc) · 6.77 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
ARG ALPINE_VERSION=3.13
ARG GO_VERSION=1.17.3
ARG GRPC_GATEWAY_VERSION=1.16.0
ARG GRPC_JAVA_VERSION=1.35.0
ARG GRPC_CSHARP_VERSION=1.35.0
ARG GRPC_VERSION=1.35.0
ARG PROTOC_GEN_GO_VERSION=1.31.0
# v1.3.2, using the version directly does not work: "tar: invalid magic"
ARG PROTOC_GEN_GOGO_VERSION=b03c65ea87cdc3521ede29f62fe3ce239267c1bc
ARG PROTOC_GEN_LINT_VERSION=0.2.1
ARG UPX_VERSION=3.96
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 apk add --no-cache automake ninja && \
git clone --recursive --depth=1 -b v${GRPC_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 \
-GNinja \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCMAKE_BUILD_TYPE=Release \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
../.. && \
cmake --build . --target plugins && \
cmake --build . --target install && \
DESTDIR=/out cmake --build . --target install
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/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 && \
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
ENV GOBIN=/out/usr/bin
ARG PROTOC_GEN_GO_VERSION
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v${PROTOC_GEN_GO_VERSION}
ARG PROTOC_GEN_GOGO_VERSION
RUN mkdir -p ${GOPATH}/src/github.com/gogo/protobuf && \
curl -sSL https://api.github.com/repos/gogo/protobuf/tarball/${PROTOC_GEN_GOGO_VERSION} | tar xz --strip 1 -C ${GOPATH}/src/github.com/gogo/protobuf &&\
cd ${GOPATH}/src/github.com/gogo/protobuf && \
go build -ldflags '-w -s' -o /gogo-protobuf-out/protoc-gen-gogo ./protoc-gen-gogo && \
install -Ds /gogo-protobuf-out/protoc-gen-gogo /out/usr/bin/protoc-gen-gogo && \
mkdir -p /out/usr/include/github.com/gogo/protobuf/protobuf/google/protobuf && \
install -D $(find ./protobuf/google/protobuf -name '*.proto') -t /out/usr/include/github.com/gogo/protobuf/protobuf/google/protobuf && \
install -D ./gogoproto/gogo.proto /out/usr/include/github.com/gogo/protobuf/gogoproto/gogo.proto
# This package is not built for arm64 architecture, and we don't really use it.
# ARG PROTOC_GEN_LINT_VERSION
# RUN cd / && \
# curl -sSLO https://github.com/ckaznocha/protoc-gen-lint/releases/download/v${PROTOC_GEN_LINT_VERSION}/protoc-gen-lint_linux_${TARGETARCH}.zip && \
# mkdir -p /protoc-gen-lint-out && \
# cd /protoc-gen-lint-out && \
# unzip -q /protoc-gen-lint_linux_${TARGETARCH}.zip && \
# install -Ds /protoc-gen-lint-out/protoc-gen-lint /out/usr/bin/protoc-gen-lint
ARG GRPC_GATEWAY_VERSION
RUN mkdir -p ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \
curl -sSL https://api.github.com/repos/grpc-ecosystem/grpc-gateway/tarball/v${GRPC_GATEWAY_VERSION} | tar xz --strip 1 -C ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \
cd ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \
go build -ldflags '-w -s' -o /grpc-gateway-out/protoc-gen-grpc-gateway ./protoc-gen-grpc-gateway && \
go build -ldflags '-w -s' -o /grpc-gateway-out/protoc-gen-swagger ./protoc-gen-swagger && \
install -Ds /grpc-gateway-out/protoc-gen-grpc-gateway /out/usr/bin/protoc-gen-grpc-gateway && \
install -Ds /grpc-gateway-out/protoc-gen-swagger /out/usr/bin/protoc-gen-swagger && \
mkdir -p /out/usr/include/protoc-gen-swagger/options && \
install -D $(find ./protoc-gen-swagger/options -name '*.proto') -t /out/usr/include/protoc-gen-swagger/options && \
mkdir -p /out/usr/include/google/api && \
install -D $(find ./third_party/googleapis/google/api -name '*.proto') -t /out/usr/include/google/api && \
mkdir -p /out/usr/include/google/rpc && \
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 $(find /out/usr/bin/ \
-type f -name 'grpc_*' \
-not -name 'grpc_node_plugin' \
-not -name 'grpc_php_plugin' \
-not -name 'grpc_ruby_plugin' \
-not -name 'grpc_python_plugin' \
-or -name '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/ /
RUN apk add --no-cache bash libstdc++ && \
ln -s /usr/bin/grpc_cpp_plugin /usr/bin/protoc-gen-grpc-cpp && \
ln -s /usr/bin/grpc_csharp_plugin /usr/bin/protoc-gen-grpc-csharp && \
ln -s /usr/bin/grpc_node_plugin /usr/bin/protoc-gen-grpc-js && \
ln -s /usr/bin/grpc_python_plugin /usr/bin/protoc-gen-grpc-python
COPY protoc-wrapper /usr/bin/protoc-wrapper
ENV LD_LIBRARY_PATH='/usr/lib:/usr/lib64:/usr/lib/local'
ENTRYPOINT ["protoc-wrapper", "-I/usr/include"]