Have a look at this (extract from a Dockerfile
):
ARG VERS="3.13.0"
ARG ARCH="linux-x86_64"
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v${VERS}/protoc-${VERS}-${ARCH}.zip --output-document=./protoc-${VERS}-${ARCH}.zip && \
apt update && apt install -y unzip && \
unzip -o protoc-${VERS}-${ARCH}.zip -d protoc-${VERS}-${ARCH} && \
mv protoc-${VERS}-${ARCH}/bin/* /usr/local/bin && \
mv protoc-${VERS}-${ARCH}/include/* /usr/local/include && \
go get -u github.com/golang/protobuf/protoc-gen-go && \
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
ARG REPO="..."
ARG MODULE="github.com/${REPO}"
# Generates the Golang protobuf files
# NB Uses `go list` to determine the correct Modules directory for the package (!) containing Google APIs protos
RUN protoc \
--proto_path=. \
--proto_path=$(go list -f '{{ .Dir }}' -m github.com/grpc-ecosystem/grpc-gateway)/third_party/googleapis \
--go_out=plugins=grpc,module=${MODULE}:. \
./protos/*.proto
I use this snippet frequently when building gRPC-based solutions that use gRPC gateway.
The first RUN
gets protoc
, protoc-gen-go
and -protoc-gen-grpc-gateway
.
The second RUN
uses go list
to identify the installed grpc-gateway
module and points protoc
at it.
${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis
exists? can you try to open it? withcd
? – Alexsandro Souza