8000 GitHub - ridhwanrazaliwork/fastapi-docker-gcp-pipeline
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ridhwanrazaliwork/fastapi-docker-gcp-pipeline

Repository files navigation

FastAPI Docker Cloud Tutorial

A simple loan acceptance prediction web application built with FastAPI, containerized with Docker, and deployed on Google Cloud Run with automated CI/CD using GitHub Actions.

🎯 Project Purpose

This project serves as a learning exercise to explore and understand:

  • FastAPI web framework for building APIs
  • Docker containerization
  • Google Cloud Run deployment
  • GitHub Actions for CI/CD automation
  • Machine Learning integration with web applications

The main focus is on the deployment pipeline and cloud technologies rather than complex ML modeling.

🔧 Tech Stack

  • Backend: FastAPI
  • ML: scikit-learn (loan acceptance prediction)
  • Frontend: HTML, CSS
  • Containerization: Docker
  • Deployment: Google Cloud Run
  • CI/CD: GitHub Actions
  • Container Registry: Google Artifact Registry

🐳 Docker Configuration

The application uses a lightweight Python base image:

FROM python:3.10-slim
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8000
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port $PORT"]

🚀 CI/CD Pipeline

GitHub Actions Workflow

  • Trigger: Push/PR to main branch
  • Service: loanml
  • Project ID: cloudrunmlcicd
  • Registry: asia-southeast1-docker.pkg.dev

Deployment Steps

  1. Code Checkout - Get latest code
  2. Python Setup - Configure Python 3.10.13
  3. Dependencies - Install requirements
  4. Testing - Run pytest suite
  5. GCP Authentication - Authenticate with service account
  6. Docker Build & Push - Build image and push to Artifact Registry
  7. Cloud Run Deploy - Deploy to Google Cloud Run

⚙️ Google Cloud Setup

Required Services

Enable the following GCP services:

  • Cloud Build API
  • Artifact Registry API
  • Cloud Run API

Service Account Permissions

Create a service account with these IAM roles:

  • Artifact Registry Writer
  • Cloud Build Service Account
  • Cloud Run Admin
  • Service Account User
  • Storage Object Viewer

GitHub Secrets

Add the service account key as GCP_SA_KEY in your GitHub repository secrets.

🔗 References

📋 Getting Started

  1. Clone the repository
  2. Install dependencies: pip install -r requirements.txt
  3. Run locally: uvicorn main:app --reload
  4. Access the application at http://localhost:8000

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0