A python microservice framework
Overview
Quick start
Project files
OpenAPI specification
API objects
Server code
Deployment pipeline
Docker packaging
JWT authentication
Configuration
Error handling
Asynchronous execution
Database serialisation
Testing
Monitoring
Google Cloud Run is a fully managed serverless platform for running your containers. You can easily deploy PyMacaron microservices to Cloud Run using the pymacaron-gcp.
Note that Google Cloud Run only supports microservices that have no activity outside request handling. See ‘Avoiding background activities’.
Therefore PyMacaron’s async task implementation based on Celery/Redis will not work with Cloud Run.
Cloud Run services have both there HTTP and HTTPS ports exposed. It’s the developer’s responsibility to actively redirect all HTTP requests to HTTPS.
When deploying to Cloud Run, ‘pymdeploy’ goes through the following specific deployment steps:
Deploy the docker image as a new revision to a google Cloud Run project whose name is the service’s name suffixed with ‘-staging’.
Run the acceptance tests against that staging environment. Stop if tests fail.
Re-deploy the docker image as a new revision to a google Cloud Run project whose name is the service’s name suffixed with ‘-live’.
‘pymgcp’ sets up the Google Run service based on the parameters defined in ‘pym-config.yaml’. It is however up to you to map the live environment to a custom domain of your choice.
You will need to have:
Installed the google SDK.
Run ‘gcloud init’
Run ‘gcloud auth configure-docker’
Installed ‘pymacaron-gcp’: pip install pymacaron-gcp
To be able to deploy against Cloud Run, the following key-values must be present in your project’s pym-config.yaml:
docker_repo: <PROJECT_ID> # The ID of your gcp project
deploy_target: gcp-cloud-run
gcp_region: europe-west1 # Set to the gcp region your service should be deployed to
gcp_memory: 1G # Max memory granted to one container
gcp_request_concurrency: 8 # Number of concurrent requests a container may handled before
# triggering autoscaling
See here for details on ‘pym-config.yaml’.