Template for deploying Python gRPC services
Develop a template repository that can be cloned, updated with a single function, and seamlessly deployed to a cloud provider.
There will be some one-time setup to set up of an account with a cloud hosting provider, but after that is set up, deploying new gRPC functions should be as frictionless as possible.
To Do:
- Make workflow read from Github project name (and other meta-data?) to populate different things
- Make the server and clients re-usable - importing the generated clients
- See if we can automate some of the one-time setup via git hooks
- Google Cloud Platform
- Create an account
- Create a
Project - Set up a billing account
- Create an IAM role with the permissions Service Account User, Cloud Run Admin, Storage Admin
- Local Setup
- Fork this repo
- Set a Secret value named
GCLOUD_AUTHwith a value from step 1.
- Add input/output/function protobuf definitions here
- Run the gRPC code generator, python -m grpc_tools.protoc -I protos/ --python_out=protos --grpc_python_out=protos --proto_path protos/ sample.proto --proto_path=.`
- Implement your function logic here
- Add in additional dependencies in the Dockerfile or requirements.txt
- Test your changes locally
python sample_server.pypython sample_client.py
- Push your changes and check the build here
Steps:
- Use grpc/python Docker image for portability
- Figure out how to templatize a python function being loaded into the Docker image as a gRPC service
- Set up the Github Actions that will deploy these gRPC services
- Document the one-off setup steps that will need to be performed each time this repo is cloned
- GCP Account setup
- Enable Billing
- Create a Project
- Docker Registry Enable the Container Registry API
- Configure Docker to use gcloud
gcloud auth configure-docker - Cloud Run
- Call setup script with ___, ___, ..., ___
- Define input/output protobuf messages
- Define function
- Define any additional dependencies in
requirements.txtorDockerfile
- GCP Account setup
- Put as many of these setup steps into a script
https://github.com/marketplace/actions/cloud-run https://cloud.google.com/blog/products/compute/serve-cloud-run-requests-with-grpc-not-just-http https://github.com/fullstorydev/grpcurl