Skip to content

Commit

Permalink
update protoc-gen-go and split go gRPC plugin to protoc-gen-go-grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-namely committed Aug 24, 2022
1 parent 7b29cfb commit 1d0c570
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 57 deletions.
21 changes: 8 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ ARG node_protoc_gen_grpc_web_version
ARG ts_proto_version
ARG go_envoyproxy_pgv_version
ARG go_mwitkow_gpv_version
ARG go_protoc_gen_go_version
ARG go_protoc_gen_go_grpc_version

FROM golang:$go_version-$debian AS build

Expand All @@ -24,6 +26,9 @@ ARG scala_pb_version
ARG go_envoyproxy_pgv_version
ARG go_mwitkow_gpv_version
ARG uber_prototool_version
ARG go_protoc_gen_go_version
ARG go_protoc_gen_go_grpc_version


RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
build-essential \
Expand All @@ -42,7 +47,6 @@ RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
WORKDIR /tmp
RUN git clone --depth 1 --shallow-submodules -b v$grpc_version.x --recursive https://github.com/grpc/grpc && \
git clone --depth 1 --shallow-submodules -b v$grpc_java_version.x --recursive https://github.com/grpc/grpc-java.git && \
git clone --depth 1 --shallow-submodules -b v$grpc_version.x --recursive https://github.com/grpc/grpc-go.git && \
git clone --depth 1 https://github.com/googleapis/googleapis && \
git clone --depth 1 https://github.com/googleapis/api-common-protos

Expand All @@ -68,14 +72,8 @@ RUN curl -fsSL "https://github.com/uber/prototool/releases/download/v${uber_prot
-o /usr/local/bin/prototool && \
chmod +x /usr/local/bin/prototool

# Workaround for the transition to protoc-gen-go-grpc
# https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code
RUN ( cd ./grpc-go/cmd/protoc-gen-go-grpc && go install . )

# Go get go-related bins
WORKDIR /tmp
RUN set -e && \
GO111MODULE=on go get google.golang.org/[email protected]
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${go_protoc_gen_go_grpc_version}

# install protoc-gen-grpc-gateway and protoc-gen-openapiv2
RUN set -e && \
Expand All @@ -98,18 +96,15 @@ RUN set -e && \

RUN go get -u github.com/micro/micro/v3/cmd/protoc-gen-micro

# protoc-gen-go is depended on by protoc-gen-validate, install here and then overwrite later just in case to ensure that ultimately the right version is installed
RUN go get -u github.com/golang/protobuf/protoc-gen-go
RUN GO111MODULE=on go get -d github.com/envoyproxy/protoc-gen-validate@v${go_envoyproxy_pgv_version}
RUN make -C /go/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v${go_envoyproxy_pgv_version}/ build
RUN go install github.com/envoyproxy/protoc-gen-validate@v${go_envoyproxy_pgv_version}

# Add Ruby Sorbet types support (rbi)
RUN go get -u github.com/coinbase/protoc-gen-rbi

RUN go get github.com/gomatic/renderizer/v2/cmd/renderizer

# Origin protoc-gen-go should be installed last, for not been overwritten by any other binaries(see #210)
RUN go get -u github.com/golang/protobuf/protoc-gen-go
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@${go_protoc_gen_go_version}

