This repository serves as a starter template for setting up a FastAPI backend using Google CloudRun. It's designed to streamline the process of deploying a FastAPI application using modern infrastructure as code principles.
- Terraform-based infrastructure setup.
- Integration with GitHub Actions for continuous integration.
- Automatic trigger setup for Cloud Build.
- Secure storage of secrets using Secret Manager.
- Google Cloud Platform Account: Ensure you have an active GCP account. Sign up here if needed.
- Project Setup: Create a new GCP project and note down the project ID.
- Service Account: Create a service account with 'Owner' permissions in your GCP project and generate a JSON key file.
- Connecting Cloud Build to Your GitHub Account: Create a personal access token in GitHub with
repo
andread:user
permissions. For organization apps, includeread:org
permission. Guide here.
- Rename File: Rename
terraform.tfvars.example
toterraform.tfvars
. - Insert Credentials: Fill in your credentials in the
terraform.tfvars
file.
The Dockerfile
is configured to use the NVIDIA CUDA base image with FastAPI dependencies. The application is exposed on port 8000 and can be customized as needed.
The main.py
script is the entry point for the FastAPI application. It includes basic routes and can be extended for additional functionality.
To deploy the infrastructure and application:
- Initialize Terraform:
terraform init
- Apply Terraform configuration:
terraform apply
- To build and run the Docker container locally, use:
docker-compose up --build
Contributions to enhance this starter template are welcome. Please follow standard GitHub contribution guidelines.