-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for gateway generation (#18)
Improve the docs for where custom plugins should be defined and add an example with grpc-gateway.
- Loading branch information
1 parent
c68f583
commit ddcaa81
Showing
11 changed files
with
123 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# syntax=docker/dockerfile:1.6 | ||
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS build | ||
ARG TARGETOS TARGETARCH | ||
|
||
# Add custom plugins here | ||
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ | ||
go install -ldflags "-s -w" google.golang.org/protobuf/cmd/protoc-gen-go@v1.32 \ | ||
&& go install -ldflags "-s -w" google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3 \ | ||
&& go install -ldflags "-s -w" github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@v0.5.0 \ | ||
&& go install -ldflags "-s -w" github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.19 | ||
|
||
# Install protoc-gen-multi, must be installed. | ||
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ | ||
go install -ldflags "-s -w" github.com/bufbuild/tools/cmd/protoc-gen-multi@latest | ||
|
||
# Move binaries prefixed with GOOS_GOARCH to /go/bin. | ||
RUN mv /go/bin/$TARGETOS_$TARGETARCH/* /go/bin || true | ||
|
||
# Build final image. | ||
FROM scratch | ||
COPY --from=build --link /etc/passwd /etc/passwd | ||
COPY --from=build /go/bin/ /bin | ||
USER nobody | ||
ENTRYPOINT [ "protoc-gen-multi" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
version: v1 | ||
managed: | ||
enabled: true | ||
go_package_prefix: | ||
default: "example.com" | ||
plugins: | ||
# Use the plugin as a remote plugin. | ||
# NB: ensure BSR registry and version matches. | ||
- plugin: bufbuild.internal/local/multi:v1.0.3 | ||
out: gen | ||
# Set the below options to invoke different commands. | ||
opt: --go_out=. | ||
--go_opt=paths=source_relative | ||
--go-grpc_out=. | ||
--go-grpc_opt=paths=source_relative | ||
--go-vtproto_out=. | ||
--go-vtproto_opt=paths=source_relative,features=marshal+unmarshal+size | ||
--grpc-gateway_out=. | ||
--grpc-gateway_opt=paths=source_relative,generate_unbound_methods=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
version: v1 | ||
name: bufbuild.internal/local/multi # Change me to your BSR plugin repository. | ||
plugin_version: v0.1.0 # Change me to your version. | ||
output_languages: | ||
- go | ||
registry: | ||
# Add the runtime deps required by your plugins for the generated SDK. | ||
go: | ||
deps: | ||
- module: google.golang.org/protobuf | ||
version: v1.32 | ||
- module: google.golang.org/grpc | ||
version: v1.3 | ||
- module: github.com/grpc-ecosystem/grpc-gateway/v2 | ||
version: v2.19 | ||
# Add the options to invoke each plugin for the generated SDK. | ||
opts: | ||
- --go_out=. | ||
- --go_opt=paths=source_relative | ||
- --go-grpc_out=. | ||
- --go-grpc_opt=paths=source_relative | ||
- --go-vtproto_out=. | ||
- --go-vtproto_opt=paths=source_relative,features=marshal+unmarshal+size | ||
- --grpc-gateway_out=. | ||
- --grpc-gateway_opt=paths=source_relative,generate_unbound_methods=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version: v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2023 Buf Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto3"; | ||
|
||
package acme.example; | ||
|
||
message GreetRequest { | ||
string name = 1; | ||
} | ||
message GreetResponse { | ||
string message = 1; | ||
} | ||
|
||
service GreeterServier { | ||
rpc Greet(GreetRequest) returns (GreetResponse); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
cmd/protoc-gen-multi/buf.plugin.yaml → ...protoc-gen-multi/testdata/buf.plugin.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters