Skip to content

Slime-Stack/Sluggers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MLB Sluggers Backend Services πŸ†βšΎ

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).

πŸš€ Services Overview

1️⃣ Flask API (/api)

A RESTful Flask API for serving highlights and processing game data.

2️⃣ Cloud Functions

  • process-game-status-event: Listens for game status updates via Pub/Sub and triggers AI processing when a game reaches Final.
  • ai-processing-service: Handles AI-powered content generation for highlights.

πŸ“‚ Directory Structure

/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

🌎 Environment Setup

1️⃣ Prerequisites

  • Install Google Cloud SDK: Install Guide
  • Authenticate with Google Cloud:
    gcloud auth application-default login

2️⃣ Setting Up Local Development

  1. Clone the repository
    git clone git@github.com:Slime-Stack/Sluggers.git
    cd apps/backend
  2. Setup Flask API
    cd api
    pip install -r requirements.txt
    python main.py

πŸš€ Deploying Services

1️⃣ Deploy Flask API

  • 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

2️⃣ Deploy Cloud Functions

πŸš€ Deploy process-game-status-event

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

πŸš€ Deploy ai-processing-service

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

πŸ” Monitoring & Debugging

1️⃣ Check Running Functions

gcloud functions list

2️⃣ Check Function Logs

gcloud functions logs read process-game-status-event --limit 50
gcloud functions logs read ai-processing-service --limit 50

3️⃣ View Logs in Google Cloud Console

πŸ“Œ Pub/Sub Topics

Topic Name Trigger
sluggers-process-game-status Triggers process-game-status-event function
sluggers-ai-processing Triggers ai-processing-service function

πŸ› οΈ Managing Cloud Functions

πŸ›‘ Deleting a Function

gcloud functions delete process-game-status-event --region us-central1
gcloud functions delete ai-processing-service --region us-central1

πŸ›‘ Deleting Cloud Run API

gcloud run services delete mlb-sluggers-api --region us-central1

βš™οΈ Automating Deployment with GitHub Actions

To automate deployments:

  1. Set up Google Cloud authentication in GitHub Actions
    • Store GOOGLE_APPLICATION_CREDENTIALS in GitHub Secrets.
  2. 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

πŸ“œ License

MIT License.

πŸ“ž Support

For questions, contact [Your Name] at your-email@example.com.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published