This repository contains the backend services for MLB Sluggers, handling game highlights processing, AI content generation, and Pub/Sub event-driven workflows using Google Cloud Functions (2nd Gen).
A RESTful Flask API for serving highlights and processing game data.
process-game-status-event
: Listens for game status updates via Pub/Sub and triggers AI processing when a game reachesFinal
.ai-processing-service
: Handles AI-powered content generation for highlights.
/backend
βββ /api # Flask API Directory
β βββ main.py # Flask API Entry Point
β βββ requirements.txt # Flask API Dependencies
β βββ Dockerfile # (If using Docker for App Engine)
β
βββ /cloud-functions # Cloud Functions Directory
β βββ /process-game-status-event # Function for processing game status updates
β β βββ main.py # Entry point for function
β β βββ requirements.txt # Dependencies
β β
β βββ /ai-processing-service # Function for AI-powered content generation
β β βββ main.py # Entry point for function
β β βββ requirements.txt # Dependencies
β
βββ README.md # Project Documentation
βββ .gitignore # Ignore unnecessary files
- Install Google Cloud SDK: Install Guide
- Authenticate with Google Cloud:
gcloud auth application-default login
- Clone the repository
git clone git@github.com:Slime-Stack/Sluggers.git cd apps/backend
- Setup Flask API
cd api pip install -r requirements.txt python main.py
- Build & Push Docker Image
gcloud builds submit --tag gcr.io/slimeify/mlb-sluggers-api
- Deploy to Cloud Run
gcloud run deploy mlb-sluggers-api \ --image gcr.io/slimeify/mlb-sluggers-api \ --region us-central1 \ --platform managed \ --allow-unauthenticated
gcloud functions deploy process-game-status-event \
--gen2 \
--runtime python39 \
--region us-central1 \
--trigger-topic sluggers-process-game-status \
--source=cloud-functions/process-game-status-event \
--entry-point=process_game_status_event \
--memory=256MB \
--timeout=300s
gcloud functions deploy ai-processing-service \
--gen2 \
--runtime python39 \
--region us-central1 \
--trigger-topic sluggers-ai-processing \
--source=cloud-functions/ai-processing-service \
--entry-point=ai_processing_service \
--memory=256MB \
--timeout=300s
gcloud functions list
gcloud functions logs read process-game-status-event --limit 50
gcloud functions logs read ai-processing-service --limit 50
Topic Name | Trigger |
---|---|
sluggers-process-game-status |
Triggers process-game-status-event function |
sluggers-ai-processing |
Triggers ai-processing-service function |
gcloud functions delete process-game-status-event --region us-central1
gcloud functions delete ai-processing-service --region us-central1
gcloud run services delete mlb-sluggers-api --region us-central1
To automate deployments:
- Set up Google Cloud authentication in GitHub Actions
- Store
GOOGLE_APPLICATION_CREDENTIALS
in GitHub Secrets.
- Store
- Create a GitHub Actions Workflow (
.github/workflows/deploy.yml
)
name: Deploy Cloud Functions
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
- name: Deploy `process-game-status-event`
run: |
gcloud functions deploy process-game-status-event \
--gen2 \
--runtime python39 \
--region us-central1 \
--trigger-topic sluggers-process-game-status \
--source=cloud-functions/process-game-status-event \
--entry-point=process_game_status_event \
--memory=256MB \
--timeout=300s
- name: Deploy `ai-processing-service`
run: |
gcloud functions deploy ai-processing-service \
--gen2 \
--runtime python39 \
--region us-central1 \
--trigger-topic sluggers-ai-processing \
--source=cloud-functions/ai-processing-service \
--entry-point=ai_processing_service \
--memory=256MB \
--timeout=300s
MIT License.
For questions, contact [Your Name] at your-email@example.com.