forked from infobloxopen/atlas-gentool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
122 lines (104 loc) · 5.31 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
# The docker image to generate Golang code from Protol Buffer.
FROM golang:1.9.2-alpine as builder
LABEL intermediate=true
MAINTAINER DL NGP-App-Infra-API <[email protected]>
ARG PGG_VERSION=master
ARG AAT_VERSION=master
# Set up mandatory Go environmental variables.
ENV CGO_ENABLED=0
# Install zip tool to unpack the protoc compiler.
RUN apk update \
&& apk add --no-cache --purge unzip curl git build-base automake autoconf libtool ucl-dev zlib-dev
# The versions for the protocol buffers compiler and grpc.
ENV PROTOC_VERSION 3.5.1
ENV GRPC_VERSION=1.8.3
# Download and build of the protobuffer compiler and grpc
# This and compression behavior adapted from github.com/znly/docker-protobuf
RUN mkdir -p /protobuf && \
curl -L https://github.com/google/protobuf/archive/v${PROTOC_VERSION}.tar.gz | tar xvz --strip-components=1 -C /protobuf
RUN git clone --depth 1 --recursive -b v${GRPC_VERSION} https://github.com/grpc/grpc.git /grpc && \
rm -rf grpc/third_party/protobuf && \
ln -s /protobuf /grpc/third_party/protobuf
RUN cd /protobuf && \
autoreconf -f -i -Wall,no-obsolete && \
./configure --prefix=/usr --enable-static=no && \
make -j2 && make install
RUN cd /grpc && \
make -j2 plugins
RUN cd /protobuf && \
make install DESTDIR=/out
RUN cd /grpc && \
make install-plugins prefix=/out/usr
RUN find /out -name "*.a" -delete -or -name "*.la" -delete
# The version and the binaries checksum for the glide package manager.
ENV GLIDE_VERSION 0.12.3
ENV GLIDE_DOWNLOAD_URL https://github.com/Masterminds/glide/releases/download/v${GLIDE_VERSION}/glide-v${GLIDE_VERSION}-linux-amd64.tar.gz
ENV GLIDE_DOWNLOAD_SHA256 0e2be5e863464610ebc420443ccfab15cdfdf1c4ab63b5eb25d1216900a75109
# Download and install the glide package manager.
RUN curl -fsSL ${GLIDE_DOWNLOAD_URL} -o glide.tar.gz \
&& echo "${GLIDE_DOWNLOAD_SHA256} glide.tar.gz" | sha256sum -c - \
&& tar -xzf glide.tar.gz --strip-components=1 -C /usr/local/bin \
&& rm -rf glide.tar.gz
# Install as the protoc plugins as build-time dependecies.
COPY glide.yaml.tmpl .
# Compile binaries for the protocol buffer plugins. We need specific
# versions of these tools, this is why we at first step install glide,
# download required versions and then installing them.
RUN sed -e "s/@PGGVersion/$PGG_VERSION/" -e "s/@AATVersion/$AATVersion/" glide.yaml.tmpl > glide.yaml; \
glide up --skip-test \
&& cp -r vendor/* ${GOPATH}/src/ \
&& go install github.com/golang/protobuf/protoc-gen-go \
&& go install github.com/gogo/protobuf/protoc-gen-combo \
&& go install github.com/gogo/protobuf/protoc-gen-gofast \
&& go install github.com/gogo/protobuf/protoc-gen-gogo \
&& go install github.com/gogo/protobuf/protoc-gen-gogofast \
&& go install github.com/gogo/protobuf/protoc-gen-gogofaster \
&& go install github.com/gogo/protobuf/protoc-gen-gogoslick \
&& go install github.com/gogo/protobuf/protoc-gen-gogotypes \
&& go install github.com/gogo/protobuf/protoc-gen-gostring \
&& go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger \
&& go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway \
&& go install github.com/lyft/protoc-gen-validate \
&& go install github.com/mwitkow/go-proto-validators/protoc-gen-govalidators \
&& go install github.com/pseudomuto/protoc-gen-doc/cmd/... \
&& go install \
-ldflags "-X github.com/infobloxopen/protoc-gen-gorm/plugin.ProtocGenGormVersion=$PGG_VERSION -X github.com/infobloxopen/protoc-gen-gorm/plugin.AtlasAppToolkitVersion=$AAT_VERSION" \
github.com/infobloxopen/protoc-gen-gorm \
&& rm -rf vendor/* ${GOPATH}/pkg/* \
&& install -c ${GOPATH}/bin/protoc-gen* /out/usr/bin/
RUN mkdir -p /out/protos && \
find ${GOPATH}/src -name "*.proto" -exec cp --parents {} /out/protos \;
RUN git clone --depth 1 --recursive https://github.com/upx/upx.git /upx
RUN cd /upx/src && \
make -j2 upx.out CHECK_WHITESPACE=
RUN /upx/src/upx.out --lzma -o /usr/bin/upx /upx/src/upx.out
RUN upx --lzma \
/out/usr/bin/protoc \
/out/usr/bin/grpc_* \
/out/usr/bin/protoc-gen-*
FROM alpine:3.6
RUN apk add --no-cache libstdc++
COPY --from=builder /out/usr /usr
COPY --from=builder /out/protos /
WORKDIR /go/src
RUN mkdir -p google/protobuf && \
for f in any duration empty struct timestamp wrappers; do \
cp /go/src/github.com/golang/protobuf/ptypes/${f}/${f}.proto /go/src/google/protobuf; \
done
# protoc as an entry point for all plugins with import paths set
ENTRYPOINT ["protoc", "-I.", \
# required import paths for protoc-gen-grpc-gateway plugin
"-Igithub.com/grpc-ecosystem/grpc-gateway/third_party/googleapis", \
# required import paths for protoc-gen-swagger plugin
"-Igithub.com/grpc-ecosystem/grpc-gateway", "-Igithub.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger/options", \
# required import paths for extensions of protoc-gen-gogo
"-Igithub.com/gogo/protobuf/protobuf", \
# required import paths for protoc-gen-validate plugin
"-Igithub.com/lyft/protoc-gen-validate/validate", \
# required import paths for go-proto-validators plugin
"-Igithub.com/mwitkow/go-proto-validators", \
# googleapis proto files
"-Igithub.com/googleapis/googleapis", \
# required import paths for protoc-gen-gorm plugin
"-Igithub.com/infobloxopen/protoc-gen-gorm" \
]