Skip to content

Commit

Permalink
feat: generate grpc protos in namely/protoc-all image (#1187)
Browse files Browse the repository at this point in the history
* feat: generate manager protoc

Signed-off-by: Gaius <[email protected]>

* chore: makefile add protoc command

Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi committed Jun 28, 2023
1 parent 1320018 commit 998110f
Show file tree
Hide file tree
Showing 14 changed files with 1,396 additions and 1,276 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ generate:
@go generate ${PKG_LIST}
.PHONY: generate

# Generate grpc protos
protoc:
@./hack/protoc.sh
.PHONY: protoc

# Generate swagger files
swag:
@swag init --parseDependency --parseInternal -g cmd/manager/main.go -o api/manager
Expand Down Expand Up @@ -343,7 +348,8 @@ help:
@echo "make kind-load-testing-tools kind load testing tools docker image"
@echo "make lint run code lint"
@echo "make markdownlint run markdown lint"
@echo "make generate run go generate"
@echo "make protoc generate grpc protos"
@echo "make swag generate swagger api docs"
@echo "make changelog generate CHANGELOG.md"
@echo "make generate run go generate"
@echo "make clean clean"
38 changes: 17 additions & 21 deletions hack/protoc.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
#!/bin/bash

SRC="$(cd "$(dirname "$0")/.." && pwd)"
PROTOC_ALL_IMAGE=${PROTOC_ALL_IMAGE:-"namely/protoc-all:1.42_1"}
PROTO_PATH=pkg/rpc
LANGUAGE=go

echo "work dir:$SRC"
if protoc -I="$SRC" \
-I $GOPATH/pkg/mod/github.com/envoyproxy/[email protected] \
--go_out "$SRC" --go_opt paths=source_relative \
--go-grpc_out "$SRC" --go-grpc_opt paths=source_relative \
--validate_out "lang=go,paths=source_relative:$SRC" \
"$SRC"/pkg/rpc/base/*.proto \
"$SRC"/pkg/rpc/cdnsystem/*.proto \
"$SRC"/pkg/rpc/dfdaemon/*.proto \
"$SRC"/pkg/rpc/scheduler/*.proto \
"$SRC"/pkg/rpc/manager/*.proto; then
echo "generate grpc code success"
# warning messages about symlinks, fix in golang 1.17
# https://github.com/golang/go/issues/35941
if cd "$SRC" && go mod tidy; then
echo "go mod tidy success"
proto_modules="base cdnsystem dfdaemon manager scheduler"

echo "generate protos..."

for module in ${proto_modules}; do
if docker run -v $PWD:/defs ${PROTOC_ALL_IMAGE} \
-d ${PROTO_PATH}/$module -i . \
-l ${LANGUAGE} -o . \
--go-source-relative \
--with-validator \
--validator-source-relative; then
echo "generate protos ${module} successfully"
else
echo "go mod tidy fail"
echo "generate protos ${module} failed"
fi
else
echo "generate grpc code fail"
fi
done
2 changes: 1 addition & 1 deletion pkg/rpc/base/base.pb.go

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

224 changes: 223 additions & 1 deletion pkg/rpc/cdnsystem/cdnsystem.pb.go

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

Loading

0 comments on commit 998110f

Please sign in to comment.