Skip to content

Commit

Permalink
Make grpc gateway v2.21.0 (#1385)
Browse files Browse the repository at this point in the history
Ran `go run ./internal/cmd/fetcher plugins/grpc-ecosystem ` and updated
the patch for the version.

[upstream release
changelog](grpc-ecosystem/grpc-gateway@v2.20.0...v2.21.0)

Patch diff:

```
diff plugins/grpc-ecosystem/gateway/v2.21.0/separate_pkg_additional_imports.patch plugins/grpc-ecosystem/gateway/v2.20.0/separate_pkg_additional_imports.patch
71c71
< index 684fc5b6..c1b69363 100644
---
> index 421c0089..26bed31a 100644
88c88
< @@ -255,6 +262,9 @@ func (r *Registry) loadFile(filePath string, file *protogen.File) {
---
> @@ -252,6 +259,9 @@ func (r *Registry) loadFile(filePath string, file *protogen.File) {
577c577
< index 9975e424..13332ef7 100644
---
> index ffe4d413..fdd9bc5b 100644
649c649
< @@ -606,6 +624,9 @@ func local_request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ct
---
> @@ -606,12 +624,18 @@ func local_request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ct
659c659
< @@ -613,6 +634,9 @@ func local_request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ct
---
>  // UnaryRPC     :call {{$svc.GetName}}Server directly.
662d661
<  // GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.
669c668
< @@ -664,6 +688,7 @@ func Register{{$svc.GetName}}{{$.RegisterFuncSuffix}}Server(ctx context.Context,
---
> @@ -663,6 +687,7 @@ func Register{{$svc.GetName}}{{$.RegisterFuncSuffix}}Server(ctx context.Context,
677c676
< @@ -671,6 +696,9 @@ func Register{{$svc.GetName}}{{$.RegisterFuncSuffix}}Server(ctx context.Context,
---
> @@ -670,6 +695,9 @@ func Register{{$svc.GetName}}{{$.RegisterFuncSuffix}}Server(ctx context.Context,
687c686
< @@ -693,18 +721,26 @@ func Register{{$svc.GetName}}{{$.RegisterFuncSuffix}}FromEndpoint(ctx context.Co
---
> @@ -692,18 +720,26 @@ func Register{{$svc.GetName}}{{$.RegisterFuncSuffix}}FromEndpoint(ctx context.Co
707c706
<  // "{{$svc.InstanceName}}Client" to call the correct interceptors. This client ignores the HTTP middlewares.
---
>  // "{{$svc.InstanceName}}Client" to call the correct interceptors.
714c713
< @@ -785,5 +821,9 @@ var (
---
> @@ -784,5 +820,9 @@ var (
726c725
< index 086a4624..5f65b894 100644
---
> index 5a1e6977..7e89ad1c 100644
737c736
< @@ -36,6 +37,7 @@ var (
---
> @@ -35,6 +36,7 @@ var (
745c744
< @@ -73,15 +75,22 @@ func main() {
---
> @@ -58,15 +60,22 @@ func main() {
772c771
< @@ -135,6 +144,7 @@ func applyFlags(reg *descriptor.Registry) error {
---
> @@ -120,6 +129,7 @@ func applyFlags(reg *descriptor.Registry) error {
```

Upstream diff in plugin

```
git --no-pager diff v2.20.0..v2.21.0 protoc-gen-grpc-gateway
diff --git a/protoc-gen-grpc-gateway/internal/gengateway/template.go b/protoc-gen-grpc-gateway/internal/gengateway/template.go
index ffe4d413..9975e424 100644
--- a/protoc-gen-grpc-gateway/internal/gengateway/template.go
+++ b/protoc-gen-grpc-gateway/internal/gengateway/template.go
@@ -612,6 +612,7 @@ func local_request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ct
 // UnaryRPC     :call {{$svc.GetName}}Server directly.
 // StreamingRPC :currently unsupported pending grpc/grpc-go#906.
 // Note that using this registration option will cause many gRPC library features to stop working. Consider using Register{{$svc.GetName}}{{$.RegisterFuncSuffix}}FromEndpoint instead.
+// GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.
 func Register{{$svc.GetName}}{{$.RegisterFuncSuffix}}Server(ctx context.Context, mux *runtime.ServeMux, server {{$svc.InstanceName}}Server) error {
 	{{range $m := $svc.Methods}}
 	{{range $b := $m.Bindings}}
@@ -703,7 +704,7 @@ func Register{{$svc.GetName}}{{$.RegisterFuncSuffix}}(ctx context.Context, mux *
 // to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "{{$svc.InstanceName}}Client".
 // Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "{{$svc.InstanceName}}Client"
 // doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
-// "{{$svc.InstanceName}}Client" to call the correct interceptors.
+// "{{$svc.InstanceName}}Client" to call the correct interceptors. This client ignores the HTTP middlewares.
 func Register{{$svc.GetName}}{{$.RegisterFuncSuffix}}Client(ctx context.Context, mux *runtime.ServeMux, client {{$svc.InstanceName}}Client) error {
 	{{range $m := $svc.Methods}}
 	{{range $b := $m.Bindings}}
diff --git a/protoc-gen-grpc-gateway/main.go b/protoc-gen-grpc-gateway/main.go
index 5a1e6977..086a4624 100644
--- a/protoc-gen-grpc-gateway/main.go
+++ b/protoc-gen-grpc-gateway/main.go
@@ -13,6 +13,7 @@ import (
 	"flag"
 	"fmt"
 	"os"
+	"runtime/debug"
 	"strings"

 	"github.com/grpc-ecosystem/grpc-gateway/v2/internal/codegenerator"
@@ -50,6 +51,20 @@ func main() {
 	flag.Parse()

 	if *versionFlag {
+		if commit == "unknown" {
+			buildInfo, ok := debug.ReadBuildInfo()
+			if ok {
+				version = buildInfo.Main.Version
+				for _, setting := range buildInfo.Settings {
+					if setting.Key == "vcs.revision" {
+						commit = setting.Value
+					}
+					if setting.Key == "vcs.time" {
+						date = setting.Value
+					}
+				}
+			}
+		}
 		fmt.Printf("Version %v, commit %v, built at %v\n", version, commit, date)
 		os.Exit(0)
 	}
```
  • Loading branch information
oliversun9 authored Jul 31, 2024
1 parent ee0a19d commit e3e37a0
Show file tree
Hide file tree
Showing 8 changed files with 829 additions and 4 deletions.
4 changes: 0 additions & 4 deletions plugins/grpc-ecosystem/gateway/source.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
source:
# Temporarily disabled until we can fix both the patch and tests.
#
# See https://github.com/bufbuild/plugins/issues/1382 for more details.
disabled: true
github:
owner: grpc-ecosystem
repository: grpc-gateway
3 changes: 3 additions & 0 deletions plugins/grpc-ecosystem/gateway/v2.21.0/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!Dockerfile
!separate_pkg_additional_imports.patch
21 changes: 21 additions & 0 deletions plugins/grpc-ecosystem/gateway/v2.21.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# syntax=docker/dockerfile:1.9
FROM --platform=$BUILDPLATFORM golang:1.22.5-bookworm AS build

ARG TARGETOS TARGETARCH
ENV CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH

WORKDIR /tmp
RUN git clone --depth 1 --branch v2.21.0 https://github.com/grpc-ecosystem/grpc-gateway.git
COPY --link separate_pkg_additional_imports.patch /tmp/separate_pkg_additional_imports.patch
WORKDIR /tmp/grpc-gateway
RUN git apply /tmp/separate_pkg_additional_imports.patch
WORKDIR /tmp/grpc-gateway/protoc-gen-grpc-gateway
RUN --mount=type=cache,target=/go/pkg/mod \
go install -ldflags="-s -w" -trimpath \
&& mv /go/bin/${GOOS}_${GOARCH}/protoc-gen-grpc-gateway /go/bin/protoc-gen-grpc-gateway || true

FROM scratch
COPY --from=build --link --chown=root:root /etc/passwd /etc/passwd
COPY --from=build --link --chown=root:root /go/bin/protoc-gen-grpc-gateway /
USER nobody
ENTRYPOINT [ "/protoc-gen-grpc-gateway" ]
23 changes: 23 additions & 0 deletions plugins/grpc-ecosystem/gateway/v2.21.0/buf.plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: v1
name: buf.build/grpc-ecosystem/gateway
plugin_version: v2.21.0
source_url: https://github.com/grpc-ecosystem/grpc-gateway
integration_guide_url: https://github.com/grpc-ecosystem/grpc-gateway#usage
description: gRPC to JSON proxy generator following the gRPC HTTP spec.
output_languages:
- go
registry:
go:
min_version: "1.20"
deps:
- module: github.com/grpc-ecosystem/grpc-gateway/v2
version: v2.21.0
opts:
- paths=source_relative
- standalone=true
- separate_package=true
deps:
- plugin: buf.build/protocolbuffers/go:v1.34.2
- plugin: buf.build/grpc/go:v1.5.1
spdx_license_id: BSD-3-Clause
license_url: https://github.com/grpc-ecosystem/grpc-gateway/blob/v2.21.0/LICENSE.txt
Loading

0 comments on commit e3e37a0

Please sign in to comment.