Skip to content

crosleythomas/python-grpc

Repository files navigation

python-grpc

Test, Build, Publish

Template for deploying Python gRPC services

Goal

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

One-Time Setup

  1. Google Cloud Platform
    1. Create an account
    2. Create a Project
    3. Set up a billing account
    4. Create an IAM role with the permissions Service Account User, Cloud Run Admin, Storage Admin
  2. Local Setup
    1. Install gRPC tools

New-Service Setup

  1. Fork this repo
  2. Set a Secret value named GCLOUD_AUTH with a value from step 1.

Implementation

  1. Add input/output/function protobuf definitions here
  2. 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=.`
  3. Implement your function logic here
  4. Add in additional dependencies in the Dockerfile or requirements.txt
  5. Test your changes locally
    1. python sample_server.py
    2. python sample_client.py
  6. 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
    • Call setup script with ___, ___, ..., ___
    • Define input/output protobuf messages
    • Define function
    • Define any additional dependencies in requirements.txt or Dockerfile
  • 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

About

Template for deploying Python gRPC services

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages