avatarSaverio Mazza

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1464

Abstract

n ensures that every code commit goes through a standardized testing process, enhancing code quality and reliability.</p><h1 id="1cf2">Automated Cloud Build Triggers</h1><p id="97b8">Google Cloud Build is utilized for automated building, testing, and deploying. The starter template sets up triggers that automatically initiate Cloud Build processes upon code changes, ensuring that the latest version of the application is always ready for deployment.</p><h1 id="0640">Secure Storage with Secret Manager</h1><p id="8469">Security is a top priority in application deployment. The use of Google Cloud’s Secret Manager in this template ensures that sensitive information, such as API keys and credentials, is stored securely. This tool provides a centralized and secure way to manage and access secrets, reducing the risk of data breaches.</p><h1 id="82b2">Getting Started</h1><h1 id="8153">Prerequisites</h1><p id="db83">Before diving into this template, certain prerequisites are necessary:</p><ul><li>Google Cloud Platform Account: An active GCP account is required. <a href="https://cloud.google.com/">Sign up here</a> if you don’t have one.</li><li>Project Setup: Create a new GCP project and take note of the project ID for future steps.</li><li>Service Account Creation: Set up a service account with ‘Owner’ permissions and generate a JSON key file for authentication.</li><li>GitHub Integration: For integration with GitHub, generate a personal access token

Options

with the necessary permissions.</li></ul><figure id="4a88"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*dHYI5ShXesICyQla9AAJsA.jpeg"><figcaption></figcaption></figure><h1 id="a673">Terraform Configuration</h1><p id="5284">Terraform plays a crucial role in this template. Start by renaming the <code>terraform.tfvars.example</code> to <code>terraform.tfvars</code> and input your credentials. This step initializes the Terraform configuration, tailoring it to your specific GCP setup.</p><h1 id="3e8c">Docker Configuration</h1><p id="f049">The <code>Dockerfile</code> is pre-configured to use NVIDIA's CUDA base image, catering to FastAPI's dependencies. It exposes the application on port 8000, but this can be modified as per your requirements.</p><h1 id="d0d8">FastAPI Application Setup</h1><p id="678a">At the heart of this template is the <code>main.py</code> script, which serves as the entry point for the FastAPI application. It comes with basic routes, but you're encouraged to extend and customize it according to your application's needs.</p><h1 id="68c3">Usage and Deployment</h1><p id="8be6">Deploying your infrastructure and application is straightforward:</p><ol><li>Initialize Terraform with <code>terraform init</code>.</li><li>Apply the Terraform configuration using <code>terraform apply</code>.</li><li>To build and run the Docker container locally, execute <code>docker-compose up --build</code>.</li></ol></article></body>

FastAPI CloudRun Starter: Serveless Backend Deployment

In the realm of web application development, the need for efficient and streamlined backend deployment is paramount. The FastAPI CloudRun Starter repository addresses this need by providing a robust and easy-to-use starter template for setting up a FastAPI backend using Google CloudRun. This tool harnesses the power of modern infrastructure-as-code principles to simplify the deployment process of FastAPI applications, making it an invaluable asset for developers.

https://github.com/mazzasaverio/fastapi-cloudrun-starter

Terraform-Based Infrastructure Setup

The integration of Terraform in the FastAPI CloudRun Starter allows for the automated setup of infrastructure. This Infrastructure as Code (IaC) tool enables developers to define and provision data center infrastructure using a high-level configuration language. This approach ensures consistency and repeatability across environments, significantly reducing the potential for human error during the setup process.

Seamless Integration with GitHub Actions

GitHub Actions facilitates continuous integration (CI) by automating workflows. In this template, GitHub Actions are configured to automatically test and deploy applications. This integration ensures that every code commit goes through a standardized testing process, enhancing code quality and reliability.

Automated Cloud Build Triggers

Google Cloud Build is utilized for automated building, testing, and deploying. The starter template sets up triggers that automatically initiate Cloud Build processes upon code changes, ensuring that the latest version of the application is always ready for deployment.

Secure Storage with Secret Manager

Security is a top priority in application deployment. The use of Google Cloud’s Secret Manager in this template ensures that sensitive information, such as API keys and credentials, is stored securely. This tool provides a centralized and secure way to manage and access secrets, reducing the risk of data breaches.

Getting Started

Prerequisites

Before diving into this template, certain prerequisites are necessary:

  • Google Cloud Platform Account: An active GCP account is required. Sign up here if you don’t have one.
  • Project Setup: Create a new GCP project and take note of the project ID for future steps.
  • Service Account Creation: Set up a service account with ‘Owner’ permissions and generate a JSON key file for authentication.
  • GitHub Integration: For integration with GitHub, generate a personal access token with the necessary permissions.

Terraform Configuration

Terraform plays a crucial role in this template. Start by renaming the terraform.tfvars.example to terraform.tfvars and input your credentials. This step initializes the Terraform configuration, tailoring it to your specific GCP setup.

Docker Configuration

The Dockerfile is pre-configured to use NVIDIA's CUDA base image, catering to FastAPI's dependencies. It exposes the application on port 8000, but this can be modified as per your requirements.

FastAPI Application Setup

At the heart of this template is the main.py script, which serves as the entry point for the FastAPI application. It comes with basic routes, but you're encouraged to extend and customize it according to your application's needs.

Usage and Deployment

Deploying your infrastructure and application is straightforward:

  1. Initialize Terraform with terraform init.
  2. Apply the Terraform configuration using terraform apply.
  3. To build and run the Docker container locally, execute docker-compose up --build.
Fastapi
Terraform
Gcp
Google Cloud Run
Serverless
Recommended from ReadMedium