Files
media-analyzer/CLAUDE.md
2025-08-25 04:03:56 -03:00

839 lines
38 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Real-Time Video Analysis Platform
Project Overview
A scalable real-time video streaming and AI analysis platform
that demonstrates modern cloud-native architecture and machine learning integration.
The system ingests RTMP video streams (from sources like OBS),
processes them with computer vision AI models,
and provides live analysis results through a responsive web dashboard.
Core Functionality
Video Ingestion: Accept RTMP streams and convert to HLS for web playback
AI Processing: Real-time object detection (YOLO) and scene analysis (CLIP) on video segments
Live Dashboard: Angular frontend with WebSocket-powered real-time analysis overlays
Scalable Architecture: Kubernetes-deployed microservices with configurable processing modes
Cloud Integration: GCP services integration while maintaining platform agnostic design
Technical Stack
Backend: Django + Django Channels, PostgreSQL, Redis, Celery
AI/ML: OpenCV, YOLO, CLIP, Whisper (Hugging Face Transformers)
Frontend: Angular 17+ with HLS.js video player and Canvas overlays
Infrastructure: Docker containers, Kubernetes, NGINX
Cloud: Google Cloud Platform integration (Storage, Vision API, Build, Logging)
Streaming: FFmpeg for RTMP→HLS conversion, WebSocket for real-time data
Key Features
Dual processing modes (real-time vs batch) with runtime switching
Live video analysis overlays (bounding boxes, object labels, confidence scores)
OBS Studio integration for testing with various video sources
Kubernetes auto-scaling based on processing queue depth
Performance monitoring and benchmarking for 1080p30 video streams
Platform-agnostic design with cloud-specific optimizations
Architecture Goals
Demonstrate event-driven microservices architecture
Showcase AI model deployment and inference at scale
Implement real-time data streaming and WebSocket communication
Show proficiency with modern web frameworks and container orchestration
Prove understanding of video processing pipelines and streaming protocols
This project serves as a technical showcase for backend development, AI/ML integration, cloud platform expertise, and modern web application architecture - directly addressing the requirements for a streaming media and AI-focused development role.
Master Implementation Checklist
Core Infrastructure Setup
Django project structure - Create apps: streaming, ai_processing, api, dashboard
Database models - Stream, MediaSegment, VideoAnalysis, ObjectDetection tables
Docker containers - Django app, PostgreSQL, Redis, Nginx
Basic Kubernetes manifests - Deployments, services, configmaps, PVCs
RTMP ingestion endpoint - Accept OBS streams, trigger ffmpeg HLS conversion
HLS segment monitoring - File watcher to detect new video segments
AI Processing Pipeline
Video analysis models setup - CLIP for scene understanding, YOLO for object detection
Frame extraction service - Extract keyframes from HLS segments
Real-time vs batch processing abstraction - Strategy pattern implementation
AI processing worker - Celery tasks for video analysis
Results storage - Store detection results with timestamps and confidence scores
Processing queue management - Handle backlog and prioritization
Real-Time Video Effects Pipeline
GPU-accelerated shader pipeline - OpenGL/CUDA integration with FFmpeg
AI-triggered effects system - Apply shaders based on detection results
Custom filter development - Face blur, object highlighting, scene-based color grading
WebGL frontend effects - Client-side shader preview and control
Angular Frontend
Angular 17+ project setup - Standalone components, signals, new control flow
WebSocket service - Real-time communication with Django Channels
Video player component - HLS.js integration for stream playback
Analysis overlay component - Canvas-based bounding boxes and labels
Stream control dashboard - Start/stop streams, processing mode toggle
Real-time results panel - Live object detection and scene analysis display
Real-time Communication
Django Channels setup - WebSocket consumers for live data streaming
WebSocket message protocols - Define message types for analysis results
Frontend WebSocket integration - Angular service for real-time updates
Overlay synchronization - Match analysis results with video timeline
GCP Integration Features
Cloud Storage integration - Store processed video segments and analysis results
Cloud Vision API comparison - Benchmark against local models (within free tier)
Cloud Logging - Structured logging for monitoring and debugging
Cloud Build CI/CD - Automated Docker builds and deployments
GKE-specific configurations - Node selectors, resource requests/limits
Cloud Load Balancer - External access to the application
Video Processing & Effects
FFmpeg integration - HLS generation with proper segment duration
Video quality optimization - Handle 1080p streams efficiently
Frame rate analysis - Detect motion and activity levels
Color analysis - Dominant colors and scene brightness
Performance monitoring - Track processing latency and throughput
Kubernetes Production Setup
Resource management - CPU/memory limits for AI processing
Auto-scaling configuration - HPA based on processing queue length
Persistent storage - Claims for video segments and database
Service mesh setup - Istio for traffic management (optional)
Monitoring stack - Prometheus and Grafana integration
Ingress configuration - NGINX ingress with SSL termination
Testing & Validation
OBS integration testing - Verify RTMP stream ingestion
AI model accuracy testing - Validate object detection results
Performance benchmarking - Process 1080p30 streams in real-time
WebSocket stress testing - Multiple concurrent viewers
End-to-end pipeline testing - OBS → Processing → Angular display
Documentation & Deployment
API documentation - OpenAPI/Swagger specs
Kubernetes deployment guide - Step-by-step cluster setup
GCP setup instructions - Service account, IAM, and resource creation
Architecture diagrams - System overview and data flow
Performance metrics documentation - Benchmarks and optimization notes
Suggested Implementation Order:
Phase 1 (Foundation): Infrastructure Setup → Django + Models → Docker Setup
Phase 2 (Core Features): RTMP Ingestion → AI Processing Pipeline → Results Storage
Phase 3 (Frontend): Angular Setup → WebSocket Service → Video Player
Phase 4 (Integration): Real-time Communication → Analysis Overlays → Stream Control
Phase 5 (Cloud): GCP Services → Kubernetes Production → Monitoring
Phase 6 (Polish): Testing → Documentation → Performance Optimization
This order ensures each component builds on the previous ones and you can test functionality incrementally. The GCP integration is spread throughout to demonstrate platform knowledge without being overwhelming.
Ready to start with the foundation phase?
Media Analyzer - Complete Project Structure
media-analyzer/
├── README.md
├── docker-compose.yml # Development environment
├── requirements.txt # Python dependencies
├── manage.py # Django management
├── backend/ # Django application root
│ ├── media_analyzer/ # Main Django project
│ │ ├── __init__.py
│ │ ├── settings/
│ │ │ ├── __init__.py
│ │ │ ├── base.py # Base settings
│ │ │ ├── development.py # Dev overrides
│ │ │ └── production.py # Prod overrides
│ │ ├── urls.py # Main URL routing
│ │ ├── wsgi.py # WSGI application
│ │ └── asgi.py # ASGI for Django Channels
│ │
│ ├── streaming/ # RTMP/HLS handling app
│ │ ├── __init__.py
│ │ ├── models.py # Stream, MediaSegment models
│ │ ├── views.py # RTMP endpoints
│ │ ├── consumers.py # WebSocket consumers
│ │ ├── rtmp_handler.py # RTMP server logic
│ │ ├── hls_monitor.py # File system watcher
│ │ └── urls.py
│ │
│ ├── ai_processing/ # AI analysis app
│ │ ├── __init__.py
│ │ ├── models.py # Analysis results models
│ │ ├── processors/
│ │ │ ├── __init__.py
│ │ │ ├── base.py # Processing strategy interface
│ │ │ ├── realtime.py # Real-time processor
│ │ │ ├── batch.py # Batch processor
│ │ │ └── video_analyzer.py # CLIP/YOLO integration
│ │ ├── tasks.py # Celery tasks
│ │ └── apps.py # App configuration
│ │
│ ├── effects/ # Real-time video effects app
│ │ ├── __init__.py
│ │ ├── models.py # Effect presets, shader configs
│ │ ├── processors/
│ │ │ ├── __init__.py
│ │ │ ├── gpu_pipeline.py # OpenGL/CUDA processing
│ │ │ ├── ffmpeg_filters.py # FFmpeg custom filters
│ │ │ └── effect_engine.py # Main effects orchestrator
│ │ ├── shaders/ # GLSL shader files
│ │ │ ├── vertex/ # Vertex shaders
│ │ │ ├── fragment/ # Fragment shaders
│ │ │ ├── blur.glsl # Face blur shader
│ │ │ ├── highlight.glsl # Object highlight shader
│ │ │ └── color_grade.glsl # Scene-based color grading
│ │ ├── triggers/
│ │ │ ├── __init__.py
│ │ │ ├── ai_triggers.py # AI detection → effect mapping
│ │ │ └── manual_triggers.py # User-controlled effects
│ │ ├── tasks.py # GPU processing Celery tasks
│ │ └── apps.py
│ │
│ └── api/ # REST API app
│ ├── __init__.py
│ ├── serializers.py # DRF serializers
│ ├── views.py # API endpoints
│ └── urls.py
├── frontend/ # Angular application
│ ├── package.json
│ ├── angular.json
│ ├── src/
│ │ ├── app/
│ │ │ ├── app.component.ts
│ │ │ ├── app.config.ts # Angular 17+ config
│ │ │ │
│ │ │ ├── components/
│ │ │ │ ├── stream-viewer/
│ │ │ │ │ ├── stream-viewer.component.ts
│ │ │ │ │ ├── stream-viewer.component.html
│ │ │ │ │ └── stream-viewer.component.scss
│ │ │ │ ├── analysis-panel/
│ │ │ │ │ └── analysis-panel.component.ts
│ │ │ │ ├── stream-control/
│ │ │ │ │ └── stream-control.component.ts
│ │ │ │ └── effects-panel/
│ │ │ │ ├── effects-panel.component.ts
│ │ │ │ ├── effects-panel.component.html
│ │ │ │ └── shader-editor.component.ts
│ │ │ │
│ │ │ ├── services/
│ │ │ │ ├── websocket.service.ts
│ │ │ │ ├── stream.service.ts
│ │ │ │ ├── analysis.service.ts
│ │ │ │ └── effects.service.ts
│ │ │ │
│ │ │ ├── webgl/ # Client-side effects engine
│ │ │ │ ├── shader.service.ts
│ │ │ │ ├── effects-engine.ts
│ │ │ │ ├── webgl-utils.ts
│ │ │ │ └── shaders/ # WebGL shaders
│ │ │ │ ├── overlay.vert.glsl
│ │ │ │ ├── overlay.frag.glsl
│ │ │ │ ├── particle.vert.glsl
│ │ │ │ └── particle.frag.glsl
│ │ │ │
│ │ │ └── models/
│ │ │ ├── stream.interface.ts
│ │ │ ├── analysis.interface.ts
│ │ │ └── effects.interface.ts
│ │ │
│ │ └── main.ts # Angular bootstrap
│ └── ...
├── docker/ # Docker configurations
│ ├── Dockerfile.django # Django app container
│ ├── Dockerfile.nginx # Nginx for HLS serving
│ └── docker-compose.override.yml
├── k8s/ # Kubernetes manifests
│ ├── base/ # Base configurations
│ │ ├── namespace.yaml
│ │ ├── django-deployment.yaml
│ │ ├── nginx-deployment.yaml
│ │ ├── postgres-statefulset.yaml
│ │ ├── redis-deployment.yaml
│ │ ├── services.yaml
│ │ └── configmaps.yaml
│ │
│ ├── overlays/ # Environment-specific
│ │ ├── development/
│ │ │ └── kustomization.yaml
│ │ └── production/
│ │ ├── kustomization.yaml
│ │ └── gcp-specific.yaml
│ │
│ └── scripts/
│ ├── deploy.sh
│ └── setup-cluster.sh
├── media/ # Media storage (mounted volume)
│ ├── segments/ # HLS video segments
│ ├── playlists/ # HLS playlists
│ └── uploads/ # Uploaded content
├── scripts/ # Helper scripts
│ ├── setup-dev.sh # Development environment setup
│ ├── start-rtmp-server.sh # RTMP server startup
│ └── load-ai-models.py # Download and setup AI models
└── docs/ # Documentation
├── api.md # API documentation
├── deployment.md # Deployment guide
└── architecture.md # System architecture
vertical separation instead of phases
Slice 1: Basic Stream Ingestion
RTMP endpoint (basic)
HLS conversion (minimal)
Stream model + API
Simple Angular video player
Basic K8s deployment
Slice 2: AI Processing Foundation
Video segment detection
Single AI model integration (YOLO)
Processing strategy abstraction
Results storage + API
Analysis display component
Slice 3: Real-time Communication
WebSocket setup
Live analysis streaming
Frontend overlay system
Processing queue monitoring
Slice 4: GCP Integration
Cloud Storage for segments
GKE deployment
Monitoring integration
considerations for deployment / testing
does this planning take into consideration running it on a local kubernetes cluster? I use kind and tilt for running tough a prefer not to depend on it for developing just test the orchestration?
The current planning assumes traditional development (Django dev server + Angular dev server) with K8s only for testing orchestration. This is actually perfect for your workflow! Let me clarify the development vs testing approach:
## **Development Mode (Local Servers)**
```bash
# Backend development
cd backend
python manage.py runserver 8000
# Frontend development
cd frontend
ng serve --port 4200
# Supporting services (via Docker Compose)
docker-compose up redis postgres
```
**Benefits:**
- Hot reload for both Django and Angular
- Easy debugging with IDE integration
- Fast iteration cycles
- No K8s complexity during development
## **Testing Mode (KIND + K8s)**
```bash
# Build and deploy to KIND cluster
kind create cluster --name media-analyzer
kubectl apply -k k8s/overlays/development
```
**For orchestration testing only:**
- Container builds and registry
- Service discovery and networking
- Volume mounts and persistence
- Resource limits and scaling
- Inter-service communication
## **Suggested Development Workflow**## **Key Points for Your Workflow:**
### **Development (95% of time):**
- **No K8s dependency** - just Docker Compose for supporting services
- **Fast hot reload** - Django and Angular dev servers
- **Easy debugging** - direct access to logs and debugger
- **Simple database migrations** and model changes
### **K8s Testing (when needed):**
- **Container builds** work correctly
- **Service networking** functions properly
- **Volume mounts** for media files
- **Resource limits** don't break anything
- **Horizontal scaling** works as expected
### **Perfect for KIND:**
- KIND cluster only created when testing orchestration
- No overhead during daily development
- Easy to tear down and recreate
- Matches production K8s behavior
### **Tilt Usage (Optional):**
- **If you use Tilt**: Only for K8s testing, not development
- **If you skip Tilt**: Use the simple `kubectl` commands for testing
This approach gives you:
- **Fast development** without K8s complexity
- **Realistic testing** of the actual deployment
- **No vendor lock-in** to Tilt (though it's great if you want it)
- **Easy CI/CD** since K8s manifests are tested locally
The planning already supports this perfectly - you develop fast locally and test orchestration when needed!
STEP DONE
now that I have a basic stream pipeline a need to add an AI feature (something simple) before stepping everything to something that scales. I was thinking on detecting my extend hand, but maybe some more bussines oriented feature would work better (read the very first message with the JD in spanish to think about this)
Edit
Looking back at the job description, they mention analyzing "millones de emisiones en medios y redes sociales" for communication and advertising optimization. For a business-oriented AI feature that aligns with Seenka's focus, I'd suggest:
🎯 Brand/Logo Detection
Business Value: Identify brands and logos in video streams (like TV broadcasts, social media content)
Detect when competitors appear in content
Monitor brand visibility and placement
Track advertising effectiveness
Technical Implementation:
Use CLIP for general brand recognition
Train on common logos/brand imagery
Output: Brand name, confidence, screen position, duration
📺 Content Classification
Business Value: Categorize video content for media monitoring
Detect content types: "news", "sports", "entertainment", "advertising"
Identify show segments vs commercial breaks
Monitor content themes and topics
Technical Implementation:
CLIP scene classification with predefined categories
Frame sampling every few seconds
Output: Content category, confidence, timestamp
🗣️ Speaker Detection
Business Value: Media monitoring and audience analysis
Count people on screen (audience size estimation)
Detect when someone is speaking/presenting
Monitor speaker time and engagement
Technical Implementation:
YOLO for person detection
Basic pose estimation to detect "presentation pose"
Output: Person count, speaking activity, screen position
My Recommendation: Content Classification
Why it's perfect for your demo:
Business relevant: Directly matches Seenka's media analysis focus
Technically achievable: CLIP can classify scenes out-of-the-box
Visually impressive: Live categorization overlay on your OBS stream
Extensible: Easy to add more categories or confidence thresholds
Demo scenario: Stream different content types with OBS (news clips, sports, entertainment) and watch the AI classify them in real-time.
Which direction appeals to you most? The hand detection is cool for personal interaction, but content classification would really showcase understanding of their business domain.
Im using streams of myself (I have a decent setup) so for now the input will be just that but I think i can be fun if I display logos with my phone or something like that
Edit
Perfect! Logo detection with your phone is brilliant - it's both business-relevant (brand monitoring) and interactive demo-friendly. You can hold up logos on your phone screen or physical items and watch the AI detect them in real-time.
🏷️ Logo Detection Implementation
Simple Approach (Weekend-friendly):
CLIP-based Brand Recognition:
python
# Use CLIP's zero-shot classification
brands = ["Apple", "Google", "Nike", "Coca-Cola", "McDonald's", "Amazon"]
# Hold up logos on phone/laptop and classify scenes
Demo Flow:
You stream yourself with OBS
Hold up different brand logos on your phone/laptop screen
AI detects and labels them with confidence scores
Live overlay shows: "Apple Logo detected (87% confidence)"
Enhanced Approach:
Combine YOLO + CLIP:
YOLO: Detect objects in scene (phone, laptop, clothing, etc.)
CLIP: Classify detected regions for brand/logo content
Output: "iPhone detected", "Nike logo on shirt", "Starbucks cup visible"
Fun Demo Scenarios:
Tech Logos: Show Apple, Google, Microsoft logos on your devices
Fashion Brands: Wear branded clothing/accessories
Food/Drink: Hold up branded items from your desk
Mixed Reality: Point phone camera at branded items around your room
Business Value Demo:
Brand Monitoring: "Track when competitors appear in streams"
Advertising Analysis: "Measure brand visibility duration and positioning"
Content Compliance: "Detect unauthorized brand usage"
Implementation in Your Matrix:
This fits perfectly in AI Analysis → Local Single Server:
Frame extraction from HLS ✓
CLIP logo classification (instead of YOLO objects)
Analysis results storage
Results API endpoint
Want to start with basic CLIP brand classification, or go straight for the object detection + brand recognition combo?
CURRENT STEP
Demo Strategy
For Interviewers:
Show local demo: "Here's the system running locally with GCP integration"
Explain cloud strategy: "This architecture scales to full GCP with these manifests"
Demonstrate cloud services: "Logo detection uses Cloud Vision API"
Show cost optimization: "Uses free tier effectively while maintaining production patterns"
Scaling Path:
Local K8s → Single VM K8s → GKE Autopilot → Full GKE
Questions for You:
Comfort with hybrid approach? Local K8s + GCP services vs pure cloud?
Demo requirements? Do interviewers need to access it remotely, or is screen sharing sufficient?
AI model preference? Keep local CLIP for demo, or switch to Cloud Vision for "production"?
Time investment? How much time do you want to spend on infrastructure vs other features?
The hybrid approach gives you the best of both worlds - demonstrates K8s and GCP knowledge without the costs!
myself said: def what I prefer 2. would like to extend this not just this interview but as portfolio asset for others and potential people interested in learning how to do it 3. I reckon that design decisions allow for easy switching between the two. 4 today's focus is only infra (only had time for end to end logo detection, so shader effects are postponed indefinitely, I separated the visual properties on a different celery task to put in different queues but is commented out to test just the logo detection end-to-end and that's the feature that must work in after completing this prod-ready phase)
Perfect! Your hybrid approach as a portfolio/learning asset changes everything - much better than a throwaway demo. Let me design this for educational value and real-world applicability.
Portfolio-Ready Architecture
Design Principles:
Teachable: Others can follow your setup
Realistic: Mirrors actual production patterns
Cost-effective: $0 monthly with scaling options
Demonstrable: Works for interviews and learning
Hybrid K8s + GCP Implementation
Phase 1: Local Foundation (Today's Focus)
┌──────────────────────────────────────────────────────────┐
│ Local KIND Cluster │
├─────────────────┬─────────────────┬─────────────────────┤
│ Django Pod │ Worker Pod │ Infrastructure │
│ • Web API │ • Logo Analysis │ • PostgreSQL │
│ • Admin │ • Visual Tasks │ • Redis │
│ • WebSocket │ • Celery │ • NGINX │
└─────────────────┴─────────────────┴─────────────────────┘
┌─────────────┐
│ GCP Services│
│ • Storage │
│ • Vision AI │
│ • Logging │
└─────────────┘
K8s Manifests Structure:
k8s/
├── base/ # Platform-agnostic
│ ├── django-deployment.yaml # Web application
│ ├── worker-deployment.yaml # Celery workers
│ ├── postgres-statefulset.yaml # Database
│ ├── redis-deployment.yaml # Cache/Queue
│ ├── nginx-deployment.yaml # Reverse proxy
│ └── services.yaml # Internal networking
├── overlays/
│ ├── local/ # KIND cluster
│ │ ├── kustomization.yaml # Local configs
│ │ └── local-storage.yaml # Local volumes
│ ├── gcp-single-vm/ # Single VM deployment
│ │ ├── kustomization.yaml # VM-specific configs
│ │ └── resource-limits.yaml # Memory constraints
│ └── gcp-production/ # Full GKE deployment
│ ├── kustomization.yaml # Production configs
│ ├── hpa.yaml # Auto-scaling
│ └── monitoring.yaml # Observability
Today's Infrastructure Implementation
1. GCP Project Setup (Free Tier)
bash# Create project and enable APIs
gcloud projects create media-analyzer-demo
gcloud config set project media-analyzer-demo
gcloud services enable vision.googleapis.com
gcloud services enable storage.googleapis.com
gcloud services enable logging.googleapis.com
# Create service account
gcloud iam service-accounts create media-analyzer \
--display-name="Media Analyzer Service Account"
# Create and download key
gcloud iam service-accounts keys create credentials.json \
--iam-account=media-analyzer@media-analyzer-demo.iam.gserviceaccount.com
# Create storage bucket
gsutil mb gs://media-analyzer-segments
2. Local K8s with GCP Integration
yaml# k8s/base/django-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: django-app
spec:
replicas: 2
template:
spec:
containers:
- name: django
image: media-analyzer-backend:latest
env:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: "/var/secrets/google/credentials.json"
- name: GCP_BUCKET_NAME
value: "media-analyzer-segments"
- name: USE_CLOUD_VISION
value: "true"
volumeMounts:
- name: gcp-credentials
mountPath: /var/secrets/google
readOnly: true
volumes:
- name: gcp-credentials
secret:
secretName: gcp-credentials
3. Environment Switching Design
python# backend/media_analyzer/settings/base.py
import os
# AI Processing Configuration
USE_CLOUD_VISION = os.getenv('USE_CLOUD_VISION', 'false').lower() == 'true'
USE_LOCAL_CLIP = not USE_CLOUD_VISION
# Storage Configuration
USE_CLOUD_STORAGE = os.getenv('USE_CLOUD_STORAGE', 'false').lower() == 'true'
GCP_BUCKET_NAME = os.getenv('GCP_BUCKET_NAME', 'media-analyzer-segments')
# AI Analysis Strategy
if USE_CLOUD_VISION:
AI_ANALYSIS_BACKEND = 'ai_processing.backends.CloudVisionBackend'
else:
AI_ANALYSIS_BACKEND = 'ai_processing.backends.LocalClipBackend'
Portfolio Documentation Strategy
README Structure:
markdown# Media Analyzer - Production K8s Deployment
## Architecture Options
- [Local Development](docs/local-setup.md) - Docker Compose
- [Hybrid K8s](docs/hybrid-k8s.md) - KIND + GCP Services
- [Single VM](docs/single-vm-k8s.md) - k3s on GCP e2-micro
- [Full Production](docs/production-gke.md) - GKE with auto-scaling
## Cost Analysis
- Local: $0/month
- Hybrid: $0/month (free tier)
- Single VM: $0/month (free tier e2-micro)
- Production: ~$150/month (full GKE)
## Features Demonstrated
- ✅ Real-time video streaming (RTMP → HLS)
- ✅ AI-powered logo detection (CLIP/Cloud Vision)
- ✅ Kubernetes orchestration
- ✅ Cloud-native patterns
- ⏳ Auto-scaling and monitoring
Deployment Commands for Today:
bash# 1. Setup GCP credentials in K8s
kubectl create secret generic gcp-credentials \
--from-file=credentials.json=./credentials.json
# 2. Deploy to local KIND
kubectl apply -k k8s/overlays/local
# 3. Port forward for access
kubectl port-forward service/nginx 8080:80
# 4. Test logo detection
curl http://localhost:8080/api/streams/
Learning/Portfolio Value:
For Others:
Step-by-step deployment guides
Cost optimization strategies
Environment switching patterns
Real-world K8s manifests
For Interviews:
"Here's how I optimized for $0 monthly cost"
"This scales from laptop to production GKE"
"Logo detection works with both local and cloud AI"
"Others have successfully followed my setup guide"
Today's Checklist:
GCP project setup with service account
K8s secrets for GCP credentials
Environment switching for AI backends
Local deployment with cloud services
Logo detection end-to-end test
Documentation for portfolio sharing
Ready to tackle the infrastructure setup? This approach gives you a real portfolio asset that others can learn from while showcasing production-ready patterns!
Your Infrastructure Focus Today:
✅ Hybrid K8s (KIND) + GCP services architecture
✅ Environment switching between local CLIP and Cloud Vision
✅ Portfolio-ready documentation approach
✅ $0 monthly cost with production scaling path
Key Deliverable:
Logo detection working end-to-end in production-ready K8s setup
- non free GCP services should use local k8s services that are preferably easy switchable
- dont add things to gitignore that you don't know if they'll ever be there, just add what's needed as we go
docker check up
Heres a fast “what changed → what to do” map so you dont nuke/prune on every edit.
# Quick map
| You changed… | Do this (fastest first) | Notes / good defaults |
| -------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| **App code** (source files) | Nothing if you have livereload. Otherwise `docker compose restart <svc>` | Use bind mounts + a dev runner: Node `nodemon`, Python `uvicorn --reload`/Flask debug, Django `runserver`, Go `air`/`reflex`. |
| **Runtime config** inside container (env var values, flags) | `docker compose up -d --no-deps <svc>` (recreate) or `restart` | If the env is in `.env` or `compose.yml` `environment:`, a restart/recreate is enough. |
| **Config files read at startup** (e.g., `nginx.conf`, app config YAML) | `docker compose up -d --no-deps <svc>` | Bind-mount the config so you can `restart` instead of `rebuild`. |
| **Dependency lockfile** (`package-lock.json`, `poetry.lock`, `requirements.txt`, `go.mod/sum`, `Gemfile.lock`) | `docker compose build <svc>` then `up -d --no-deps <svc>` | Cache layers by copying lockfile before `COPY .`. See Dockerfile pattern below. |
| **Dockerfile** (but not the base image) | `docker compose build <svc>` then `up -d --no-deps <svc>` | BuildKit keeps layer cache; only changed layers rebuild. |
| **Base image tag** (e.g., `FROM node:20-bullseye` -> new tag or want latest security updates) | `docker compose build --pull <svc>` then `up -d --no-deps <svc>` | `--pull` refreshes the base. Use pinned tags in prod. |
| **Build args** (`ARG VAR=...` used in Dockerfile) | `docker compose build --no-cache --build-arg VAR=... <svc>` (if the arg affects earlier layers) | If the arg only affects late layers, drop `--no-cache`. |
| **Multi-service libraries** (shared package used by multiple services) | Rebuild every consumer: `docker compose build svc1 svc2` then `up -d --no-deps svc1 svc2` | Consider a shared base image stage to centralize caches. |
| **compose.yml** service definition (ports, volumes, healthchecks) | `docker compose up -d` | Compose detects what must be recreated. |
| **External dependency** (DB schema, migrations) | Run migration container/task; usually no rebuild | Keep DB in a **named volume** so rebuilds dont wipe data. |
| **Static assets** (built by a toolchain) | If built outside: restart only. If built inside: `build` that web service | Prefer building in a separate “builder” stage with a cache. |
| **Secrets** (files mounted via `secrets:` or env injected at runtime) | `restart` the service | Dont bake secrets into images → no rebuilds needed. |
| **Data in bind/named volumes** | Nothing (data persists) | Avoid pruning volumes unless you *want* to reset state. |
# Minimal dev patterns that avoid rebuilds
**Dockerfile (Node/Python example)**
```dockerfile
# syntax=docker/dockerfile:1.7
FROM node:20 AS deps
WORKDIR /app
COPY package*.json ./
RUN npm ci
FROM node:20 AS dev
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
# Copy only whats needed for runtime; source comes from a bind mount in dev
COPY package*.json ./
CMD ["npm","run","dev"] # e.g., vite/next with HMR
```
For Python, copy `pyproject.toml`/`requirements.txt` to a deps layer first, install, then bindmount your app code.
**docker-compose.yml (dev)**
```yaml
services:
web:
build:
context: .
target: dev
volumes:
- .:/app:cached
env_file: .env
ports:
- "3000:3000"
command: npm run dev
```
# Everyday command palette
* Restart a single service (pick up env/config):
`docker compose restart <svc>`
* Recreate a service without touching deps (uses existing image):
`docker compose up -d --no-deps <svc>`
* Rebuild only what changed (then recreate):
`docker compose build <svc> && docker compose up -d --no-deps <svc>`
* Rebuild with fresh base image:
`docker compose build --pull <svc> && docker compose up -d --no-deps <svc>`
* Tail logs:
`docker compose logs -f <svc>`
* Exec a shell:
`docker compose exec <svc> sh` (or `bash`)
* Clean **containers & images from dangling builds** (keep volumes!):
`docker image prune -f && docker container prune -f`
* Clean everything **except named volumes**:
`docker system prune -a` ← only when truly needed.
# Tips that keep you off the prune button
1. **Bind-mount code in dev** + a livereload command, so edits dont require rebuilds.
2. **Layer your Dockerfile** so deps install before copying the whole source:
* `COPY package*.json .` → install → **then** `COPY src .`
3. **Use BuildKit caches** for heavy steps (node, pip, apt):
* `RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt`
* `RUN --mount=type=cache,target=/root/.npm npm ci`
4. **Pin base images** (e.g., `node:20-bullseye`) and consciously use `--pull` when you want updates.
5. **Separate build and runtime** (multistage). Artifacts copied forward make rebuilds smaller.
6. **Keep data in named volumes**; never in the image. Pruning images wont touch your DB/files.
7. **.dockerignore** aggressively: exclude `node_modules` (if you install in image), `.git`, build outputs, tmp.
8. **Compose profiles** for optional services (e.g., `profiles: ["dev"]`) so you dont restart the world.
# Tiny Makefile (muscle memory)
```make
up: ## start everything
docker compose up -d
logs: ## tail logs from app
docker compose logs -f web
re: ## rebuild + recreate app only
docker compose build web && docker compose up -d --no-deps web
restart: ## restart app only
docker compose restart web
```
If you tell me your stack (language/framework + how you install deps), Ill tailor the Dockerfile and compose snippets so most edits are “save → livereload,” lockfile changes are “build web,” and prunes are basically never.
it's docker compose not docker-compose
- use debug logs not prints