# Need to get these too:
RUN go get -u github.com/mwitkow/go-proto-validators/@v${go_mwitkow_gpv_version}
Expand Down
77 changes: 42 additions & 35 deletions all/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,41 @@ printUsage() {
echo "Usage: gen-proto -f my-service.proto -l go"
echo " "
echo "options:"
echo " -h, --help Show help"
echo " -f FILE The proto source file to generate"
echo " -d DIR Scans the given directory for all proto files"
echo " -l LANGUAGE The language to generate (${SUPPORTED_LANGUAGES[@]})"
echo " -o DIRECTORY The output directory for generated files. Will be automatically created."
echo " -i includes Extra includes"
echo " --lint CHECKS Enable linting protoc-lint (CHECKS are optional - see https://github.com/ckaznocha/protoc-gen-lint#optional-checks)"
echo " --with-gateway Generate grpc-gateway files (experimental)."
echo " --with-docs FORMAT Generate documentation (FORMAT is optional - see https://github.com/pseudomuto/protoc-gen-doc#invoking-the-plugin)"
echo " --with-rbi Generate Sorbet type declaration files (.rbi files) - see https://github.com/coinbase/protoc-gen-rbi"
echo " --with-typescript Generate TypeScript declaration files (.d.ts files) - see https://github.com/improbable-eng/ts-protoc-gen#readme"
echo " --with-validator Generate validations for (${VALIDATOR_SUPPORTED_LANGUAGES[@]}) - see https://github.com/envoyproxy/protoc-gen-validate"
echo " --validator-source-relative Make the output dirctory for protoc-gen-validate 'source relative' - see https://github.com/envoyproxy/protoc-gen-validate#go"
echo " --go-source-relative Make go import paths 'source_relative' - see https://github.com/golang/protobuf#parameters"
echo " --go-module-prefix Specify the module prefix to remove from the import path - see https://developers.google.com/protocol-buffers/docs/reference/go-generated#invocation"
echo " --go-package-map Map proto imports to go import paths"
echo " --go-plugin-micro Replaces the Go gRPC plugin with go-micro"
echo " --go-proto-validator Generate Go proto validations - see https://github.com/mwitkow/go-proto-validators"
echo " --no-google-includes Don't include Google protobufs"
echo " --descr-include-imports When using --descriptor_set_out, also include all dependencies of the input files in the set, so that the set is self-contained"
echo " --descr-include-source-info When using --descriptor_set_out, do not strip SourceCodeInfo from the FileDescriptorProto. This results in vastly
larger descriptors that include information about the original location of each decl in the source file as well
as surrounding comments."
echo " --descr-filename The filename for the descriptor proto when used with -l descriptor_set. Default to descriptor_set.pb"
echo " --csharp_opt The options to pass to protoc to customize the csharp code generation."
echo " --scala_opt The options to pass to protoc to customize the scala code generation."
echo " --with-swagger-json-names Use with --with-gateway flag. Generated swagger file will use JSON names instead of protobuf names.
(deprecated. Please use --with-openapi-json-names)"
echo " --with-openapi-json-names Use with --with-gateway flag. Generated OpenAPI file will use JSON names instead of protobuf names."
echo " --generate-unbound-methods Use with --with-gateway flag. Produce the HTTP mapping even for methods without any HttpRule annotation."
echo " --js-out This option overrides the 'js_out=' argument in the grpc-node and grpc-web code generation. Defaults to 'import_style=commonjs'."
echo " --grpc-out This option allows overriding the left-half of the 'grpc_out=' argument (before the colon) with grpc-node and grpc-web code generation. Options are: generate_package_definition, grpc_js or grpc(depricated from April 2021). Defaults to grpc_js."
echo " --grpc-web-out This option overrides the 'grpc-web_out=' argument in the grpc-web code generation. Defaults to 'import_style=typescript'."
echo " --ts_opt The options to pass to protoc to customize the typescript code generation. See https://github.com/stephenh/ts-proto#supported-options. --ts_opt useOptionals=messages will evaluate to --ts_proto_opt=useOptionals=messages"
echo " -h, --help Show help"
echo " -f FILE The proto source file to generate"
echo " -d DIR Scans the given directory for all proto files"
echo " -l LANGUAGE The language to generate (${SUPPORTED_LANGUAGES[@]})"
echo " -o DIRECTORY The output directory for generated files. Will be automatically created."
echo " -i includes Extra includes"
echo " --lint CHECKS Enable linting protoc-lint (CHECKS are optional - see https://github.com/ckaznocha/protoc-gen-lint#optional-checks)"
echo " --with-gateway Generate grpc-gateway files (experimental)."
echo " --with-docs FORMAT Generate documentation (FORMAT is optional - see https://github.com/pseudomuto/protoc-gen-doc#invoking-the-plugin)"
echo " --with-rbi Generate Sorbet type declaration files (.rbi files) - see https://github.com/coinbase/protoc-gen-rbi"
echo " --with-typescript Generate TypeScript declaration files (.d.ts files) - see https://github.com/improbable-eng/ts-protoc-gen#readme"
echo " --with-validator Generate validations for (${VALIDATOR_SUPPORTED_LANGUAGES[@]}) - see https://github.com/envoyproxy/protoc-gen-validate"
echo " --validator-source-relative Make the output dirctory for protoc-gen-validate 'source relative' - see https://github.com/envoyproxy/protoc-gen-validate#go"
echo " --go-source-relative Make go import paths 'source_relative' - see https://github.com/golang/protobuf#parameters"
echo " --go-module-prefix Specify the module prefix to remove from the import path - see https://developers.google.com/protocol-buffers/docs/reference/go-generated#invocation"
echo " --go-package-map Map proto imports to go import paths"
echo " --go-plugin-micro Replaces the Go gRPC plugin with go-micro"
echo " --go-proto-validator Generate Go proto validations - see https://github.com/mwitkow/go-proto-validators"
echo " --go-grpc-require-unimplemented-servers Generate Go gRPC service with unimplemented server for future compatability- https://github.com/grpc/grpc-go/tree/master/cmd/protoc-gen-go-grpc#future-proofing-services"
echo " --no-google-includes Don't include Google protobufs"
echo " --descr-include-imports When using --descriptor_set_out, also include all dependencies of the input files in the set, so that the set is self-contained"
echo " --descr-include-source-info When using --descriptor_set_out, do not strip SourceCodeInfo from the FileDescriptorProto. This results in vastly
larger descriptors that include information about the original location of each decl in the source file as well
as surrounding comments."
echo " --descr-filename The filename for the descriptor proto when used with -l descriptor_set. Default to descriptor_set.pb"
echo " --csharp_opt The options to pass to protoc to customize the csharp code generation."
echo " --scala_opt The options to pass to protoc to customize the scala code generation."
echo " --with-swagger-json-names Use with --with-gateway flag. Generated swagger file will use JSON names instead of protobuf names.
(deprecated. Please use --with-openapi-json-names)"
echo " --with-openapi-json-names Use with --with-gateway flag. Generated OpenAPI file will use JSON names instead of protobuf names."
echo " --generate-unbound-methods Use with --with-gateway flag. Produce the HTTP mapping even for methods without any HttpRule annotation."
echo " --js-out This option overrides the 'js_out=' argument in the grpc-node and grpc-web code generation. Defaults to 'import_style=commonjs'."
echo " --grpc-out This option allows overriding the left-half of the 'grpc_out=' argument (before the colon) with grpc-node and grpc-web code generation. Options are: generate_package_definition, grpc_js or grpc(depricated from April 2021). Defaults to grpc_js."
echo " --grpc-web-out This option overrides the 'grpc-web_out=' argument in the grpc-web code generation. Defaults to 'import_style=typescript'."
echo " --ts_opt The options to pass to protoc to customize the typescript code generation. See https://github.com/stephenh/ts-proto#supported-options. --ts_opt useOptionals=messages will evaluate to --ts_proto_opt=useOptionals=messages"
}

