Skip to content

Commit

Permalink
Upgrade to Go 1.17 (#273)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Orest Petruniv <[email protected]>
  • Loading branch information
3 people authored Dec 14, 2021
1 parent 0ac94c8 commit 520f0ce
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 17 deletions.
16 changes: 11 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 \
Expand Down Expand Up @@ -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 \
Expand All @@ -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 \
Expand Down Expand Up @@ -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
Expand Down
26 changes: 24 additions & 2 deletions all/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
.

Expand Down
2 changes: 2 additions & 0 deletions gwy/generate_gateway.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ while test $# -gt 0; do
shift
;;
*)
echo "Unrecognized option or argument: $1 in $@"
echo ""
printUsage
exit 1
;;
Expand Down
6 changes: 4 additions & 2 deletions gwy/templates/Dockerfile.tmpl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions gwy/templates/go.mod.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module gateway

go 1.14
go 1.17

require (
github.com/gorilla/handlers v1.5.1
Expand All @@ -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
)
9 changes: 5 additions & 4 deletions variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ 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}
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}}"

0 comments on commit 520f0ce

Please sign in to comment.