Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build protos via docker #6548

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,21 @@ PROTO_GO_OUTS = $(foreach name, $(PROTO_SRC_NAMES), go/vt/proto/$(name)/$(name).
# This rule rebuilds all the go files from the proto definitions for gRPC.
proto: $(PROTO_GO_OUTS)

docker-proto:
docker build -t proto-builder -f docker/proto/Dockerfile .
docker run --rm -v $(shell pwd)/go/vt/proto/:/go/vt/proto/ proto-builder

ifndef NOBANNER
echo $$(date): Compiling proto definitions
endif

# TODO(sougou): find a better way around this temp hack.
VTTOP=$(VTROOT)/../../..
$(PROTO_GO_OUTS): install_protoc-gen-go proto/*.proto
for name in $(PROTO_SRC_NAMES); do \
cd $(VTTOP)/src && \
$(VTROOT)/bin/protoc --go_out=plugins=grpc:. -Ivitess.io/vitess/proto vitess.io/vitess/proto/$${name}.proto && \
goimports -w $(VTROOT)/go/vt/proto/$${name}/$${name}.pb.go; \
$(VTROOT)/bin/protoc --go_out=plugins=grpc:. -Iproto proto/$${name}.proto && \
goimports -w vitess.io/vitess/go/vt/proto/$${name}/$${name}.pb.go; \
done
cp -Rf vitess.io/vitess/go/vt/proto/* go/vt/proto
rm -rf vitess.io/vitess/go/vt/proto/

# Helper targets for building Docker images.
# Please read docker/README.md to understand the different available images.
Expand Down
38 changes: 38 additions & 0 deletions docker/proto/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM golang:1.14-buster

# Install depedencies
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
curl \
unzip \
wget

ARG PROTOC_GEN_GO_VERSION=v1.3.2

# Need to set up a module in order to install a specific version of protoc-gen-go.
# 1. The `go get package@version` syntax is only supported in module mode.
# 2. In module mode, `go get` is unsupported outside of a module.
# These two things together force us to do this quick hack.
#
# See https://github.com/golang/go/issues/24250 as just one of many issues on the subject.
RUN mkdir proto-builder && \
cd proto-builder && \
go mod init proto-builder && \
GO111MODULE=on go get \
golang.org/x/tools/cmd/goimports \
github.com/golang/protobuf/protoc-gen-go@${PROTOC_GEN_GO_VERSION}

ARG PROTOC_VERSION=3.12.4

# Download protoc
RUN curl -LO https://github.com/protocolbuffers/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/local/bin/ && \
rm -rf protoc-${PROTOC_VERSION}-linux-x86_64.zip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what the end use of this container would be, but I would support having it be built once and pushed to the vitess repo on docker hub. That would prevent the fetching of these dependencies every time we rebuild proto's

Copy link
Contributor Author

@ajm188 ajm188 Aug 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushing this up somewhere sounds like a great idea! Is that something that I can do, or does that require a vitess maintainer (I see references to pushing in the Release Instructions, so I don't want to push carelessly).


ADD proto proto

# Build proto/$x.proto files into /go/vt/proto/$x/$x.pb.go
CMD [ "./proto/build.sh" ]
16 changes: 16 additions & 0 deletions proto/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

for file in proto/*.proto
do
name="$(basename "$file" | cut -d. -f1)"

echo "Building $name.proto ..."
dir="vt/proto/$name"
mkdir -p "./$dir" && chmod 755 "./$dir"

protoc --go_out=plugins=grpc:. -Iproto "proto/$name.proto"
mv "vitess.io/vitess/go/$dir/$name.pb.go" "./$dir/$name.pb.go"
goimports -w "./$dir/$name.pb.go"
done

rm -rf vitess.io