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.
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.
- 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
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"]
- Trigger: Push/PR to main branch
- Service:
loanml
- Project ID:
cloudrunmlcicd
- Registry:
asia-southeast1-docker.pkg.dev
- Code Checkout - Get latest code
- Python Setup - Configure Python 3.10.13
- Dependencies - Install requirements
- Testing - Run pytest suite
- GCP Authentication - Authenticate with service account
- Docker Build & Push - Build image and push to Artifact Registry
- Cloud Run Deploy - Deploy to Google Cloud Run
Enable the following GCP services:
- Cloud Build API
- Artifact Registry API
- Cloud Run API
Create a service account with these IAM roles:
- Artifact Registry Writer
- Cloud Build Service Account
- Cloud Run Admin
- Service Account User
- Storage Object Viewer
Add the service account key as GCP_SA_KEY
in your GitHub repository secrets.
- Clone the repository
- Install dependencies:
pip install -r requirements.txt
- Run locally:
uvicorn main:app --reload
- Access the application at
http://localhost:8000