Skip to content

Commit

Permalink
Use remote plugins, migrate config files (grpc-ecosystem#2347)
Browse files Browse the repository at this point in the history
* Upgrade buf version, use remote plugins

Removes the need to depend on protoc-gen-go
and protoc-gen-go-grpc

* Migrate to v1 of buf.gen.yaml

* Migrate buf.yaml to v1

* Update CONTRIBUTING.md references

* Regenerate files with latest buf
  • Loading branch information
johanbrandhorst authored Sep 25, 2021
1 parent cc31c42 commit bb2225c
Show file tree
Hide file tree
Showing 36 changed files with 806 additions and 819 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ All submissions, including submissions by project members, require review.
It should be as simple as this (run from the root of the repository):

```bash
docker run -v $(pwd):/grpc-gateway -w /grpc-gateway --rm ghcr.io/grpc-ecosystem/grpc-gateway/build-env:1.16 \
docker run -v $(pwd):/grpc-gateway -w /grpc-gateway --rm ghcr.io/grpc-ecosystem/grpc-gateway/build-env:1.17 \
/bin/bash -c 'make install && \
make clean && \
make generate'
Expand All @@ -22,7 +22,7 @@ docker run -itv $(pwd):/grpc-gateway -w /grpc-gateway --entrypoint /bin/bash --r
bazel run :buildifier'
```

You may need to authenticate with GitHub to pull `docker.pkg.github.com/grpc-ecosystem/grpc-gateway/build-env`.
You may need to authenticate with GitHub to pull `ghcr.io/grpc-ecosystem/grpc-gateway/build-env`.
You can do this by following the steps on the [GitHub Package docs](https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-docker-for-use-with-github-packages#authenticating-to-github-packages).

### Using Visual Studio Code dev containers
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ $(GENERATE_UNBOUND_METHODS_EXAMPLE_SRCS): $(GENERATE_UNBOUND_METHODS_EXAMPLE_SPE
$(EXAMPLE_CLIENT_DIR)/generateunboundmethods/git_push.sh

install:
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
go install github.com/bufbuild/buf/cmd/buf@v0.51.1

go install github.com/bufbuild/buf/cmd/buf@v1.0.0-rc2
go install \
./protoc-gen-openapiv2 \
./protoc-gen-grpc-gateway
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Alternatively, see the section on remotely managed plugin versions below.
Here's an example `buf.gen.yaml` you can use to generate the stubs with [buf](https://github.com/bufbuild/buf):

```yaml
version: v1beta1
version: v1
plugins:
- name: go
out: gen/go
Expand Down Expand Up @@ -174,7 +174,7 @@ Alternatively, see the section on remotely managed plugin versions below.
Here's what a `buf.gen.yaml` file might look like with this option enabled:

```yaml
version: v1beta1
version: v1
plugins:
- name: go
out: gen/go
Expand Down Expand Up @@ -235,7 +235,7 @@ Alternatively, see the section on remotely managed plugin versions below.
> be added to the `deps` array in your `buf.yaml` under the name
> `buf.build/googleapis/googleapis`:
> ```yaml
> version: v1beta1
> version: v1
> name: buf.build/yourorg/myprotos
> deps:
> - buf.build/googleapis/googleapis
Expand All @@ -249,7 +249,7 @@ Alternatively, see the section on remotely managed plugin versions below.
Here's what a `buf.gen.yaml` file might look like:

```yaml
version: v1beta1
version: v1
plugins:
- name: go
out: gen/go
Expand Down Expand Up @@ -299,7 +299,7 @@ Alternatively, see the section on remotely managed plugin versions below.
Here's what a `buf.gen.yaml` file might look like with this option enabled:

```yaml
version: v1beta1
version: v1
plugins:
- name: go
out: gen/go
Expand Down Expand Up @@ -384,7 +384,7 @@ Alternatively, see the section on remotely managed plugin versions below.
Here's what a `buf.gen.yaml` file might look like:

```yaml
version: v1beta1
version: v1
plugins:
- name: go
out: gen/go
Expand All @@ -407,7 +407,7 @@ Alternatively, see the section on remotely managed plugin versions below.
`buf`, you can add the `buf.build/grpc-ecosystem/grpc-gateway` dependency
to your `deps` array:
```yaml
version: v1beta1
version: v1
name: buf.build/yourorg/myprotos
deps:
- buf.build/googleapis/googleapis
Expand Down Expand Up @@ -480,7 +480,7 @@ When using `buf` to generate stubs, flags and parameters are passed through
the `opt` field in your `buf.gen.yaml` file, for example:

```yaml
version: v1beta1
version: v1
plugins:
- name: grpc-gateway
out: gen/go
Expand Down
6 changes: 3 additions & 3 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
version: v1beta1
version: v1
plugins:
- name: go
- remote: buf.build/library/plugins/go:v1.27.1-1
out: .
opt:
- paths=source_relative
- name: go-grpc
- remote: buf.build/library/plugins/go-grpc:v1.1.0-2
out: .
opt:
- paths=source_relative
Expand Down
10 changes: 4 additions & 6 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
version: v1beta1
version: v1
name: buf.build/grpc-ecosystem/grpc-gateway
deps:
- buf.build/googleapis/googleapis
build:
roots:
- .
excludes:
- bazel-grpc-gateway
breaking:
use:
- FILE
lint:
use:
- DEFAULT
Expand Down Expand Up @@ -164,6 +165,3 @@ lint:
- examples/internal/proto/examplepb/flow_combination.proto
- examples/internal/proto/examplepb/openapi_merge_a.proto
- examples/internal/proto/examplepb/openapi_merge_b.proto
breaking:
use:
- FILE
7 changes: 2 additions & 5 deletions docs/docs/tutorials/adding_annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Now that we've got the gRPC-Gateway annotations added to the proto file, we need
We'll need to add the gRPC-Gateway generator to the generation configuration:

```yaml
version: v1beta1
version: v1
plugins:
- name: go
out: proto
Expand All @@ -69,13 +69,10 @@ plugins:
We'll also need to add the `googleapis` dependency to our `buf.yaml` file:

```yaml
version: v1beta1
version: v1
name: buf.build/myuser/myrepo
deps:
- buf.build/googleapis/googleapis
build:
roots:
- proto
```

Then we need to run `buf mod update` to select a version of the dependency to use.
Expand Down
15 changes: 5 additions & 10 deletions docs/docs/tutorials/generating_stubs/using_buf.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@ grand_parent: Tutorials

[Buf](https://github.com/bufbuild/buf) is a tool that provides various protobuf utilities such as linting, breaking change detection and generation. Please find installation instructions on [https://docs.buf.build/installation/](https://docs.buf.build/installation/).

It is configured through a `buf.yaml` file that should be checked in to the root of your repository. Buf will automatically read this file if present. Configuration can also be provided via the command-line flag `--config`, which accepts a path to a `.json` or `.yaml` file, or direct JSON or YAML data.
It is configured through a `buf.yaml` file that should be checked in to the root of your Protobuf file hierarchy. Buf will automatically read this file if present. Configuration can also be provided via the command-line flag `--config`, which accepts a path to a `.json` or `.yaml` file, or direct JSON or YAML data. As opposed to `protoc`, where all `.proto` files are manually specified on the command-line, buf operates by recursively discovering all `.proto` files under configuration and building them.

All Buf operations that use your local `.proto` files as input rely on a valid build configuration. This configuration tells Buf where to search for `.proto` files, and how to handle imports. As opposed to `protoc`, where all `.proto` files are manually specified on the command-line, buf operates by recursively discovering all `.proto` files under configuration and building them.

The following is an example of a valid configuration, assuming you have your `.proto` files rooted in the `proto` folder relative to the root of your repository.
The following is an example of a valid configuration, and you would put it in the root of your Protobuf file hierarchy, e.g. in `proto/buf.yaml` relative to the root of your repository.

```yaml
version: v1beta1
version: v1
name: buf.build/myuser/myrepo
build:
roots:
- proto
```
To generate type and gRPC stubs for Go, create the file `buf.gen.yaml` at the root of the repository:
To generate type and gRPC stubs for Go, create the file `buf.gen.yaml`:

```yaml
version: v1beta1
version: v1
plugins:
- name: go
out: proto
Expand Down
38 changes: 19 additions & 19 deletions examples/internal/helloworld/helloworld.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bb2225c

Please sign in to comment.