video-accessibility/infra/cloud-run
Vadym Samoilenko ea21cace96 feat: replace SDK with direct HTTP integration to centralized cost tracker
- New services/cost_tracker.py: sync httpx preflight()/record() + async wrappers;
  BudgetExceeded exception; no-op when COST_TRACKER_BASE_URL is empty
- Preflight budget check added before ingestion (Gemini), per-language translation
  (video-native + traditional), and per-language TTS dispatch
- _record_gemini_usage and _record_tts_cost now call cost_tracker directly;
  removes broken asyncio.get_event_loop() hack from sync Celery worker
- Fix: _cost_ctx now threaded into extract_accessibility_targeted (video-native path)
- Fix: user_id/cost_project_id now propagated through dispatch_language_tts →
  synthesize_cue_task.s() and the rerender_accessible_video.py re-render path
- Remove oliver-cost-tracker SDK dependency (was commented-out/never installed)
- Drop cost_tracker_outbox_path setting and get_cost_tracker() factory
- Update COST_TRACKER_BASE_URL default to optical-dev.oliver.solutions in
  .env.prod.example, docker-compose.yml, and all Cloud Run service yamls
- Cloud Run yamls use Secret Manager ref (cost-tracker-api-key) for the API key

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 13:36:15 +01:00
..
api-service.yaml feat: replace SDK with direct HTTP integration to centralized cost tracker 2026-04-27 13:36:15 +01:00
cloudbuild-http-services.yaml feat: add Cloud Run HTTP services for Whisper and FFmpeg 2026-01-02 10:12:50 -06:00
cloudbuild.yaml feat: switch Whisper model from large-v3 to medium 2025-12-28 22:35:47 -06:00
deploy.sh initial commit 2025-08-24 16:28:33 -05:00
ffmpeg-http-service.yaml fix: update Cloud Run service configs for compatibility 2026-01-02 17:34:10 -06:00
main.tf initial commit 2025-08-24 16:28:33 -05:00
README.md initial commit 2025-08-24 16:28:33 -05:00
terraform.tfvars.example initial commit 2025-08-24 16:28:33 -05:00
tts-worker-service.yaml feat: replace SDK with direct HTTP integration to centralized cost tracker 2026-04-27 13:36:15 +01:00
whisper-http-service.yaml fix: update Cloud Run service configs for compatibility 2026-01-02 17:34:10 -06:00
whisper-worker-service.yaml feat: replace SDK with direct HTTP integration to centralized cost tracker 2026-04-27 13:36:15 +01:00
worker-service.yaml feat: replace SDK with direct HTTP integration to centralized cost tracker 2026-04-27 13:36:15 +01:00

Cloud Run Deployment

This directory contains deployment configurations for running the Accessible Video Platform on Google Cloud Run.

Files

  • cloudbuild.yaml - Cloud Build configuration for CI/CD
  • api-service.yaml - Cloud Run service definition for API
  • worker-service.yaml - Cloud Run service definition for Celery workers
  • main.tf - Terraform infrastructure as code
  • terraform.tfvars.example - Example Terraform variables
  • deploy.sh - Manual deployment script
  • README.md - This file

Prerequisites

  1. Google Cloud Project with billing enabled

  2. Required APIs enabled (script will enable them):

    • Cloud Build API
    • Cloud Run API
    • Container Registry API
    • Secret Manager API
    • Cloud Trace API
    • Cloud Monitoring API
    • Translate API
    • Text-to-Speech API
    • Cloud Storage API
    • AI Platform API
  3. Secrets created in Secret Manager:

    • mongodb-url - MongoDB Atlas connection string
    • redis-url - Redis connection string (Cloud Memorystore)
    • jwt-secret - JWT signing secret
    • jwt-refresh-secret - JWT refresh token secret
    • gemini-api-key - Google Gemini API key
    • sendgrid-api-key - SendGrid API key for emails
    • elevenlabs-api-key - ElevenLabs API key for TTS
    • sentry-dsn - Sentry error tracking DSN

Deployment Options

# Initialize Terraform
cd infra/cloud-run
terraform init

# Copy and configure variables
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars with your project details

# Plan deployment
terraform plan

# Deploy infrastructure
terraform apply

Option 2: Manual Script

# Set environment variables
export PROJECT_ID="your-gcp-project-id"
export REGION="us-central1"

# Run deployment script
./infra/cloud-run/deploy.sh

Option 3: Cloud Build Trigger

Set up a Cloud Build trigger connected to your Git repository that uses cloudbuild.yaml for automatic deployments on code changes.

Local Development

Use the provided docker-compose.yml in the project root:

# Copy environment file
cp .env.example .env
# Edit .env with your development credentials

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f api
docker-compose logs -f worker

Service Architecture

  • API Service: Handles HTTP requests, authentication, job management

    • Memory: 2Gi, CPU: 2000m
    • Autoscaling: 1-10 instances
    • Public access via HTTPS
  • Worker Service: Processes video files with AI models

    • Memory: 4Gi, CPU: 4000m
    • Autoscaling: 0-5 instances
    • Internal access only

Monitoring

Both services include:

  • OpenTelemetry tracing exported to Cloud Trace
  • Prometheus metrics for monitoring
  • Sentry error tracking for error reporting
  • Health checks for service reliability

Security

  • Services run with least-privilege service accounts
  • Secrets managed via Secret Manager
  • No hardcoded credentials in containers
  • Network isolation for worker service