Providers a backend for Goravel Market. In facilitate deployment and testing, we put all microservices in this project.
We are using the Github action to deploy the Staging environment. The action will build a docker image and deploy it to the Staging server automatically when you create a new tag in the repository.
There is a rule when you create a new tag, the name should consist of the service name and version, for example:
gateway-0.0.1
, the gateway
is the folder name of src/go/gateway
.
Once you create a new tag, please check the deployment process here, to ensure the deployment is successful.
You can also deploy the staging environment manually, open this page
and click the Run workflow
button, then select the branch, environment and tag.
- Create a new project in the
src/go
folder, the folder name should be the service name; - Configure deploy parameters in the deploy/config.yml file;
- Create the docker running command in the
deploy
folder:deploy/{SERVICE_NAME}/deploy.sh
, add the environment variables according to the.env
file; - Optimize the
Dockerfile
in thesrc/go/{SERVICE_NAME}
folder; - Add the environment variables to Github secrets, such as:
PACKAGE_APP_KEY
; - Add the environment variables to the
.github/workflows/deploy.yml
file; - If the new service providers external GRPC endpoints, add the GRPC host and port to
deploy/gateway/deploy.sh
; - create a new tag in Github to test the service is deployed successfully;
- A reference PR;
- A request from the client;
- Nginx forward to gateway;
- The HTTP server of gateway;
- (If JWT token exists)Parse User information through UserService;
- (If JWT token exists)Append
user_id
,user_name
to the request queries; - The request forward to the corresponding HTTP interface that define in proto files(through [goravel/gateway] (https://github.com/goravel/gateway));
- The HTTP interface forward to the corresponding GRPC interface(through grpc-ecosystem/grpc-gateway);
Based on the request process, we can get some key points:
- All proto files are defined in the proto folder, and the GRPC endpoints that expose to the outside need to
contain the
google.api.http
annotation, for example:option (google.api.http) = {get: "/v1/user"}
; - We need to define a corresponding HTTP routing based on the annotation in step 1, and all HTTP routing is defined in the route folder of gateway;
- All microservices only need to define the GRPC endpoints, and the gateway will automatically generate the HTTP routing to the corresponding GRPC endpoint;
- If you want to get the current login user information in a microservice, you can add
string user_id = 1
,string user_name = 2
to your GRPC request, the fields will be filled by gateway automatically;
- mockery@v2.42.1: Generate mock files for testing.
- check the version by
mockery --version
- check the version by
- protoc@libprotoc 25.1: Generate proto files.
- check the version by
protoc --version
- check the version by
- protoc-gen-go@v1.33.0: Generate go files from proto files.
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.33.0
- check the version by
protoc-gen-go --version
- protoc-gen-go-grpc@1.3.0: Generate go grpc files from proto
files.
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0
- check the version by
protoc-gen-go-grpc --version
- protoc-gen-grpc-gateway@v2.19.1: Generate grpc gateway files from proto files.
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.19.1
- check the version by
protoc-gen-grpc-gateway --version
, but it will print:Version dev, commit unknown, built at unknown
- protoc-gen-doc@v1.5.1: Generate documentation from proto files.
go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@v1.5.1
- check the version by
protoc-gen-doc --version