Skip to content

FastAPI on Cloud Run v2: Terraform setup, GitHub Actions CI, Cloud Build triggers, Secret Manager integration

Notifications You must be signed in to change notification settings

mazzasaverio/fastapi-cloudrun-starter

Repository files navigation

FastAPI CloudRun Starter

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.

Features

  • Terraform-based infrastructure setup.
  • Integration with GitHub Actions for continuous integration.
  • Automatic trigger setup for Cloud Build.
  • Secure storage of secrets using Secret Manager.

Getting Started

Prerequisites

  1. Google Cloud Platform Account: Ensure you have an active GCP account. Sign up here if needed.
  2. Project Setup: Create a new GCP project and note down the project ID.
  3. Service Account: Create a service account with 'Owner' permissions in your GCP project and generate a JSON key file.
  4. Connecting Cloud Build to Your GitHub Account: Create a personal access token in GitHub with repo and read:user permissions. For organization apps, include read:org permission. Guide here.

Terraform Configuration

  • Rename File: Rename terraform.tfvars.example to terraform.tfvars.
  • Insert Credentials: Fill in your credentials in the terraform.tfvars file.

Docker Configuration

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.

FastAPI Application

The main.py script is the entry point for the FastAPI application. It includes basic routes and can be extended for additional functionality.

Usage

To deploy the infrastructure and application:

  1. Initialize Terraform:
    terraform init
  2. Apply Terraform configuration:
    terraform apply
  3. To build and run the Docker container locally, use:
    docker-compose up --build

Contributing

Contributions to enhance this starter template are welcome. Please follow standard GitHub contribution guidelines.

About

FastAPI on Cloud Run v2: Terraform setup, GitHub Actions CI, Cloud Build triggers, Secret Manager integration

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published