Skip to content

Commit

Permalink
Faster proto generation (#2402)
Browse files Browse the repository at this point in the history
From 2:23 to 1:49 with an empty docker cache.

Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot authored Jul 4, 2019
1 parent da89d7b commit 2f2a6f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion hack/generate-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
cd $GOPATH/src/github.com/GoogleContainerTools/skaffold
export CONTAINER_NAME=generate-proto
export PROTO_PATH=pkg/skaffold/server/proto
docker build -t $CONTAINER_NAME -f hack/proto/Dockerfile --target generateFiles .
docker build -t $CONTAINER_NAME -f hack/proto/Dockerfile --target generateFiles ${PROTO_PATH}
if [ $? -ne 0 ]; then
printf "\nError generating files.\n"
exit 1
Expand Down
20 changes: 8 additions & 12 deletions hack/proto/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,24 @@
# limitations under the License.

# Install protoc
FROM ubuntu@sha256:9b1702dcfe32c873a770a32cfd306dd7fc1c4fd134adfb783db68defc8894b3c AS protoc
RUN apt-get update && apt-get install -y curl unzip
FROM alpine:3.9 AS protoc
RUN apk add --no-cache unzip

ENV PROTOC_VERSION=3.8.0
RUN curl -Lo protoc-${PROTOC_VERSION}-linux-x86_64.zip https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \
unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d protoc && \
mv protoc/bin/protoc /usr/bin/protoc

RUN wget -O protoc.zip https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip
RUN unzip protoc.zip -d protoc

# Install protoc-gen-go and grpc-gateway binaries; then generate files.
FROM golang AS generateFiles
FROM golang:1.12.5-alpine3.9 AS generateFiles
RUN apk add --no-cache protobuf git

COPY --from=protoc /usr/bin/protoc /usr/bin/protoc
COPY --from=protoc /protoc/include /usr/local/include

ENV GIT_TAG=v1.2.0
RUN go get -d -u github.com/golang/protobuf/protoc-gen-go
RUN git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG
RUN go install github.com/golang/protobuf/protoc-gen-go


WORKDIR /go/src/github.com/grpc-ecosystem
RUN git clone https://github.com/grpc-ecosystem/grpc-gateway.git

Expand All @@ -48,13 +45,12 @@ RUN go get -u github.com/golang/protobuf/protoc-gen-go

WORKDIR /
ENV PROTO_PATH=/pkg/skaffold/server/proto
COPY ${PROTO_PATH}/skaffold.proto ${PROTO_PATH}/skaffold.proto
COPY skaffold.proto ${PROTO_PATH}/skaffold.proto
RUN protoc -I /usr/local/include -I pkg/skaffold/server/proto -I $GOPATH/src -I $GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:pkg/skaffold/server/proto pkg/skaffold/server/proto/skaffold.proto --go_out=plugins=grpc:pkg/skaffold/server/proto


# Compare the proto files with the existing proto files
FROM generateFiles AS compare
WORKDIR /compare
COPY ${PROTO_PATH}/*.go ./
COPY *.go ./
RUN cmp ${PROTO_PATH}/skaffold.pb.go skaffold.pb.go
RUN cmp ${PROTO_PATH}/skaffold.pb.gw.go skaffold.pb.gw.go

0 comments on commit 2f2a6f4

Please sign in to comment.