-
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 gen-proto and init-proto target and regen protobufv2 clients (dap…
…r#2684) * add init-proto and gen-proto targets to makefile * regen * skip proto * fix test
- Loading branch information
1 parent
b4b4c19
commit f69345a
Showing
35 changed files
with
15,557 additions
and
4,218 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 |
---|---|---|
|
@@ -23,6 +23,8 @@ FORCE_INMEM ?= true | |
# Add latest tag if LATEST_RELEASE is true | ||
LATEST_RELEASE ?= | ||
|
||
PROTOC ?=protoc | ||
|
||
ifdef REL_VERSION | ||
DAPR_VERSION := $(REL_VERSION) | ||
else | ||
|
@@ -234,6 +236,34 @@ lint: | |
modtidy: | ||
go mod tidy | ||
|
||
################################################################################ | ||
# Target: init-proto # | ||
################################################################################ | ||
.PHONY: init-proto | ||
init-proto: | ||
go get google.golang.org/protobuf/cmd/[email protected] google.golang.org/grpc/cmd/[email protected] | ||
|
||
################################################################################ | ||
# Target: gen-proto # | ||
################################################################################ | ||
GRPC_PROTOS:=common internals operator placement runtime sentry | ||
PROTO_PREFIX:=github.com/dapr/dapr | ||
|
||
# Generate archive files for each binary | ||
# $(1): the binary name to be archived | ||
define genProtoc | ||
.PHONY: gen-proto-$(1) | ||
gen-proto-$(1): | ||
$(PROTOC) --go_out=. --go_opt=module=$(PROTO_PREFIX) --go-grpc_out=. --go-grpc_opt=require_unimplemented_servers=false,module=$(PROTO_PREFIX) ./dapr/proto/$(1)/v1/*.proto | ||
endef | ||
|
||
$(foreach ITEM,$(GRPC_PROTOS),$(eval $(call genProtoc,$(ITEM)))) | ||
|
||
GEN_PROTOS:=$(foreach ITEM,$(GRPC_PROTOS),gen-proto-$(ITEM)) | ||
|
||
.PHONY: gen-proto | ||
gen-proto: $(GEN_PROTOS) modtidy | ||
|
||
################################################################################ | ||
# Target: get-components-contrib # | ||
################################################################################ | ||
|
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 |
---|---|---|
|
@@ -11,91 +11,22 @@ | |
|
||
## Proto client generation | ||
|
||
### Prerequsites | ||
1. Install protoc version: [v3.11.0](https://github.com/protocolbuffers/protobuf/releases/tag/v3.11.0) | ||
|
||
Because of [etcd dependency issue](https://github.com/etcd-io/etcd/issues/11563), contributor needs to use the below verisons of tools to generate gRPC protobuf clients. | ||
2. Install protoc-gen-go and protoc-gen-go-grpc | ||
|
||
* protoc version: [v3.11.0](https://github.com/protocolbuffers/protobuf/releases/tag/v3.11.0) | ||
* protobuf protoc-gen-go: [v1.3.2](https://github.com/golang/protobuf/releases/tag/v1.3.2) | ||
* gRPC version: [v1.26.0](https://github.com/grpc/grpc-go/releases/tag/v1.26.0) | ||
|
||
### Getting the correct versions of tools | ||
|
||
If you have the versions above, you can skip this section. | ||
|
||
#### protoc | ||
|
||
Click the link above, download the appropriate file for your OS and unzip it in a location of your choice. You can add this to your path if you choose. If you don't, you'll have to use the full path later. | ||
|
||
|
||
#### protoc-gen-go/grpc-go | ||
|
||
To get the version listed above (1.3.2): | ||
|
||
``` | ||
cd ~/go/src | ||
mkdir temp | ||
cd temp | ||
go mod init | ||
go get -d -v github.com/golang/[email protected] | ||
``` | ||
|
||
Open go.mod and add this line to the end to add the specific version grpc required, including the comment: | ||
|
||
``` | ||
require google.golang.org/grpc v1.26.0 // indirect | ||
``` | ||
|
||
go.mod should now look like this: | ||
|
||
``` | ||
module temp | ||
go 1.14 | ||
require github.com/golang/protobuf v1.3.2 // indirect | ||
require google.golang.org/grpc v1.26.0 // indirect | ||
``` | ||
|
||
Now build: | ||
|
||
``` | ||
go build github.com/golang/protobuf/protoc-gen-go | ||
``` | ||
|
||
The binary will be put in current directory. | ||
|
||
Copy the binary to your go bin (e.g. ~/go/bin) or some preferred location. Add that location to your path. | ||
|
||
Now generate the protobufs. For this example assume you have a change in `dapr/dapr/proto/runtime/v1/dapr.proto` and want to generate from that: | ||
|
||
``` | ||
protoc -I . ./dapr/proto/runtime/v1/*.proto --go_out=plugins=grpc:../../../ | ||
```bash | ||
make init-proto | ||
``` | ||
|
||
> Note if you didn't add protoc to your path above, you'll have to use the full path. | ||
The output will be `*pb.go` files in a file hierarchy starting 3 dirs above the current directory. Find the `*pb.go` files and diff them with the current `dapr/dapr/pkg/proto/runtime/v1/dapr.pb.go`. Assuming you have a small change (e.g. adding a field to a struct), the diff should be relatively small, less than 10 lines, other than to the file descriptor which will look like an array of bytes. If the size of the diff is much larger than that, the version of tools you're using likely does not match the ones above. | ||
|
||
Finally, copy the generated pb.go files over the corresponding ones in the dapr/dapr repo. In this case, that is `dapr/dapr/pkg/proto/runtime/v1/dapr.pb.go`. | ||
3. Generate gRPC proto clients | ||
|
||
Repeat for each modified `.proto`. | ||
|
||
### Generate go clients | ||
|
||
> TODO: move the commands to makefile | ||
To generate all protobufs: | ||
|
||
```bash | ||
protoc -I . ./dapr/proto/operator/v1/*.proto --go_out=plugins=grpc:../../../ | ||
protoc -I . ./dapr/proto/placement/v1/*.proto --go_out=plugins=grpc:../../../ | ||
protoc -I . ./dapr/proto/sentry/v1/*.proto --go_out=plugins=grpc:../../../ | ||
protoc -I . ./dapr/proto/common/v1/*.proto --go_out=plugins=grpc:../../../ | ||
protoc -I . ./dapr/proto/runtime/v1/*.proto --go_out=plugins=grpc:../../../ | ||
protoc -I . ./dapr/proto/internals/v1/*.proto --go_out=plugins=grpc:../../../ | ||
make gen-proto | ||
``` | ||
|
||
|
||
## Update e2e test apps | ||
Whenever there are breaking changes in the proto files, we need to update the e2e test apps to use the correct version of dapr dependencies. This can be done by navigating to the tests folder and running the commands:- | ||
|
||
|
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
Oops, something went wrong.