GEN_GATEWAY=false
Expand All @@ -59,6 +60,7 @@ GO_MODULE_PREFIX=""
GO_PACKAGE_MAP=""
GO_PLUGIN="grpc"
GO_VALIDATOR=false
GO_GRPC_REQUIRE_UNIMPLEMENTED_SERVERS="require_unimplemented_servers=false"
NO_GOOGLE_INCLUDES=false
DESCR_INCLUDE_IMPORTS=false
DESCR_INCLUDE_SOURCE_INFO=false
Expand Down Expand Up @@ -175,6 +177,10 @@ while test $# -gt 0; do
GO_VALIDATOR=true
shift
;;
--go-grpc-require-unimplemented-servers)
GO_GRPC_REQUIRE_UNIMPLEMENTED_SERVERS="require_unimplemented_servers=true"
shift
;;
--no-google-includes)
NO_GOOGLE_INCLUDES=true
shift
Expand Down Expand Up @@ -328,7 +334,8 @@ fi
GEN_STRING=''
case $GEN_LANG in
"go")
GEN_STRING="--go_out=${GO_SOURCE_RELATIVE}${GO_MODULE_PREFIX}${GO_PACKAGE_MAP}plugins=grpc:$OUT_DIR"
GEN_STRING="--go_out=${GO_SOURCE_RELATIVE}${GO_MODULE_PREFIX}${GO_PACKAGE_MAP}:$OUT_DIR\
--go-grpc_out=${GO_SOURCE_RELATIVE}${GO_MODULE_PREFIX}${GO_PACKAGE_MAP}${GO_GRPC_REQUIRE_UNIMPLEMENTED_SERVERS}:$OUT_DIR"
if [[ ${GO_PLUGIN} == "micro" ]]; then
GEN_STRING="$GEN_STRING --micro_out=$OUT_DIR"
fi
Expand Down
Loading

0 comments on commit 1d0c570

Please sign in to comment.