Skip to content

Instantly share code, notes, and snippets.

@atomatt
Last active January 6, 2021 17:32
Show Gist options
  • Select an option

  • Save atomatt/a73cd111769fb32d37aefa27363ec962 to your computer and use it in GitHub Desktop.

Select an option

Save atomatt/a73cd111769fb32d37aefa27363ec962 to your computer and use it in GitHub Desktop.
General purpose protobuf tools image
FROM alpine as protoc
RUN apk add unzip
ADD https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/protoc-3.14.0-linux-x86_64.zip /
WORKDIR /protoc
RUN unzip /protoc-3.14.0-linux-x86_64.zip
FROM golang:1.15.6 as protoc-go
RUN \
export GO111MODULE=on && \
go get google.golang.org/protobuf/cmd/protoc-gen-go \
google.golang.org/grpc/cmd/protoc-gen-go-grpc
FROM alpine as googleapis
RUN apk add git
RUN git clone --depth=1 https://github.com/googleapis/googleapis
FROM python
RUN python -m pip install grpcio-tools
COPY --from=protoc /protoc/bin/* /usr/local/bin/
COPY --from=protoc-go /go/bin/* /usr/local/bin/
COPY --from=protoc /protoc/include/* /usr/local/include/google/
COPY --from=googleapis /googleapis/google/api/* /usr/local/include/google/api/
WORKDIR /work
ENTRYPOINT []
CMD ["sh"]
@atomatt
Copy link
Author

atomatt commented Jan 6, 2021

e.g.

$ docker build ./pbtool -t pbtool
$ docker run --rm -it -v $(pwd):/work pbtool protoc --go_out=. --go-grpc_out=. ./proto/*.proto
$ docker run --rm -it -v $(pwd):/work pbtool protoc -I. --include_imports --descriptor_set_out=pb/service.pb ./proto/*.proto
$ docker run --rm -it -v $(pwd):/work pbtool python -m grpc_tools.protoc --proto_path=. --python_out=. --grpc_python_out=. ./proto/*.proto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment