From 520f0ce8fed93f108811db3c3a57ebf488b31d14 Mon Sep 17 00:00:00 2001 From: James Craig Burley <430319+jcburley@users.noreply.github.com> Date: Tue, 14 Dec 2021 15:11:46 -0500 Subject: [PATCH] Upgrade to Go 1.17 (#273) * Preliminary attempt to upgrade to generating Go 1.17 code * With -e in effect, a nonzero status code exits immediately, so capture it * Explain what went wrong before printing usage * Update to grpc 1.41 * Upgrade alpine to 3.14 * Tiidy the gateway dockerfilie * Upgrade more components, 'fix' test to expect new data type * Fix typo that occurred in 3 places (to no net effect afaict) * Upgrade protobuf to v1.27.1 * PR feedback * Further PR feedback * Upgrade to gRPC 1.42.0 * PR feedback * Add rudimentary testing of --go-proto-validator Co-authored-by: James Craig Burley Co-authored-by: Orest Petruniv --- Dockerfile | 16 +++++++++++----- all/test.sh | 26 ++++++++++++++++++++++++-- build.sh | 3 ++- gwy/generate_gateway.sh | 2 ++ gwy/templates/Dockerfile.tmpl | 6 ++++-- gwy/templates/go.mod.tmpl | 6 +++--- variables.sh | 9 +++++---- 7 files changed, 51 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1031951c..93724a90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ ARG node_grpc_tools_node_protoc_ts_version ARG node_grpc_tools_version ARG node_protoc_gen_grpc_web_version ARG go_envoyproxy_pgv_version +ARG go_mwitkow_gpv_version FROM golang:$go_version-$debian AS build @@ -20,6 +21,7 @@ ARG grpc_java_version ARG grpc_web_version ARG scala_pb_version ARG go_envoyproxy_pgv_version +ARG go_mwitkow_gpv_version RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \ build-essential \ @@ -92,21 +94,23 @@ RUN go get -u github.com/ckaznocha/protoc-gen-lint RUN set -e && \ GO111MODULE=on go get github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc -RUN go get -u github.com/micro/micro/cmd/protoc-gen-micro +RUN go get -u github.com/micro/micro/v3/cmd/protoc-gen-micro 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 get -u github.com/mwitkow/go-proto-validators/protoc-gen-govalidators - # Add Ruby Sorbet types support (rbi) RUN go get -u github.com/coinbase/protoc-gen-rbi -RUN go get github.com/gomatic/renderizer/cmd/renderizer +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 +# Need to get these too: +RUN go get -u github.com/mwitkow/go-proto-validators/@v${go_mwitkow_gpv_version} +RUN go get -u github.com/mwitkow/go-proto-validators/protoc-gen-govalidators@v${go_mwitkow_gpv_version} + # Add scala support RUN curl -LO https://github.com/scalapb/ScalaPB/releases/download/v${scala_pb_version}/protoc-gen-scala-${scala_pb_version}-linux-x86_64.zip \ && unzip protoc-gen-scala-${scala_pb_version}-linux-x86_64.zip \ @@ -128,6 +132,7 @@ ARG node_grpc_tools_version ARG node_protoc_gen_grpc_web_version ARG go_envoyproxy_pgv_version +ARG go_mwitkow_gpv_version RUN mkdir -p /usr/share/man/man1 RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \ @@ -172,7 +177,8 @@ COPY --from=build /tmp/protoc-gen-scala /usr/local/bin/ COPY --from=build /go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v${grpc_gateway_version}/protoc-gen-openapiv2/options /opt/include/protoc-gen-openapiv2/options/ COPY --from=build /go/pkg/mod/github.com/envoyproxy/protoc-gen-validate@v${go_envoyproxy_pgv_version}/ /opt/include/ -COPY --from=build /go/src/github.com/mwitkow/go-proto-validators/ /opt/include/github.com/mwitkow/go-proto-validators/ + +COPY --from=build /go/pkg/mod/github.com/mwitkow/go-proto-validators@v${go_mwitkow_gpv_version}/ /opt/include/github.com/mwitkow/go-proto-validators/ ADD all/entrypoint.sh /usr/local/bin RUN chmod +x /usr/local/bin/entrypoint.sh diff --git a/all/test.sh b/all/test.sh index 31660497..f207e89d 100755 --- a/all/test.sh +++ b/all/test.sh @@ -5,7 +5,7 @@ LANGS=("go" "ruby" "csharp" "java" "python" "objc" "node" "gogo" "php" "cpp" "de CONTAINER=${CONTAINER} if [ -z ${CONTAINER} ]; then - echo "You must specify a build container with \${CONTAINER} to test" + echo "You must specify a build container with \${CONTAINER} to test (see my README.md)" exit 1 fi @@ -116,7 +116,7 @@ testGeneration() { expected_field_mask_property_type="array" actual_field_mask_property_type=$(cat $expected_output_dir$expected_file_name2 | jq '.definitions.MessagesUpdateMessageRequest.properties.updateMask.type' | tr -d "\042") if [ ! "$actual_field_mask_property_type" == "$expected_field_mask_property_type" ]; then - echo "expected field mask type not found" + echo "expected field mask type not found ($actual_field_mask_property_type != $expected_field_mask_property_type)" exit 1 fi @@ -158,6 +158,22 @@ testGeneration() { fi fi + if [[ "$extra_args" == *"--with-go-proto-validator"* ]]; then + expected_file_name1="/all/test.pb.go" + expected_file_name2="/all/test.pb.validate.go" + if [[ "$extra_args" == *"--validator-source-relative"* ]]; then + expected_file_name2="/all/test/test.pb.validate.go" + fi + if [[ ! -f "$expected_output_dir$expected_file_name1" ]]; then + echo "$expected_file_name1 file was not generated in $expected_output_dir" + exit 1 + fi + if [[ ! -f "$expected_output_dir$expected_file_name2" ]]; then + echo "$expected_file_name2 file was not generated in $expected_output_dir" + exit 1 + fi + fi + if [[ "$extra_args" == *"--js-out library=testlib"* ]]; then # Test that we have generated the testlib.js file testlib_count=$(find $expected_output_dir -type f -name "testlib.js" | wc -l) @@ -241,6 +257,12 @@ testGeneration go "gen/pb-go" 0 --with-validator # Test go validator with source relative option testGeneration go "gen/pb-go" 0 --with-validator --validator-source-relative +# Test the other go validator +testGeneration go "gen/pb-go" 0 --go-proto-validator + +# Test the other go validator with source relative option +testGeneration go "gen/pb-go" 0 ---go-proto-validator --validator-source-relative + # Test go-micro generations testGeneration go "gen/pb-go" 0 --go-plugin-micro diff --git a/build.sh b/build.sh index 33260450..b868e3cf 100755 --- a/build.sh +++ b/build.sh @@ -17,8 +17,9 @@ for build in ${BUILDS[@]}; do --build-arg node_version=${NODE_VERSION} \ --build-arg node_grpc_tools_node_protoc_ts_version=${NODE_GRPC_TOOLS_NODE_PROTOC_TS_VERSION} \ --build-arg node_grpc_tools_version=${NODE_GRPC_TOOLS_VERSION} \ - --build-arg node_protoc_gen_grpc_web_version=${NODE_PROTOC_GET_GRPC_WEB_VERSION} \ + --build-arg node_protoc_gen_grpc_web_version=${NODE_PROTOC_GEN_GRPC_WEB_VERSION} \ --build-arg go_envoyproxy_pgv_version=${GO_ENVOYPROXY_PGV_VERSION} \ + --build-arg go_mwitkow_gpv_version=${GO_MWITKOW_GPV_VERSION} \ --target ${build} \ . diff --git a/gwy/generate_gateway.sh b/gwy/generate_gateway.sh index 4c487946..46c3537d 100755 --- a/gwy/generate_gateway.sh +++ b/gwy/generate_gateway.sh @@ -96,6 +96,8 @@ while test $# -gt 0; do shift ;; *) + echo "Unrecognized option or argument: $1 in $@" + echo "" printUsage exit 1 ;; diff --git a/gwy/templates/Dockerfile.tmpl b/gwy/templates/Dockerfile.tmpl index f8fe13f5..2d9ae7d7 100644 --- a/gwy/templates/Dockerfile.tmpl +++ b/gwy/templates/Dockerfile.tmpl @@ -1,7 +1,7 @@ # Template for grpc-gateway -ARG alpine_version=3.11 -ARG go_version=1.14 +ARG alpine_version=3.14 +ARG go_version=1.17 FROM golang:$go_version-alpine$alpine_version AS build RUN apk add --update --no-cache git @@ -10,6 +10,8 @@ WORKDIR /app # Copy all of the staged files (protos plus go source) COPY . /app/ +RUN go mod tidy + # Build the gateway RUN go build -o /app/grpc_gateway cmd/gateway/main.go diff --git a/gwy/templates/go.mod.tmpl b/gwy/templates/go.mod.tmpl index 7bd3358f..22eb961a 100644 --- a/gwy/templates/go.mod.tmpl +++ b/gwy/templates/go.mod.tmpl @@ -1,6 +1,6 @@ module gateway -go 1.14 +go 1.17 require ( github.com/gorilla/handlers v1.5.1 @@ -9,6 +9,6 @@ require ( github.com/sirupsen/logrus v1.7.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.7.1 - google.golang.org/grpc v1.41.0 - google.golang.org/protobuf v1.24.0 + google.golang.org/grpc v1.42.0 + google.golang.org/protobuf v1.27.1 ) diff --git a/variables.sh b/variables.sh index e343610b..524c8b65 100755 --- a/variables.sh +++ b/variables.sh @@ -6,9 +6,9 @@ NAMESPACE=${NAMESPACE:-namely} CONTAINER=${DOCKER_REPO}${NAMESPACE} LATEST=${1:false} -GO_VERSION=${GO_VERSION:-1.14} -GRPC_VERSION=${GRPC_VERSION:-1.41} -GRPC_JAVA_VERSION=${GRPC_JAVA_VERSION:-1.41} +GO_VERSION=${GO_VERSION:-1.17} +GRPC_VERSION=${GRPC_VERSION:-1.42} +GRPC_JAVA_VERSION=${GRPC_JAVA_VERSION:-1.42} GRPC_WEB_VERSION=${GRPC_WEB_VERSION:-1.2.1} GRPC_GATEWAY_VERSION=${GRPC_GATEWAY_VERSION:-2.0.1} UBER_PROTOTOOL_VERSION=${UBER_PROTOTOOL_VERSION:-1.3.0} @@ -16,7 +16,8 @@ SCALA_PB_VERSION=${SCALA_PB_VERSION:-0.11.0} NODE_VERSION=${NODE_VERSION:-14} NODE_GRPC_TOOLS_NODE_PROTOC_TS_VERSION=${NODE_GRPC_TOOLS_NODE_PROTOC_TS_VERSION:-5.1.3} NODE_GRPC_TOOLS_VERSION=${NODE_GRPC_TOOLS_VERSION:-1.11.1} -NODE_PROTOC_GET_GRPC_WEB_VERSION=${NODE_PROTOC_GET_GRPC_WEB_VERSION:-1.2.1} +NODE_PROTOC_GEN_GRPC_WEB_VERSION=${NODE_PROTOC_GEN_GRPC_WEB_VERSION:-1.2.1} GO_ENVOYPROXY_PGV_VERSION=${GO_ENVOYPROXY_PGV_VERSION:-0.6.1} +GO_MWITKOW_GPV_VERSION=${GO_MWITKOW_GPV_VERSION:-0.3.2} BUILD_VERSION="${BUILD_VERSION:-local}" VERSION="${VERSION:-${GRPC_VERSION}_${BUILD_VERSION}}"