diff --git a/Makefile b/Makefile index 18354ae2e..5c9dc25ed 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,44 @@ +######################################################## +######################################################## +######################################################## +######################################################## + +# Scripts Related to developing Blobber + +######################################################## +######################################################## +######################################################## +######################################################## + + +.PHONY: test +test: + go test ./...; + +.PHONY: lint +lint: + golangci-lint run --timeout 2m0s; + +.PHONY: integration-tests +integration-tests: + sudo go test ./... -args integration; + + + + +######################################################## +######################################################## +######################################################## +######################################################## + +# Scripts related to setting up Buf + +######################################################## +######################################################## +######################################################## +######################################################## + + SHELL := /usr/bin/env bash -o pipefail # This controls the location of the cache. @@ -116,14 +157,3 @@ else sed -i "s/BUF_VERSION := [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/BUF_VERSION := $(VERSION)/g" Makefile endif endif - -.PHONY: test lint integration-tests - -test: - go test ./...; - -lint: - golangci-lint run --timeout 2m0s; - -integration-tests: - sudo go test ./... -args integration; diff --git a/code/go/0chain.net/blobbercore/blobbergrpc/README.md b/code/go/0chain.net/blobbercore/blobbergrpc/README.md index 5ac239d6a..93a50a7ab 100644 --- a/code/go/0chain.net/blobbercore/blobbergrpc/README.md +++ b/code/go/0chain.net/blobbercore/blobbergrpc/README.md @@ -1,17 +1,15 @@ # GRPC Endpoints -## Development - -Modify the '.proto' file in `code/go/0chain.net/blobbercore/blobbergrpc/proto/blobber.proto` and run -`scripts/generate-grpc.sh` to add new api's. - -GRPC API is implemented in `code/go/0chain.net/blobbercore/handler/grpc_handler.go`. - -## Installation - -Install the [protoc](https://grpc.io/docs/protoc-installation/) command line interface. +We are using Buf, which is building a better way to work with Protocol Buffers. Buf supports +linting & detecting breaking changes for our gRPC protos as well as generating the gRPC stubs. +### Pre-Requisites +- Setup [Buf](https://buf.build) tool on local, run +```sh +make deps ``` +- Installation of required go-deps for gRPC, run +```sh go install \ github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway \ github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 \ @@ -19,14 +17,13 @@ google.golang.org/protobuf/cmd/protoc-gen-go \ google.golang.org/grpc/cmd/protoc-gen-go-grpc ``` -Run this command to install all the GRPC related binaries required to generate GRPC related files using `protoc` CLI. +## Development -Now you can run the script in `scripts/generate-grpc.sh`. +- All the protos present in the project can be found by `buf ls-files`. -## Plugins +- Generation of stubs on local can be done by ` buf generate -o ./code/go/0chain.net/blobbercore/blobbergrpc/` -* [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway) -plugin is being used to expose a REST api for grpc incompatible clients. +- Buf is also capable of linting the protos according to the best practices of the gRPC `buf lint` ## Testing @@ -36,12 +33,10 @@ to use docker network ip and not localhost. Make sure the server is running on `--deployment_mode 0` to use server reflection. -You can use https://github.com/vektra/mockery to generate mocks for tests. - ## Documentation -Basic documentation can be found here - https://grpc.io/docs/languages/go/basics/. +The basic documentation can be found here - https://grpc.io/docs/languages/go/basics/. -Advanced documentation can be found here - https://github.com/grpc/grpc-go/tree/master/Documentation. +The advanced documentation can be found here - https://github.com/grpc/grpc-go/tree/master/Documentation. diff --git a/scripts/generate-grpc.sh b/scripts/generate-grpc.sh deleted file mode 100755 index c03fa71a1..000000000 --- a/scripts/generate-grpc.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -protoc -I ./code/go/0chain.net/blobbercore/blobbergrpc/proto --go-grpc_out=. --go_out=. --grpc-gateway_out=allow_delete_body=true:. --openapiv2_opt allow_delete_body=true --openapiv2_out=./code/go/0chain.net/blobbercore/openapi ./code/go/0chain.net/blobbercore/blobbergrpc/proto/blobber.proto \ No newline at end of file