Switch to buf for protobuf generation (#1944)

* Install buf with go install

This reduces the impact of using buf on our dependency
closure, which was significant. It also avoids potential
issues with building buf given our own internal dependency
constraints. This has caused issues (including crashes!)
in the past.

See https://github.com/cockroachdb/cockroach/issues/67216#issuecomment-874176186
for more discussion on using tool dependencies generally, and
https://github.com/bufbuild/buf/issues/52
for an example of where this sort of thing caused an issue for a user.

* Upgrade buf version

We should migrate to v1 sooner rather than later, as it has some
breaking changes from v0.

* Change buf lint/breaking commands

These commands were moved up one level for v1

* Migrate to buf.yaml to v1

* Remove unused imports

These were uncovered by using "buf lint".

* Use buf v1.3.1

* Depend on googleapis and grpc-gateway via BSR

* Switch to buf for proto generation

* Remove third party dependency

* Remove unused tools and scripts

* Move local protos up one level

* Temporarily don't fail on breaking changes

* Generate CI config

* Fix generation of controller.json

* Replace use of deprecated flag

* Remove unused import, regenerate files

* Remove temporary skipping over breaking check
This commit is contained in:
Johan Brandhorst-Satzkorn authored and GitHub committed 2022-04-04 13:55:42 -04:00
1 parent 58a448fc6a
commit b1d6a1da9a
194 files changed
+1130 -2411

No files matched your search

+7 -22
View File
@@ -21,6 +21,7 @@ cli:
.PHONY: tools
tools:
go generate -tags tools tools/tools.go
go install github.com/bufbuild/buf/cmd/buf@v1.3.1
.PHONY: cleangen
cleangen:
@@ -107,28 +108,13 @@ proto: protolint protobuild
.PHONY: protobuild
protobuild:
# To add a new directory containing a proto pass the proto's root path in
# through the --proto_path flag.
@bash scripts/protoc_gen_plugin.bash \
"--proto_path=internal/proto/local" \
"--proto_include_path=internal/proto/third_party" \
"--plugin_name=go" \
"--plugin_out=${TMP_DIR}"
@bash scripts/protoc_gen_plugin.bash \
"--proto_path=internal/proto/local" \
"--proto_include_path=internal/proto/third_party" \
"--plugin_name=go-grpc" \
"--plugin_out=${TMP_DIR}"
@bash scripts/protoc_gen_plugin.bash \
"--proto_path=internal/proto/local/" \
"--proto_include_path=internal/proto/third_party" \
"--plugin_name=grpc-gateway" \
"--plugin_out=logtostderr=true:${TMP_DIR}"
@buf generate -o "${TMP_DIR}"
# Move the generated files from the tmp file subdirectories into the current repo.
cp -R ${TMP_DIR}/${REPO_PATH}/* ${THIS_DIR}
@protoc --proto_path=internal/proto/local --proto_path=internal/proto/third_party --openapiv2_out=json_names_for_fields=false,logtostderr=true,disable_default_errors=true,include_package_in_tags=true,fqn_for_openapi_name=true,allow_merge,merge_file_name=controller:internal/gen/. internal/proto/local/controller/api/services/v1/*.proto
@buf generate --template buf.openapiv2.gen.yaml --path internal/proto/controller/api/services/v1/
@protoc-go-inject-tag -input=./internal/oplog/store/oplog.pb.go
@protoc-go-inject-tag -input=./internal/oplog/oplog_test/oplog_test.pb.go
@protoc-go-inject-tag -input=./internal/iam/store/group_member.pb.go
@@ -173,15 +159,14 @@ protobuild:
# these protos, services and openapi artifacts are purely for testing purposes
@protoc-go-inject-tag -input=./internal/gen/testing/event/event.pb.go
@protoc --proto_path=internal/proto/local --proto_path=internal/proto/third_party --openapiv2_out=json_names_for_fields=false,logtostderr=true,disable_default_errors=true,include_package_in_tags=true,fqn_for_openapi_name=true,allow_merge,merge_file_name=testing:internal/gen/testing/event/. internal/proto/local/testing/event/v1/*.proto
@buf generate --template buf.testing.gen.yaml --path internal/proto/testing/event/v1/
@rm -R ${TMP_DIR}
.PHONY: protolint
protolint:
@buf check lint
@buf check breaking --against 'https://github.com/hashicorp/boundary.git#branch=stable-website'
@buf lint
@buf breaking --against 'https://github.com/hashicorp/boundary.git#branch=stable-website'
.PHONY: website
# must have nodejs and npm installed