Template for running FastAPI on Google Cloud Run with GitHub Actions for testing and CICD.
For all documentation visit the docs folder.
Pull requests and issues are very welcome!
FastAPI on Google Cloud Run
License: MIT License
Template for running FastAPI on Google Cloud Run with GitHub Actions for testing and CICD.
For all documentation visit the docs folder.
Pull requests and issues are very welcome!
SendGrid is a great choice for sending emails and managing the analytics around them. Checkout their free tier, https://sendgrid.com/free, to get started. In order to send emails, you will have to verify your sending authentication. You can set that up here https://app.sendgrid.com/settings/sender_auth.
In this sample, we'll place all templates in the assets/templates/
directory, located in the project root.
Sample provided from SendGrid:
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
message = Mail(
from_email='[email protected]',
to_emails='[email protected]',
subject='Sending with Twilio SendGrid is Fun',
html_content='<strong>and easy to do anywhere, even with Python</strong>')
try:
sg = SendGridAPIClient(api_key=<YOUR_API_KEY>)
response = sg.send(message=message)
print(response.status_code)
print(response.body)
print(response.headers)
except Exception as e:
print(e)
print(e.body)
Hi,
First, thank you a lot for this template. I'm new to the API world and trying to deploy my own one on GCP. But first I'm developing locally. But I'm struggling using the local db.
I first run postgres on a container locally with docker run --rm --name pg-docker -e POSTGRES_DB=postgres_test_db -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres:12.3-alpine
Then if I run PYTHONPATH=. alembic revision --autogenerate -m "initial setup"
, I have the following error message:
...
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
In config.py
I have url = 'postgresql+psycopg2://postgres:postgres@localhost/postgres_test_db'
.
Is there any documentation that could help me?
I'm running everything on Ubuntu (20.04), use vscode and poetry. If I run psql -U postgres -h localhost
it connects to the database as expected.
When deploying to Cloud Run, this error triggered: ModuleNotFoundError: No module named python container tests
.
tests/
was indeed added to .dockerignore
Add authorization example
See gcloud reference: https://cloud.google.com/sdk/gcloud/reference/scheduler
Hi!
When I'm connecting to my cloud SQL instance with psql "sslmode=disable host=/tmp/cloudsql/PROJECT_ID:REGION:INSTANCE_NAME user=postgres dbname=postgres"
, it works well but when using:
cloud_sql_proxy -instances=PROJECT_ID:REGION:INSTANCE_NAME -dir=/tmp/cloudsql
And then doing:
PYTHONPATH=. alembic revision --autogenerate -m "initial setup"
I have the error:
...
sqlalchemy.exc.ArgumentError: Could not parse rfc1738 URL from string 'PROJECT_ID:REGION:INSTANCE_NAME'
(PROJECT_ID:REGION:INSTANCE_NAME being my own instance)
Any idea or documentation to solve this issue?
Hi,
FastAPI docs say that when running in a system that manages distributed containers (e.g. K8s) it is better to run a single Uvicorn process.
See here: https://fastapi.tiangolo.com/deployment/docker/#replication-number-of-processes
I believe Cloud Run falls under that group of systems that manage container clusters, load balancing, etc'...
So the question is, why use Gunicron to manage the workload?
WDYT?
Hi! Thanks for this repo.
Quick q, I am able to view docs on the raw cloud run domain, but I am using a custom domain mapping so all my services are reachable at customdomain.com/{service-name}
, this works fine for all uses apart from the docs are not available at customdomain.com/{service-name}/docs
Any idea why that could be the case?
Hey,
thanks for the project and your work. I have a question about the Gunicorn config. The official Cloud Run tutorial for Python applications (in this case Flask and not async) states that this config should be used:
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
I understand that this might not be the best config for FastAPI applications but they explicitly say that "Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling."
So is there a reason to use your timeout value of 60 instead of the recommended one?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.